Guest User

Untitled

a guest
Mar 2nd, 2020
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.50 KB | None | 0 0
  1. //- -----------------------------------------------------------------------------------------------------------------------
  2. // AskSin++
  3. // 2016-10-31 papa Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
  4. //- -----------------------------------------------------------------------------------------------------------------------
  5.  
  6. // define this to read the device id, serial and device type from bootloader section
  7. // #define USE_OTA_BOOTLOADER
  8.  
  9. #define EXTRAMILLIS 730 // 730 millisecond extra time to better hit the slot
  10. #define EI_NOTEXTERNAL
  11. #include <EnableInterrupt.h>
  12. #include <AskSinPP.h>
  13. #include <LowPower.h>
  14.  
  15. #include <Register.h>
  16. #include <MultiChannelDevice.h>
  17. #include <Weather.h>
  18. #include <sensors/Bme280.h>
  19.  
  20. // we use a Pro Mini
  21. // Arduino pin for the LED
  22. // D4 == PIN 4 on Pro Mini
  23. #define LED_PIN 4
  24. // Arduino pin for the config button
  25. // B0 == PIN 8 on Pro Mini
  26. #define CONFIG_BUTTON_PIN 8
  27.  
  28. // === Sensor offset settings ===
  29. // OFFSET for Temperature -> measured Temp +/- Offset = Announced Temperature
  30. #define OFFSETtemp 0 //e.g. -50 ≙ -5°C / 50 ≙ +5°C
  31. // OFFSET for Humidity -> measured Humidity +/- Offset = Announced Humidity
  32. #define OFFSEThumi 0 //e.g. -10 ≙ -10%RF / 10 ≙ +10%RF
  33.  
  34. // number of available peers per channel
  35. #define PEERS_PER_CHANNEL 6
  36.  
  37. // all library classes are placed in the namespace 'as'
  38. using namespace as;
  39.  
  40. // define all device properties
  41. const struct DeviceInfo PROGMEM devinfo = {
  42.     {0x34,0x56,0x79},       // Device ID
  43.     "papa111111",           // Device Serial
  44.     {0x00,0x3d},            // Device Model
  45.     0x10,                   // Firmware Version
  46.     as::DeviceType::THSensor, // Device Type
  47.     {0x01,0x00}             // Info Bytes
  48. };
  49.  
  50. typedef Bme280 SensorType; // I2C
  51.  
  52. /**
  53.  * Configure the used hardware
  54.  */
  55. typedef AvrSPI<10,11,12,13> SPIType;
  56. typedef Radio<SPIType,2> RadioType;
  57. typedef StatusLed<LED_PIN> LedType;
  58. typedef AskSinRTC<LedType,BatterySensor,RadioType> Hal;
  59.  
  60. /*
  61.  * Define List0 registers
  62.  */
  63. DEFREGISTER(WeatherRegsList0,MASTERID_REGS,DREG_BURSTRX)
  64. typedef RegList0<WeatherRegsList0> WeatherList0;
  65.  
  66. /*
  67.  * Sensors class is used by the WeatherChannel to measure the data. It has to implement
  68.  * temperature() and humidity().
  69.  */
  70. class Sensors : public Alarm {
  71.   SensorType    sensor;
  72. public:
  73.   Sensors () {}
  74.   // init the used hardware
  75.   void init () { sensor.init(); }
  76.   // return how many milliseconds the measure should start in front of sending the message
  77.   uint16_t before () const { return 4000; }
  78.   // get the data
  79.   virtual void trigger (__attribute__ ((unused)) AlarmClock& clock) {
  80.     DPRINTLN("Measure...  ");
  81.     sensor.measure();
  82.     DPRINT("T: ");DDEC(sensor.temperature()+OFFSETtemp);DPRINT("  H: ");DDECLN(sensor.humidity()+OFFSEThumi);
  83.   }
  84.   uint16_t temperature () { return sensor.temperature()+OFFSETtemp; }
  85.   uint8_t  humidity () { return sensor.humidity()+OFFSEThumi; }
  86. };
  87.  
  88.  
  89. typedef WeatherChannel<Hal,RTC,Sensors,PEERS_PER_CHANNEL,EXTRAMILLIS,WeatherList0> ChannelType;
  90. typedef MultiChannelDevice<Hal,ChannelType,1,WeatherList0> WeatherType;
  91.  
  92. Hal hal;
  93. WeatherType sdev(devinfo,0x20);
  94. ConfigButton<WeatherType> cfgBtn(sdev);
  95.  
  96. void setup () {
  97.   DINIT(57600,ASKSIN_PLUS_PLUS_IDENTIFIER);
  98.   sdev.init(hal);
  99.   buttonISR(cfgBtn,CONFIG_BUTTON_PIN);
  100.   hal.initBattery(60UL*60,22,19);
  101.   sdev.initDone();
  102. }
  103.  
  104. void loop() {
  105.   bool worked = hal.runready();
  106.   bool poll = sdev.pollRadio();
  107.   if( worked == false && poll == false ) {
  108.     hal.sleep<>();
  109.   }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment