remove old window copy
This commit is contained in:
parent
2508d2cf5e
commit
3d7e0e3ec6
@ -1,119 +0,0 @@
|
|||||||
#include <RCSwitch.h>
|
|
||||||
#include <avr/sleep.h>
|
|
||||||
#include <avr/power.h>
|
|
||||||
#include <avr/wdt.h>
|
|
||||||
#include <SystemStatus.h>
|
|
||||||
|
|
||||||
// Utility macros
|
|
||||||
#define adc_disable() (ADCSRA &= ~_BV(ADEN)) // disable ADC (before power-off)
|
|
||||||
#define adc_enable() (ADCSRA |= _BV(ADEN)) // re-enable ADC
|
|
||||||
#define enable_pin_interrupts() (GIMSK |= _BV(PCIE)) // Enable Pin Change Interrupts
|
|
||||||
|
|
||||||
// Pins
|
|
||||||
#define SWITCH 0
|
|
||||||
#define SENDER 2
|
|
||||||
#define CONTROLLER 4
|
|
||||||
|
|
||||||
RCSwitch mySwitch = RCSwitch();
|
|
||||||
char* WND_OPEN = "00000000000000000000000001000001";
|
|
||||||
char* WND_CLOSED = "00000000000000000000000001100001";
|
|
||||||
|
|
||||||
int counter = 0;
|
|
||||||
//SystemStatus sys = SystemStatus();
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
|
|
||||||
pinMode(SWITCH, INPUT_PULLUP);
|
|
||||||
pinMode(CONTROLLER, OUTPUT);
|
|
||||||
digitalWrite(CONTROLLER, LOW);
|
|
||||||
|
|
||||||
mySwitch.enableTransmit(SENDER);
|
|
||||||
mySwitch.setProtocol(2);
|
|
||||||
|
|
||||||
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
|
|
||||||
enable_pin_interrupts();
|
|
||||||
enableWdt();
|
|
||||||
// mySwitch.send(26, 32);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
sleep();
|
|
||||||
}
|
|
||||||
|
|
||||||
void sendWindowState() {
|
|
||||||
byte state = digitalRead(SWITCH);
|
|
||||||
if (state == HIGH) {
|
|
||||||
mySwitch.send(WND_OPEN);
|
|
||||||
} else {
|
|
||||||
mySwitch.send(WND_CLOSED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void sendBatteryStatus() {
|
|
||||||
// mySwitch.send(sys.getVCC(), 32);
|
|
||||||
}
|
|
||||||
|
|
||||||
long readVcc() {
|
|
||||||
// Read 1.1V reference against AVcc
|
|
||||||
// set the reference to Vcc and the measurement to the internal 1.1V reference
|
|
||||||
#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
|
||||||
ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
|
|
||||||
#elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
|
|
||||||
ADMUX = _BV(MUX5) | _BV(MUX0);
|
|
||||||
#elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
|
|
||||||
ADMUX = _BV(MUX3) | _BV(MUX2);
|
|
||||||
#else
|
|
||||||
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
delay(2); // Wait for Vref to settle
|
|
||||||
ADCSRA |= _BV(ADSC); // Start conversion
|
|
||||||
while (bit_is_set(ADCSRA,ADSC)); // measuring
|
|
||||||
|
|
||||||
uint8_t low = ADCL; // must read ADCL first - it then locks ADCH
|
|
||||||
uint8_t high = ADCH; // unlocks both
|
|
||||||
|
|
||||||
long result = (high<<8) | low;
|
|
||||||
|
|
||||||
result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
|
|
||||||
return result; // Vcc in millivolts
|
|
||||||
}
|
|
||||||
|
|
||||||
void sleep() {
|
|
||||||
PCMSK |= _BV(PCINT0); // Use PB0 as interrupt pin
|
|
||||||
adc_disable();
|
|
||||||
|
|
||||||
sleep_enable(); // Sets the Sleep Enable bit in the MCUCR Register (SE BIT)
|
|
||||||
sei(); // Enable interrupts
|
|
||||||
|
|
||||||
sleep_cpu(); // sleep
|
|
||||||
|
|
||||||
cli(); // Disable interrupts
|
|
||||||
PCMSK &= ~_BV(PCINT0); // Turn off PB0 as interrupt pin
|
|
||||||
sleep_disable(); // Clear SE bit
|
|
||||||
adc_enable();
|
|
||||||
|
|
||||||
sei(); // Enable interrupts
|
|
||||||
}
|
|
||||||
|
|
||||||
ISR(PCINT0_vect) {
|
|
||||||
sendWindowState();
|
|
||||||
}
|
|
||||||
|
|
||||||
ISR(WDT_vect) {
|
|
||||||
counter++;
|
|
||||||
if (counter % 38 == 0) {
|
|
||||||
sendWindowState();
|
|
||||||
counter = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//enable the wdt for 8sec interrupt
|
|
||||||
void enableWdt()
|
|
||||||
{
|
|
||||||
MCUSR = 0x00;
|
|
||||||
WDTCR |= _BV(WDCE) | _BV(WDE);
|
|
||||||
WDTCR = _BV(WDIE) | _BV(WDP3) | _BV(WDP0); //8192ms
|
|
||||||
}
|
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user