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