performance improvment

This commit is contained in:
Nicu Hodos 2016-11-28 23:49:50 +01:00
parent 4851f7355b
commit 2f98b46929

View File

@ -5,8 +5,8 @@
#include <RCSwitch.h> #include <RCSwitch.h>
#include <SoftwareSerial_Tiny.h> #include <SoftwareSerial_Tiny.h>
#define DEBUG 0 #define DEBUG 1
#define RC_SWITCH 1 #define RC_SWITCH 0
// Utility macros // Utility macros
#define adc_disable() (ADCSRA &= ~_BV(ADEN)) // disable ADC (before power-off) #define adc_disable() (ADCSRA &= ~_BV(ADEN)) // disable ADC (before power-off)
@ -54,6 +54,7 @@ void setup() {
} }
void loop() { void loop() {
debug("loop");
sleep(); sleep();
} }
@ -89,7 +90,12 @@ ISR(PCINT0_vect) {
ISR(WDT_vect) { ISR(WDT_vect) {
timerTriggered = true; timerTriggered = true;
debug("wdt"); debug("wdt");
byte state = digitalRead(SWITCH);
if (state == LOW) {
sendCommand(false); sendCommand(false);
} else {
sendCommand(true);
}
disableWdt(); disableWdt();
} }
@ -98,34 +104,31 @@ void sleep() {
adc_disable(); adc_disable();
sleep_enable(); // Sets the Sleep Enable bit in the MCUCR Register (SE BIT) sleep_enable(); // Sets the Sleep Enable bit in the MCUCR Register (SE BIT)
sleep_bod_disable();
sei(); // Enable interrupts sei(); // Enable interrupts
sleep_cpu(); // sleep sleep_cpu(); // sleep
sleep_disable(); // Clear SE bit
cli(); // Disable interrupts cli(); // Disable interrupts
PCMSK &= ~_BV(PCINT0); // Turn off PB0 as interrupt pin PCMSK &= ~_BV(PCINT0); // Turn off PB0 as interrupt pin
sleep_disable(); // Clear SE bit
adc_enable(); adc_enable();
sei(); // Enable interrupts sei(); // Enable interrupts
} }
//enable the wdt for 1 sec interrupt //enable the wdt for 1 sec interrupt
void enableWdt() { inline void enableWdt() {
cli();
MCUSR = 0x00;
WDTCR |= _BV(WDCE) | _BV(WDE);
WDTCR = _BV(WDIE) | _BV(WDP2) | _BV(WDP1);
sei();
}
void disableWdt() {
cli();
wdt_reset(); wdt_reset();
MCUSR = 0x00;
WDTCR |= _BV(WDCE) | _BV(WDE);
WDTCR = _BV(WDIE) | _BV(WDP2) | _BV(WDP1);
}
inline void disableWdt() {
MCUSR = 0x00; MCUSR = 0x00;
WDTCR |= _BV(WDCE) | _BV(WDE); WDTCR |= _BV(WDCE) | _BV(WDE);
WDTCR = 0x00; WDTCR = 0x00;
sei();
} }
void debug(const char* msg) { void debug(const char* msg) {