14 #ifndef LCB_BAT_MULTIPLIER
15 #define LCB_BAT_MULTIPLIER 1.1*320/100/1023
18 #ifndef LCB_BAT_REFERENCE
19 #define LCB_BAT_REFERENCE INTERNAL
22 #ifndef LCB_BAT_ADCPIN
23 #define LCB_BAT_ADCPIN A0
27 #ifndef TICKS_PER_SECOND
28 #define TICKS_PER_SECOND 16
32 #define SAMPLING_INT 16
36 #define WITHRAINGAUGE 0
47 #define ISSET_ACTION(nr) ((1<<nr)&action)
48 #define UNSET_ACTION(nr) (action&= ~(1<<nr))
51 #define ACTION_COUNT 7
54 #ifndef CHECKSUM_FRAMES
55 #define CHECKSUM_FRAMES 0
63 #if TICKS_PER_SECOND>3
64 #define LED_TICK_DIV (TICKS_PER_SECOND/4)
66 #define LED_TICK_DIV 1
69 volatile uint16_t ticks;
70 volatile uint8_t action;
73 volatile uint8_t action0_pending_count=0;
76 volatile uint8_t seconds;
77 volatile unsigned long current_micros, last_micros;
78 volatile uint8_t adjust_osccal_flag;
79 volatile uint8_t led_blink = 0;
84 #ifdef RTC_SECOND_CORRECT
85 volatile long rtc_seconds_correct;
94 ISR(TIMER2_OVF_vect) {
95 #ifdef WITH_TIMER2_ISR_TASK
99 if(adjust_osccal_flag){
100 last_micros=current_micros;
101 current_micros=micros();
102 adjust_osccal_flag++;
103 if(adjust_osccal_flag>2){
104 if((current_micros-last_micros)>(1006000L/TICKS_PER_SECOND)){
106 else adjust_osccal_flag=0;
108 else if((current_micros-last_micros)<(994000L/TICKS_PER_SECOND)){
109 if(OSCCAL<252) OSCCAL++;
110 else adjust_osccal_flag=0;
114 adjust_osccal_flag=0;
121 if((ticks % TICKS_PER_SECOND)==0) {
124 #ifdef RTC_SECOND_CORRECT
126 #if RTC_SECOND_CORRECT < 0
127 rtc_seconds_correct--;
128 if(rtc_seconds_correct<=RTC_SECOND_CORRECT){
129 rtc_seconds_correct=0;
134 rtc_seconds_correct++;
135 if(rtc_seconds_correct>=RTC_SECOND_CORRECT){
136 rtc_seconds_correct=0;
143 uint16_t tick_mod=myRTC._seconds%SAMPLING_INT;
144 if(tick_mod<ACTION_COUNT) {
148 action0_pending_count++;
151 action0_pending_count=0;
152 if(action0_pending_count>RESET_COUNT){
156 asm volatile (
" jmp 0");
162 action|=(1<<tick_mod);
168 if((led_blink>0) && ((ticks%LED_TICK_DIV)==0)) {
169 if(digitalRead(LED_PIN)) led_blink--;
170 digitalWrite(LED_PIN,!digitalRead(LED_PIN));
175 inline void handleRtcLCB(
void) {
182 void adjust_OSCCAL(
void){
183 adjust_osccal_flag=1;
184 while(adjust_osccal_flag){
192 volatile uint8_t rain_event=0;
193 volatile uint16_t rain_event_ticks;
194 void rain_isr(
void) {
195 if(rain_event && ((ticks-rain_event_ticks)>(TICKS_PER_SECOND/2))){
199 rain_event_ticks=ticks;
203 void handleRainEventLCB(
void) {
206 if(rain_event && ((ticks-rain_event_ticks)>(TICKS_PER_SECOND/2))){
216 volatile uint16_t wind_count=0;
217 volatile uint8_t wind_event=0;
218 volatile uint16_t wind_event_ticks;
219 volatile uint16_t min_wind_ticks=65535;
222 uint16_t wind_direction_count=0;
223 void wind_isr(
void) {
224 if((ticks-wind_event_ticks)>4) {
225 if((ticks-wind_event_ticks)<min_wind_ticks)
226 min_wind_ticks=ticks-wind_event_ticks;
229 wind_event_ticks=ticks;
233 #ifndef WIND_DIRECTION_PIN
234 #define WIND_DIRECTION_PIN A2
236 #ifndef WIND_POWER_PIN
237 #define WIND_POWER_PIN A3
240 void readWindDirectionLCB() {
241 wind_direction_count++;
242 pinMode(WIND_POWER_PIN,OUTPUT);
243 digitalWrite(WIND_POWER_PIN,HIGH);
244 int adc=analogRead(WIND_DIRECTION_PIN);
245 digitalWrite(WIND_POWER_PIN,LOW);
246 pinMode(WIND_POWER_PIN,INPUT);
290 const byte* new_addr;
295 #ifndef DALLAS_CHANNELS
296 #define DALLAS_CHANNELS 4
299 #ifndef DALLAS_OFFSET
300 #define DALLAS_OFFSET 20
305 void readAndSendDallasLCB(uint8_t send=1) {
314 client.addChecksum();
325 void blinkLED(uint8_t times) {
334 #if TICKS_PER_SECOND==128
335 Sleep.setupTimer2(1);
336 #elif TICKS_PER_SECOND==16
337 Sleep.setupTimer2(2);
338 #elif TICKS_PER_SECOND==4
339 Sleep.setupTimer2(3);
340 #elif TICKS_PER_SECOND==2
341 Sleep.setupTimer2(4);
342 #elif TICKS_PER_SECOND==1
343 Sleep.setupTimer2(5);
345 #error unsupported TICKS_PER_SECOND
349 pinMode(LED_PIN, OUTPUT);
353 #define RAINGAUGEPIN 2
355 digitalWrite(RAINGAUGEPIN,HIGH);
356 attachInterrupt(digitalPinToInterrupt(RAINGAUGEPIN),rain_isr,FALLING);
362 attachInterrupt(1,wind_isr,RISING);
378 while(new_addr=ds.
search()) {
390 Sleep.sleep(TIMER2_ON, SLEEP_MODE_PWR_SAVE);
393 void delayLCB(uint16_t _millis) {
394 _millis /= (1000 / TICKS_PER_SECOND);
396 uint16_t end_ticks = ticks + _millis + 2;
400 }
while ((ticks != end_ticks));
404 analogReference (LCB_BAT_REFERENCE);
405 pinMode(POWER_PIN, OUTPUT);
406 digitalWrite(POWER_PIN, HIGH);
407 batLCB = LCB_BAT_MULTIPLIER * analogRead(LCB_BAT_ADCPIN);
408 digitalWrite(POWER_PIN, LOW);
409 pinMode(POWER_PIN, INPUT);
410 analogReference (DEFAULT);
419 myRTC._seconds=SAMPLING_INT-1;
423 void sendOrBufferLCB() {
uint8_t addChannelValue(float v, uint8_t channel_number=0)
Definition: BayEOS.cpp:61
uint8_t writeToBuffer(void)
Definition: BayEOS.cpp:322
uint8_t createMessage(const char *s, uint8_t checksum=0, uint8_t frametype=BayEOS_Message)
Definition: BayEOS.cpp:301
void startDataFrame(uint8_t subtype=BayEOS_Float32le, uint8_t checksum=0)
Definition: BayEOS.cpp:12
uint8_t sendOrBuffer(void)
Definition: BayEOS.cpp:369
uint8_t sendPayload(void)
Definition: BayRF24.cpp:15
const String addr2String(const uint8_t *addr)
Definition: DS18B20.cpp:199
uint8_t readChannel(uint8_t channel, float *f, uint8_t tries=1)
Definition: DS18B20.cpp:147
uint8_t setAllAddrFromEEPROM(void)
Definition: DS18B20.cpp:81
uint8_t deleteChannel(const uint8_t *addr)
Definition: DS18B20.cpp:175
uint8_t getNextChannel(void)
Definition: DS18B20.cpp:14
uint8_t getNextFreeChannel(void)
Definition: DS18B20.cpp:168
const uint8_t * search(void)
Definition: DS18B20.cpp:30
uint8_t addSensor(const uint8_t *new_addr, uint8_t channel)
Definition: DS18B20.cpp:58
uint8_t checkSensors(void)
Definition: DS18B20.cpp:40
const uint8_t * getChannelAddress(uint8_t channel) const
Definition: DS18B20.cpp:184