28 #include <i2c_config.h>
29 #include <avr/sleep.h>
30 #include <avr/power.h>
32 #include <i2c_utility.h>
33 #include <rmap_utility.h>
35 #include <json_utility.h>
37 #include <eeprom_utility.h>
41 #include <registers-leaf.h>
42 #include <debug_config.h>
44 #include <StreamUtils.h>
45 #include <ArduinoLog.h>
61 uint16_t leaf_calibration_threshold;
90 uint16_t leaf_calibration_threshold;
124 #if (ENABLE_SDCARD_LOGGING)
141 WriteLoggingStream loggingStream(logFile,Serial);
445 void reset_report_buffer(
void);
462 template<
typename sample_g,
typename observation_g,
typename value_v>
void addSample(sample_g *sample, observation_g *observation, value_v value);
464 template<
typename observation_g,
typename value_v> value_v readCurrentObservation(observation_g *buffer);
465 template<
typename observation_g,
typename value_v>
void writeCurrentObservation(observation_g *buffer, value_v value);
466 template<
typename observation_g,
typename length_v>
void resetObservation(observation_g *buffer, length_v length);
467 template<
typename observation_g,
typename length_v>
void resetBackPmObservation(observation_g *buffer, length_v length);
468 template<
typename observation_g,
typename length_v>
void incrementObservation(observation_g *buffer, length_v length);
469 template<
typename observation_g,
typename length_v,
typename value_v>
void addObservation(observation_g *buffer, length_v length, value_v value);
470 template<
typename observation_g,
typename length_v,
typename value_v> value_v readBackObservation(observation_g *buffer, length_v length);
#define I2C_MAX_DATA_LENGTH
Max length in bytes for i2c bus data buffer.
Definition: i2c_config.h:36
void leaf_reading_task(void)
Sensors reading Task. Read data from sensors.
Definition: i2c-leaf.ino:469
volatile bool is_event_command_task
Enable or disable the Command task.
Definition: i2c-leaf.h:502
volatile bool inside_transaction
Status of command transaction.
Definition: i2c-leaf.h:295
void load_configuration(void)
Load configuration from EEPROM.
Definition: i2c-leaf.ino:335
volatile uint8_t readable_data_length
Number of bytes to read at readable_data_address.
Definition: i2c-leaf.h:202
volatile uint8_t lastcommand
last command received.
Definition: i2c-leaf.h:214
bool is_start
Execute start command.
Definition: i2c-leaf.h:244
void init_tasks(void)
Init tasks variable and state.
Definition: i2c-leaf.ino:225
configuration_t configuration
Configuration data.
Definition: i2c-leaf.h:148
void init_system(void)
Init system.
Definition: i2c-leaf.ino:290
volatile uint8_t i2c_error
Number of i2c error.
Definition: i2c-leaf.h:220
void init_spi(void)
Init SPI library.
Definition: i2c-leaf.ino:262
writable_data_t writable_data
Writable i2c register.
Definition: i2c-leaf.h:184
bool do_buffers_reset
Force a buffers reset.
Definition: i2c-leaf.h:271
volatile uint8_t i2c_time
Time in seconds from last I2C reset.
Definition: i2c-leaf.h:226
void reset_samples_buffer(void)
Reset samples buffers to default value.
Definition: i2c-leaf.ino:549
writable_data_t * writable_data_ptr
Pointer for read and write data in i2c writable register.
Definition: i2c-leaf.h:190
void init_wire(void)
Init wire (i2c) library and performs checks on the bus.
Definition: i2c-leaf.ino:251
void i2c_receive_interrupt_handler(void)
I2C receive interrupt handler.
uint32_t awakened_event_occurred_time_ms
System time (in millisecond) when the system has awakened from power down.
Definition: i2c-leaf.h:238
void save_configuration(bool)
Save configuration to EEPROM.
Definition: i2c-leaf.ino:312
void init_rtc(void)
Init RTC module.
Definition: i2c-leaf.ino:266
volatile uint16_t transaction_time
Timer counter variable for compute command transaction timeout.
Definition: i2c-leaf.h:301
volatile bool is_event_leaf_reading
Enable or disable the Sensors reading task.
Definition: i2c-leaf.h:488
void init_wdt(uint8_t wdt_timer)
Init watchdog.
Definition: i2c-leaf.ino:202
leaf_reading_state_t
Definition: i2c-leaf.h:113
@ LEAF_READING_WAIT_STATE
non-blocking waiting time
Definition: i2c-leaf.h:117
@ LEAF_READING_INIT
init task variables
Definition: i2c-leaf.h:114
@ LEAF_READING_END
performs end operations and deactivate task
Definition: i2c-leaf.h:116
uint8_t samples_count
Number of samples to be acquired for make one observation.
Definition: i2c-leaf.h:265
void command_task(void)
Command Task. Execute the command received on i2c bus by reading i2c received data buffer.
Definition: i2c-leaf.ino:557
state_t
Main loop finite state machine.
Definition: i2c-leaf.h:100
@ INIT
init tasks and sensors
Definition: i2c-leaf.h:101
@ TASKS_EXECUTION
execute active tasks
Definition: i2c-leaf.h:105
@ END
go to ENTER_POWER_DOWN or TASKS_EXECUTION
Definition: i2c-leaf.h:106
void init_pins(void)
Init hardware pins.
Definition: i2c-leaf.ino:244
void commands(void)
Performs specific operations based on the received command.
Definition: i2c-leaf.ino:649
void exchange_buffers(void)
Exchange reader and writer pointer to buffer.
Definition: i2c-leaf.ino:535
void print_configuration(void)
Print current configuration.
Definition: i2c-leaf.ino:301
volatile readable_data_t readable_data_1
First readable i2c register.
Definition: i2c-leaf.h:154
volatile readable_data_t * readable_data_write_ptr
Pointer for write data in i2c readable register.
Definition: i2c-leaf.h:172
void samples_processing(bool is_force_processing)
Main routine for processing the samples to calculate an observation.
Definition: i2c-opc.ino:560
volatile uint16_t timer_counter_ms
Timer counter variable for execute timed task with time multiple of base Timer1 time.
Definition: i2c-leaf.h:277
void i2c_request_interrupt_handler(void)
I2C request interrupt handler.
Definition: i2c-leaf.ino:395
bool is_stop
Execute stop command.
Definition: i2c-leaf.h:250
void init_buffers(void)
Init buffers.
Definition: i2c-leaf.ino:208
volatile uint8_t ready_tasks_count
Number of tasks ready to execute.
Definition: i2c-leaf.h:232
void init_sensors(void)
Create and setup sensors.
Definition: i2c-leaf.ino:353
void init_logging()
Init logging system.
Definition: i2c-leaf.ino:141
state_t state
Current main loop state.
Definition: i2c-leaf.h:283
volatile uint8_t i2c_rx_data[I2C_MAX_DATA_LENGTH]
Buffer for i2c received data.
Definition: i2c-leaf.h:208
volatile uint8_t readable_data_address
Address of readable i2c register.
Definition: i2c-leaf.h:196
volatile readable_data_t * readable_data_temp_ptr
Temporary pointer for exchange read and write pointer for i2c readable register.
Definition: i2c-leaf.h:178
volatile readable_data_t * readable_data_read_ptr
Pointer for read data in i2c readable register.
Definition: i2c-leaf.h:166
volatile readable_data_t readable_data_2
Second readable i2c register.
Definition: i2c-leaf.h:160
void reset_buffer(void)
Reset sample and observations buffers to default value.
Definition: i2c-thr.ino:1252
bool is_test_read
Received command is in continuous mode.
Definition: i2c-leaf.h:256
void init_power_down(uint32_t *time_ms, uint32_t debouncing_ms)
Enter power down mode.
Definition: i2c-leaf.ino:173
void init_timer1(void)
Init Timer1 module.
Definition: stima.ino:737
void start_timer(void)
Start Timer1 module.
Definition: stima.ino:741
void stop_timer(void)
Stop Timer1 module.
Definition: stima.ino:749
EEPROM saved configuration.
Definition: i2c-leaf.h:55
uint8_t i2c_address
i2c address
Definition: i2c-leaf.h:59
bool is_oneshot
enable or disable oneshot mode
Definition: i2c-leaf.h:60
uint8_t module_configuration_version
module configuration version
Definition: i2c-leaf.h:57
uint8_t module_type
module type
Definition: i2c-leaf.h:58
uint8_t module_main_version
module main version
Definition: i2c-leaf.h:56
Leaf wetness data.
Definition: i2c-leaf.h:68
uint32_t time
time in seconds that indicates wet leaf
Definition: i2c-leaf.h:69
Readable data through i2c bus.
Definition: i2c-leaf.h:76
uint8_t module_main_version
module main version
Definition: i2c-leaf.h:78
uint8_t module_type
module type
Definition: i2c-leaf.h:77
leaf_wetness_t leaf_wetness
leaf wetness data for report
Definition: i2c-leaf.h:80
uint8_t module_minor_version
module minor version
Definition: i2c-leaf.h:79
Writable data through i2c bus.
Definition: i2c-leaf.h:87
uint8_t i2c_address
i2c address
Definition: i2c-leaf.h:88
bool is_oneshot
enable or disable oneshot mode
Definition: i2c-leaf.h:89