split TinySensor into TinySwitch
This commit is contained in:
parent
580266e50e
commit
1156d7cbef
@ -6,8 +6,8 @@ class ContactSensor: public TinySensor {
|
|||||||
SensorType sensorType = CONTACT;
|
SensorType sensorType = CONTACT;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ContactSensor(short id, short senderPin) :
|
ContactSensor(short id) :
|
||||||
TinySensor(id, senderPin) {
|
TinySensor(id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendStateAndVoltage(bool state) {
|
void sendStateAndVoltage(bool state) {
|
||||||
|
|||||||
@ -6,8 +6,8 @@ class HumiditySensor : public TinySensor {
|
|||||||
SensorType sensorType = HUMIDITY;
|
SensorType sensorType = HUMIDITY;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HumiditySensor(short id, short senderPin) :
|
HumiditySensor(short id) :
|
||||||
TinySensor(id, senderPin) {
|
TinySensor(id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendHumidityAndVoltage(int humidity) {
|
void sendHumidityAndVoltage(int humidity) {
|
||||||
|
|||||||
@ -6,8 +6,8 @@ class TempSensor : public TinySensor {
|
|||||||
SensorType sensorType = TEMPERATURE;
|
SensorType sensorType = TEMPERATURE;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TempSensor(short id, short senderPin) :
|
TempSensor(short id) :
|
||||||
TinySensor(id, senderPin) {
|
TinySensor(id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendTempAndVoltage(int temp) {
|
void sendTempAndVoltage(int temp) {
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <RCSwitch.h>
|
#include "TinySwitch.h"
|
||||||
#include "Tiny.h"
|
#include "Tiny.h"
|
||||||
|
|
||||||
|
using TinySwitch::sendInfo;
|
||||||
|
|
||||||
class TinySensor {
|
class TinySensor {
|
||||||
protected:
|
protected:
|
||||||
short id;
|
short id;
|
||||||
short senderPin;
|
|
||||||
RCSwitch mySwitch = RCSwitch();
|
|
||||||
|
|
||||||
long readVcc() {
|
long readVcc() {
|
||||||
// Read 1.1V reference against AVcc
|
// Read 1.1V reference against AVcc
|
||||||
@ -32,18 +32,8 @@ protected:
|
|||||||
return result; // Vcc in millivolts
|
return result; // Vcc in millivolts
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendInfo(unsigned long value) {
|
|
||||||
mySwitch.send(value, 32);
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TinySensor(short id, short senderPin) {
|
TinySensor(short id) {
|
||||||
this->id = 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:
|
public:
|
||||||
static void setup() {
|
static void setup() {
|
||||||
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
|
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
|
||||||
enable_pin_interrupts();
|
enable_pin_interrupts();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sleep(byte pin = PCINT0) {
|
static void sleep(byte pin = -1) {
|
||||||
PCMSK |= _BV(pin); // Use PB0 as interrupt pin
|
if (pin >= 0) PCMSK |= _BV(pin); // Use PB0 as interrupt pin
|
||||||
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();
|
sleep_bod_disable();
|
||||||
sei(); // Enable interrupts
|
sei(); // Enable interrupts
|
||||||
|
|
||||||
sleep_cpu(); // sleep
|
sleep_cpu(); // sleep
|
||||||
|
|
||||||
sleep_disable(); // Clear SE bit
|
sleep_disable(); // Clear SE bit
|
||||||
cli(); // Disable interrupts
|
cli(); // Disable interrupts
|
||||||
PCMSK &= ~_BV(pin); // Turn off PB0 as interrupt pin
|
if (pin >= 0) PCMSK &= ~_BV(pin); // Turn off PB0 as interrupt pin
|
||||||
adc_enable();
|
adc_enable();
|
||||||
|
|
||||||
sei(); // Enable interrupts
|
sei(); // Enable interrupts
|
||||||
}
|
}
|
||||||
|
|
||||||
static void enableWdt(byte time) {
|
static void enableWdt(byte time) {
|
||||||
|
|||||||
@ -20,7 +20,7 @@ SoftwareSerial AttinySerial(RxD, TxD);
|
|||||||
|
|
||||||
int readTemp();
|
int readTemp();
|
||||||
|
|
||||||
TempSensor sensor = TempSensor(TEMP_SENSOR, SENDER);
|
TempSensor sensor = TempSensor(TEMP_SENSOR);
|
||||||
|
|
||||||
volatile int counter = 0;
|
volatile int counter = 0;
|
||||||
|
|
||||||
@ -30,11 +30,11 @@ void setup() {
|
|||||||
AttinySerial.begin(9600);
|
AttinySerial.begin(9600);
|
||||||
AttinySerial.println("starting...");
|
AttinySerial.println("starting...");
|
||||||
#endif
|
#endif
|
||||||
sensor.setup();
|
|
||||||
analogReference(INTERNAL);
|
analogReference(INTERNAL);
|
||||||
pinMode(TEMP_POSITIVE, OUTPUT);
|
pinMode(TEMP_POSITIVE, OUTPUT);
|
||||||
digitalWrite(TEMP_POSITIVE, LOW);
|
digitalWrite(TEMP_POSITIVE, LOW);
|
||||||
|
|
||||||
|
TinySwitch::setup(SENDER);
|
||||||
TinyPower::setup();
|
TinyPower::setup();
|
||||||
TinyPower::enableWdt(WDTO_8S);
|
TinyPower::enableWdt(WDTO_8S);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user