123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- // Configure which sensors to compile/use
- #define ENABLE_CLAS_O_RX
- #define ENABLE_TELLDUS_RX
- // ---- Declare the functions and variables needed for the Clas O-namespace ----
- #ifdef ENABLE_CLAS_O_RX
- namespace clas_o {
- extern uint32_t x_data;
- boolean nextPulse (uint16_t width);
- void resetDecoder();
- }
- #endif
- // ---- Declare the functions and variables needed for the Telldus-namespace ----
- #ifdef ENABLE_TELLDUS_RX
- namespace telldus {
- extern uint64_t x_data;
- extern uint32_t meanPulseWidth;
- boolean nextPulse (uint16_t width);
- void resetDecoder();
- }
- #endif
- // Define which pins to use for different tasks
- const int rxPinA = 7; // 433MHz RX, Connected to pin 7
- const int ledPin = 17; // The RX LED has a defined Arduino pin
- // This code is only run once at startup
- void setup()
- {
- // Setup mode of each pin that we will use
- pinMode(ledPin, OUTPUT); // Set LED-pin as an output
- pinMode(rxPinA, INPUT);
- // Call the function that configures the interrupts
- cli(); // Clear interrupt
- setup_timer_interrupt();
- sei(); // Enable interrupt
- // Setup the different serial communication channels
- Serial.begin(115200); // Serial monitor (Over USB, when debugging with Arduino)
- Serial1.begin(9600); // HW-UART (To Raspberry)
- }
- // Convert from 12-bit unsigned data to 32-bit signed data
- static int32_t convertToSignedTemp(uint16_t value)
- {
- return ( (value >> 11) == 0 )? value : ((-1 ^ 0xFFF) | value);
- }
- // This code is called over and over again
- void loop()
- {
- static uint16_t width; // Stores the length of the received pulse
- static unsigned long totalRx = 0; // The total number of received pulses
- char str[100];
- const uint32_t now = millis(); // Time in mS
- if ( rcvDeQueue(&width) ) {
-
- totalRx++; // Increase the total received pulses
- #ifdef ENABLE_CLAS_O_RX
- if( clas_o::nextPulse(width) ) {
- static uint32_t old_rx_time = 0;
- static uint32_t old_x_data = 0;
- if( (now > (old_rx_time + 500)) || (old_x_data != clas_o::x_data) ) {
-
- const int16_t value = convertToSignedTemp( clas_o::x_data & 0xFFF ); // Temperature
- const uint16_t id = (clas_o::x_data>>12) & 0x007; // Id
-
- sprintf(str,"<TR:%u:%d:0>\n",id,value);
- Serial.print(str);
- old_x_data = clas_o::x_data;
- }
- clas_o::resetDecoder();
- old_rx_time = now;
- }
- #endif
- #ifdef ENABLE_TELLDUS_RX
- if( telldus::nextPulse(width) ) {
-
- const int16_t value = convertToSignedTemp( (telldus::x_data & 0x00FFF0000) >> 16 ); // Temperature
- const int16_t value2 = (telldus::x_data & 0x00000FF00) >> 8; // Moist
- const uint8_t id = (telldus::x_data & 0xFF0000000) >> 28; // Id
-
- sprintf(str,"<Tr:%u:%d:%d>\n",id,value,value2);
- //sprintf(str,"Id:%u Temp:%d.%d Mean:%u\n",id,value/10,value%10,telldus::meanPulseWidth);
- Serial.print(str);
- telldus::resetDecoder();
- }
- #endif
- }
- }
|