split TinySensor into TinySwitch
This commit is contained in:
parent
542ca3eddf
commit
2b414d3778
@ -6,8 +6,8 @@ class ContactSensor: public TinySensor {
|
||||
SensorType sensorType = CONTACT;
|
||||
|
||||
public:
|
||||
ContactSensor(short id, short senderPin) :
|
||||
TinySensor(id, senderPin) {
|
||||
ContactSensor(short id) :
|
||||
TinySensor(id) {
|
||||
}
|
||||
|
||||
void sendStateAndVoltage(bool state) {
|
||||
|
||||
@ -6,8 +6,8 @@ class HumiditySensor : public TinySensor {
|
||||
SensorType sensorType = HUMIDITY;
|
||||
|
||||
public:
|
||||
HumiditySensor(short id, short senderPin) :
|
||||
TinySensor(id, senderPin) {
|
||||
HumiditySensor(short id) :
|
||||
TinySensor(id) {
|
||||
}
|
||||
|
||||
void sendHumidityAndVoltage(int humidity) {
|
||||
|
||||
@ -6,8 +6,8 @@ class TempSensor : public TinySensor {
|
||||
SensorType sensorType = TEMPERATURE;
|
||||
|
||||
public:
|
||||
TempSensor(short id, short senderPin) :
|
||||
TinySensor(id, senderPin) {
|
||||
TempSensor(short id) :
|
||||
TinySensor(id) {
|
||||
}
|
||||
|
||||
void sendTempAndVoltage(int temp) {
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <RCSwitch.h>
|
||||
#include "TinySwitch.h"
|
||||
#include "Tiny.h"
|
||||
|
||||
using TinySwitch::sendInfo;
|
||||
|
||||
class TinySensor {
|
||||
protected:
|
||||
short id;
|
||||
short senderPin;
|
||||
RCSwitch mySwitch = RCSwitch();
|
||||
|
||||
long readVcc() {
|
||||
// Read 1.1V reference against AVcc
|
||||
@ -32,18 +32,8 @@ protected:
|
||||
return result; // Vcc in millivolts
|
||||
}
|
||||
|
||||
void sendInfo(unsigned long value) {
|
||||
mySwitch.send(value, 32);
|
||||
}
|
||||
|
||||
public:
|
||||
TinySensor(short id, short senderPin) {
|
||||
TinySensor(short id) {
|
||||
this->id = id;
|
||||
this->senderPin = senderPin;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
mySwitch.enableTransmit(senderPin);
|
||||
mySwitch.setProtocol(2);
|
||||
}
|
||||
};
|
||||
|
||||
16
libraries/Tiny/TinySwitch.h
Normal file
16
libraries/Tiny/TinySwitch.h
Normal file
@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <RCSwitch.h>
|
||||
|
||||
namespace TinySwitch {
|
||||
RCSwitch mySwitch = RCSwitch();
|
||||
|
||||
void sendInfo(unsigned long value) {
|
||||
mySwitch.send(value, 32);
|
||||
}
|
||||
|
||||
void setup(short senderPin) {
|
||||
mySwitch.enableTransmit(senderPin);
|
||||
mySwitch.setProtocol(2);
|
||||
}
|
||||
}
|
||||
@ -14,26 +14,26 @@ class TinyPower {
|
||||
|
||||
public:
|
||||
static void setup() {
|
||||
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
|
||||
enable_pin_interrupts();
|
||||
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
|
||||
enable_pin_interrupts();
|
||||
}
|
||||
|
||||
static void sleep(byte pin = PCINT0) {
|
||||
PCMSK |= _BV(pin); // Use PB0 as interrupt pin
|
||||
adc_disable();
|
||||
static void sleep(byte pin = -1) {
|
||||
if (pin >= 0) PCMSK |= _BV(pin); // Use PB0 as interrupt pin
|
||||
adc_disable();
|
||||
|
||||
sleep_enable(); // Sets the Sleep Enable bit in the MCUCR Register (SE BIT)
|
||||
sleep_bod_disable();
|
||||
sei(); // Enable interrupts
|
||||
sleep_enable(); // Sets the Sleep Enable bit in the MCUCR Register (SE BIT)
|
||||
sleep_bod_disable();
|
||||
sei(); // Enable interrupts
|
||||
|
||||
sleep_cpu(); // sleep
|
||||
sleep_cpu(); // sleep
|
||||
|
||||
sleep_disable(); // Clear SE bit
|
||||
cli(); // Disable interrupts
|
||||
PCMSK &= ~_BV(pin); // Turn off PB0 as interrupt pin
|
||||
adc_enable();
|
||||
sleep_disable(); // Clear SE bit
|
||||
cli(); // Disable interrupts
|
||||
if (pin >= 0) PCMSK &= ~_BV(pin); // Turn off PB0 as interrupt pin
|
||||
adc_enable();
|
||||
|
||||
sei(); // Enable interrupts
|
||||
sei(); // Enable interrupts
|
||||
}
|
||||
|
||||
static void enableWdt(byte time) {
|
||||
|
||||
@ -18,19 +18,19 @@ struct DhtValues {
|
||||
};
|
||||
DhtValues readTemp();
|
||||
|
||||
TempSensor tempSensor = TempSensor(TEMP_SENSOR, SENDER);
|
||||
HumiditySensor humidSensor = HumiditySensor(TEMP_SENSOR, SENDER);
|
||||
TempSensor tempSensor = TempSensor(TEMP_SENSOR);
|
||||
HumiditySensor humidSensor = HumiditySensor(TEMP_SENSOR);
|
||||
DHT dht(DHT_PIN, DHT22);
|
||||
|
||||
volatile int counter = 0;
|
||||
|
||||
void setup() {
|
||||
|
||||
tempSensor.setup();
|
||||
pinMode(TEMP_POSITIVE, OUTPUT);
|
||||
digitalWrite(TEMP_POSITIVE, HIGH);
|
||||
dht.begin();
|
||||
|
||||
TinySwitch::setup(SENDER);
|
||||
TinyPower::setup();
|
||||
TinyPower::enableWdt(WDTO_8S);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user