diff --git a/examples/HM-WDS40-TH-I/HM-WDS40-TH-I.ino b/examples/HM-WDS40-TH-I/HM-WDS40-TH-I.ino new file mode 100644 index 00000000..6ce39c13 --- /dev/null +++ b/examples/HM-WDS40-TH-I/HM-WDS40-TH-I.ino @@ -0,0 +1,161 @@ +//- ----------------------------------------------------------------------------------------------------------------------- +// AskSin++ +// 2016-10-31 papa Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/ +//- ----------------------------------------------------------------------------------------------------------------------- + +// define this to read the device id, serial and device type from bootloader section +// #define USE_OTA_BOOTLOADER + +#define EXTRAMILLIS 730 // 730 millisecond extra time to better hit the slot +#define EI_NOTEXTERNAL // Disable all external interruptes +#include +#include +#include +#include +#include +#include + +#define LED_PIN 4 +#define CONFIG_BUTTON_PIN 8 + +// === Festlegung welcher Sensor benutzt wird === +#define SENSOR_BME280 +//#define SENSOR_DHT22 +//#define SENSOR_SHT10 +//#define SENSOR_SHT31 +//#define SENSOR_SI7021 + +// === Festelgung der Clock === +// RTC Clock Benutzen (zB HMSensor mit verbautem 32kHz Quarz) +#define USE_RTC + +// === Batteriespannungsmessung === +// Interne Messung (Batteriespannung am AVR) +//#define BAT_SENSOR BatterySensor +//#define BAT_VOLT_LOW 21 // 2.1V +//#define BAT_VOLT_CRITICAL 19 // 1.9V +// Externe Messung (Batteriespannung über GPIO Pins) (TLV61224 StepUp can handle 0.7V) +#define BAT_VOLT_LOW 20 // 2.0V +#define BAT_VOLT_CRITICAL 13 // 1.3V +#define BAT_SENSOR BatterySensorUni<17,7,3000> + +// === Sensor Offset Einstellungen === +// OFFSET für Temperatur -> gemessene Temp +/- Offset = Angezeigte Temp. +#define OFFSETtemp 0 //z.B -50 ≙ -5°C / 50 ≙ +5°C +// OFFSET für Luftfeuchte -> gemessene Luftf. +/- Offset = Angezeigte Luftf. +#define OFFSEThumi 0 //z.B -10 ≙ -10%RF / 10 ≙ +10%RF + +// number of available peers per channel +#define PEERS_PER_CHANNEL 6 + +// all library classes are placed in the namespace 'as' +using namespace as; + +// define all device properties +const struct DeviceInfo PROGMEM devinfo = { + {0x34,0x56,0x79}, // Device ID + "papa111111", // Device Serial + {0x00,0x3f}, // Device Model: HM-WDS40-TH-I + 0x10, // Firmware Version + as::DeviceType::THSensor, // Device Type + {0x01,0x00} // Info Bytes +}; + + +#ifdef SENSOR_BME280 +#include +typedef Bme280 SensorType; +#endif +#ifdef SENSOR_DHT22 +#include +typedef Dht<4,DHT22> SensorType; +#endif +#ifdef SENSOR_SHT10 +#include +typedef Sht10 SensorType; +#endif +#ifdef SENSOR_SHT31 +#include +typedef Sht31<> SensorType; +#endif +#ifdef SENSOR_SI7021 +#include +typedef Si7021 SensorType; +#endif + +/** + * Configure the used hardware + */ +typedef AvrSPI<10,11,12,13> SPIType; +typedef Radio RadioType; +typedef StatusLed LedType; +#ifdef USE_RTC +typedef AskSinRTC Hal; +#else +typedef AskSin Hal; +#endif + +/* + * Define List0 registers + */ +DEFREGISTER(WeatherRegsList0,MASTERID_REGS,DREG_BURSTRX) +typedef RegList0 WeatherList0; + +/* + * Sensors class is used by the WeatherChannel to measure the data. It has to implement + * temperature() and humidity(). + */ +class Sensors : public Alarm { + SensorType sensor; +public: + Sensors () {} + // init the used hardware + void init () { sensor.init(); } + // return how many milliseconds the measure should start in front of sending the message + uint16_t before () const { return 4000; } + // get the data + virtual void trigger (__attribute__ ((unused)) AlarmClock& clock) { + DPRINTLN("Measure... "); + sensor.measure(); + DPRINT("T: ");DDEC(sensor.temperature()+OFFSETtemp);DPRINT(" H: ");DDECLN(sensor.humidity()+OFFSEThumi); + } + uint16_t temperature () { return sensor.temperature()+OFFSETtemp; } + uint8_t humidity () { return sensor.humidity()+OFFSEThumi; } +}; + +#ifdef USE_RTC +typedef WeatherChannel ChannelType; +#else +typedef WeatherChannel ChannelType; +#endif +typedef MultiChannelDevice WeatherType; + +Hal hal; +WeatherType sdev(devinfo,0x20); +ConfigButton cfgBtn(sdev); + +void setup () { + DINIT(57600,ASKSIN_PLUS_PLUS_IDENTIFIER); + sdev.init(hal); + buttonISR(cfgBtn,CONFIG_BUTTON_PIN); + // Measure Battery every 1h + hal.initBattery(60UL*60,BAT_VOLT_LOW,BAT_VOLT_CRITICAL); + sdev.initDone(); + DDEVINFO(sdev); +} + +void loop() { + bool worked = hal.runready(); + bool poll = sdev.pollRadio(); + if( worked == false && poll == false ) { + if( hal.battery.critical() ) { + // this call will never return + hal.activity.sleepForever(hal); + } + #ifdef USE_RTC + hal.sleep<>(); + #else + hal.activity.savePower>(hal); + #endif + } +} diff --git a/examples/HM-WDS40-TH-I/platformio.ini b/examples/HM-WDS40-TH-I/platformio.ini new file mode 100644 index 00000000..131df0a3 --- /dev/null +++ b/examples/HM-WDS40-TH-I/platformio.ini @@ -0,0 +1,20 @@ +[platformio] +src_dir = . + +[env:pro8MHzatmega328] +platform = atmelavr +framework = arduino +board = pro8MHzatmega328 +monitor_speed = 57600 + +lib_deps = + AskSinPP + EnableInterrupt + Low-Power +# Enable the sensors you want to use: +# BME280 +# DHT sensor library +# Adafruit Unified Sensor +# Sensirion +# Adafruit SHT31 Library +# Si7021