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>
34 #include <sdcard_utility.h>
36 #include <json_utility.h>
38 #include <eeprom_utility.h>
44 #include <registers-thr.h>
46 #include <registers-thr.h>
47 #elif (USE_MODULE_RAIN)
48 #include <registers-rain.h>
51 #include <SensorDriver.h>
52 #include <debug_config.h>
54 #include <StreamUtils.h>
55 #include <ArduinoLog.h>
66 uint8_t module_main_version;
67 uint8_t module_configuration_version;
72 #if (USE_MODULE_THR || USE_MODULE_TH)
73 uint8_t i2c_temperature_address;
74 uint8_t i2c_humidity_address;
77 #if (USE_MODULE_THR || USE_MODULE_RAIN)
78 uint16_t tipping_bucket_time_ms;
88 float value[SAMPLES_COUNT];
102 float sample_temperature;
103 float sample_humidity;
105 float ist_temperature;
108 float min_temperature;
111 float avg_temperature;
114 float max_temperature;
117 float sigma_temperature;
118 float sigma_humidity;
127 uint8_t module_main_version;
128 uint8_t module_minor_version;
141 #if (USE_MODULE_THR || USE_MODULE_TH)
142 uint8_t i2c_temperature_address;
143 uint8_t i2c_humidity_address;
146 #if (USE_MODULE_THR || USE_MODULE_RAIN)
147 uint16_t tipping_bucket_time_ms;
148 uint8_t rain_for_tip;
168 #if (USE_SENSOR_ADT || USE_SENSOR_HIH || USE_SENSOR_HYT)
175 SENSORS_READING_SETUP_CHECK,
195 TIPPING_BUCKET_CHECK,
318 #if (USE_SENSOR_ADT || USE_SENSOR_HYT)
322 #if (USE_SENSOR_HIH || USE_SENSOR_HYT)
340 SensorDriver *sensors[SENSORS_MAX];
346 uint8_t sensors_count;
354 #if (USE_SENSOR_ADT || USE_SENSOR_HIH || USE_SENSOR_HYT)
359 sensors_reading_state_t sensors_reading_state;
370 #if (ENABLE_SDCARD_LOGGING)
387 WriteLoggingStream loggingStream(logFile,Serial);
531 void reset_report_buffer(
void);
541 template<
typename buffer_g,
typename length_v,
typename value_v> value_v bufferRead(buffer_g *buffer, length_v length);
542 template<
typename buffer_g,
typename length_v,
typename value_v> value_v bufferReadBack(buffer_g *buffer, length_v length);
543 template<
typename buffer_g,
typename value_v>
void bufferWrite(buffer_g *buffer, value_v value);
544 template<
typename buffer_g>
void bufferPtrReset(buffer_g *buffer);
545 template<
typename buffer_g,
typename length_v>
void bufferPtrResetBack(buffer_g *buffer, length_v length);
546 template<
typename buffer_g,
typename length_v>
void incrementBuffer(buffer_g *buffer, length_v length);
547 template<
typename buffer_g,
typename length_v,
typename value_v>
void bufferReset(buffer_g *buffer, length_v length);
548 template<
typename buffer_g,
typename length_v,
typename value_v>
void addValue(buffer_g *buffer, length_v length, value_v value);
557 void copy_oneshot_data();
562 #if (USE_SENSOR_ADT || USE_SENSOR_HIH || USE_SENSOR_HYT)
567 volatile bool is_event_sensors_reading;
583 volatile uint32_t rain_tips_event_occurred_time_ms;
#define I2C_MAX_DATA_LENGTH
Max length in bytes for i2c bus data buffer.
Definition: i2c_config.h:36
volatile bool is_event_command_task
Enable or disable the Command task.
Definition: i2c-leaf.h:502
volatile uint8_t readable_data_length
Number of bytes to read at readable_data_address.
Definition: i2c-leaf.h:202
bool is_start
Execute start command.
Definition: i2c-leaf.h:244
configuration_t configuration
Configuration data.
Definition: i2c-leaf.h:148
volatile uint8_t i2c_error
Number of i2c error.
Definition: i2c-leaf.h:220
writable_data_t writable_data
Writable i2c register.
Definition: i2c-leaf.h:184
volatile uint8_t i2c_time
Time in seconds from last I2C reset.
Definition: i2c-leaf.h:226
writable_data_t * writable_data_ptr
Pointer for read and write data in i2c writable register.
Definition: i2c-leaf.h:190
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
state_t
Main loop finite state machine.
Definition: i2c-leaf.h:100
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
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
bool is_stop
Execute stop command.
Definition: i2c-leaf.h:250
volatile uint8_t ready_tasks_count
Number of tasks ready to execute.
Definition: i2c-leaf.h:232
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
bool is_oneshot
Received command is in oneshot mode.
Definition: i2c-opc.h:340
bool is_continuous
Received command is in continuous mode.
Definition: i2c-opc.h:346
volatile bool is_event_tipping_bucket
Enable or disable the Tipping Bucket task.
Definition: i2c-rain.h:457
rain_t rain
Rain data.
Definition: i2c-rain.h:253
tipping_bucket_state_t
Tipping bucket task finite state machine.
Definition: i2c-rain.h:106
@ TIPPING_BUCKET_INIT
init task variables and wait half debounce time
Definition: i2c-rain.h:107
@ TIPPING_BUCKET_END
wait for the tipping bucket switch return open and performs end operations and deactivate task
Definition: i2c-rain.h:110
@ TIPPING_BUCKET_READ
read rain tips from variable shared with tipping bucket interrupt, validate it for spike re-reading t...
Definition: i2c-rain.h:108
@ TIPPING_BUCKET_WAIT_STATE
non-blocking waiting time
Definition: i2c-rain.h:111
void tipping_bucket_interrupt_handler(void)
Tipping bucket interrupt handler.
Definition: i2c-rain.ino:391
void tipping_bucket_task(void)
Tipping bucket task.
Definition: i2c-rain.ino:491
tipping_bucket_state_t tipping_bucket_state
Current tipping bucket task state.
Definition: i2c-rain.h:265
void load_configuration(void)
Load configuration from EEPROM.
Definition: i2c-leaf.ino:335
void init_tasks(void)
Init tasks variable and state.
Definition: i2c-leaf.ino:225
void init_system(void)
Init system.
Definition: i2c-leaf.ino:290
void init_spi(void)
Init SPI library.
Definition: i2c-leaf.ino:262
void samples_processing()
Main routine for processing the samples to calculate an observation.
Definition: i2c-th.ino:1050
void reset_samples_buffer(void)
Reset samples buffers to default value.
Definition: i2c-leaf.ino:549
void init_wire(void)
Init wire (i2c) library and performs checks on the bus.
Definition: i2c-leaf.ino:251
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
void init_wdt(uint8_t wdt_timer)
Init watchdog.
Definition: i2c-leaf.ino:202
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-thr.h:159
@ INIT
init tasks and sensors
Definition: i2c-thr.h:160
@ TASKS_EXECUTION
execute active tasks
Definition: i2c-thr.h:164
@ END
go to ENTER_POWER_DOWN or TASKS_EXECUTION
Definition: i2c-thr.h:165
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
void i2c_request_interrupt_handler(void)
I2C request interrupt handler.
Definition: i2c-leaf.ino:395
void init_buffers(void)
Init buffers.
Definition: i2c-leaf.ino:208
void init_sensors(void)
Create and setup sensors.
Definition: i2c-leaf.ino:353
void reset_buffer(void)
Reset sample and observations buffers to default value.
Definition: i2c-thr.ino:1252
void init_power_down(uint32_t *time_ms, uint32_t debouncing_ms)
Enter power down mode.
Definition: i2c-leaf.ino:173
void tests(void)
Performs specific operations based on the received command.
Definition: i2c-opc.ino:1400
sensors_reading_state_t
Sensors reading task finite state machine.
Definition: stima.h:234
@ SENSORS_READING_INIT
init task variables
Definition: stima.h:235
@ SENSORS_READING_IS_GETTED
check if the sensor has been readed
Definition: stima.h:240
@ SENSORS_READING_NEXT
go to next sensor
Definition: stima.h:242
@ SENSORS_READING_PREPARE
prepare sensor
Definition: stima.h:237
@ SENSORS_READING_GET
read and get values from sensor
Definition: stima.h:239
@ SENSORS_READING_IS_PREPARED
check if the sensor has been prepared
Definition: stima.h:238
@ SENSORS_READING_END
performs end operations and deactivate task
Definition: stima.h:243
@ SENSORS_READING_READ
intermediate state (future implementation...)
Definition: stima.h:241
@ SENSORS_READING_WAIT_STATE
non-blocking waiting time
Definition: stima.h:244
void init_timer1(void)
Init Timer1 module.
Definition: stima.ino:737
void sensors_reading_task(bool do_prepare=true, bool do_get=true, char *driver=NULL, char *type=NULL, uint8_t address=0, uint8_t node=0, uint8_t *sensor_index=0, uint32_t *wait_time=NULL)
Sensors reading Task. Read data from sensors.
Definition: stima.ino:2644
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
Readable data through i2c bus.
Definition: i2c-leaf.h:76
report data.
Definition: i2c-thr.h:98
Samples values for measured opc data.
Definition: i2c-opc.h:156
float * write_ptr
writer pointer
Definition: i2c-thr.h:91
float * read_ptr
reader pointer
Definition: i2c-thr.h:90
Writable data through i2c bus.
Definition: i2c-leaf.h:87