|
@@ -1,3 +1,25 @@
|
|
|
|
+// 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
|
|
// Define which pins to use for different tasks
|
|
const int rxPinA = 7; // 433MHz RX, Connected to pin 7
|
|
const int rxPinA = 7; // 433MHz RX, Connected to pin 7
|
|
@@ -16,11 +38,10 @@ void setup()
|
|
sei(); // Enable interrupt
|
|
sei(); // Enable interrupt
|
|
|
|
|
|
// Setup the different serial communication channels
|
|
// Setup the different serial communication channels
|
|
- Serial.begin(9600); // Serial monitor (Over USB, when debugging with Arduino)
|
|
|
|
|
|
+ Serial.begin(115200); // Serial monitor (Over USB, when debugging with Arduino)
|
|
Serial1.begin(9600); // HW-UART (To Raspberry)
|
|
Serial1.begin(9600); // HW-UART (To Raspberry)
|
|
}
|
|
}
|
|
|
|
|
|
-extern unsigned long clas_o_x_data;
|
|
|
|
|
|
|
|
// Convert from 12-bit unsigned data to 32-bit signed data
|
|
// Convert from 12-bit unsigned data to 32-bit signed data
|
|
static int32_t convertToSignedTemp(uint16_t value)
|
|
static int32_t convertToSignedTemp(uint16_t value)
|
|
@@ -33,31 +54,49 @@ void loop()
|
|
{
|
|
{
|
|
static uint16_t width; // Stores the length of the received pulse
|
|
static uint16_t width; // Stores the length of the received pulse
|
|
static unsigned long totalRx = 0; // The total number of received pulses
|
|
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) ) {
|
|
if ( rcvDeQueue(&width) ) {
|
|
-
|
|
|
|
- //width = (width / 5) * 4; // 80%
|
|
|
|
|
|
|
|
totalRx++; // Increase the total received pulses
|
|
totalRx++; // Increase the total received pulses
|
|
|
|
|
|
- if( nextPulse_clas_o(width) ) {
|
|
|
|
|
|
+#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) ) {
|
|
|
|
|
|
- int16_t value = convertToSignedTemp( clas_o_x_data & 0xFFF );
|
|
|
|
- uint16_t id = (clas_o_x_data>>12) & 0x007;
|
|
|
|
-
|
|
|
|
- char rad[200];
|
|
|
|
- sprintf(rad,"Id:%u Temp:%d.%d\n",id,value/10,value%10);
|
|
|
|
- Serial.print(rad);
|
|
|
|
-
|
|
|
|
|
|
+ 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();
|
|
|
|
- }
|
|
|
|
|
|
+ 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);
|
|
|
|
|
|
- // Check if the received pulse is within limits for a start-pulse
|
|
|
|
- /*if ( 3400 <= width && width <= 3800 ) {
|
|
|
|
- Serial.print("Received one ! Total pulses: ");
|
|
|
|
- Serial.println(totalRx);
|
|
|
|
- }*/
|
|
|
|
|
|
+ telldus::resetDecoder();
|
|
|
|
+ }
|
|
|
|
+#endif
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|