|
@@ -19,17 +19,36 @@
|
|
|
#include "rxTimer.h"
|
|
|
#include "led.h"
|
|
|
#include "udp_client.h"
|
|
|
+#include "nexaTransmit.h"
|
|
|
|
|
|
QueueHandle_t nexaTxQueue = NULL;
|
|
|
|
|
|
-// Nexa : http://elektronikforumet.com/wiki/index.php/RF_Protokoll_-_Nexa_sj%C3%A4lvl%C3%A4rande
|
|
|
-// "1" = 295 µs hög och 170 µs låg
|
|
|
-// "0" = 295 µs hög och 920 µs låg
|
|
|
-//
|
|
|
-// Etta skickas som 10 och Nolla som 01
|
|
|
-//
|
|
|
-// Dessa siffror från web-sidan stämmer inte med den Nexa-kontroll som jag har.
|
|
|
-// Jag har rättat dessa med siffror från verkligheten. Finns i define's nedan.
|
|
|
+
|
|
|
+
|
|
|
+/*****************************************************************************
|
|
|
+ * Nexa : http://elektronikforumet.com/wiki/index.php/RF_Protokoll_-_Nexa_sj%C3%A4lvl%C3%A4rande
|
|
|
+ * "1" = 295 µs hög och 170 µs låg
|
|
|
+ * "0" = 295 µs hög och 920 µs låg
|
|
|
+ * Etta skickas som 10 och Nolla som 01
|
|
|
+ * Dessa siffror från web-sidan stämmer inte med den Nexa-kontroll som jag har.
|
|
|
+ * Jag har rättat dessa med siffror från verkligheten. Finns i define's nedan.
|
|
|
+ *
|
|
|
+ * ---------------------------------------------------------------------------
|
|
|
+ * From: https://github.com/TheCarlG/NexaCtrl/blob/master/NexaCtrl.cpp
|
|
|
+ *
|
|
|
+ * bits 0-25: the group code - a 26bit number assigned to controllers.
|
|
|
+ * bit 26: group flag
|
|
|
+ * bit 27: on/off/dim flag
|
|
|
+ * bits 28-31: the device code - 4bit number.
|
|
|
+ * bits 32-35: the dim level - 4bit number.
|
|
|
+ *
|
|
|
+ * The extra 4 dim bits are optional and used for setting absolute dim level
|
|
|
+ * Normally the on/off-bit is transmitted as a normal On=10, Off=01, but when
|
|
|
+ * including a dim-level the on/off-bit is transmitted as 00
|
|
|
+ *
|
|
|
+ * Dim levels are 0-15. 0=Lowest dim, 15=100%
|
|
|
+ * 0 is not off. A separate off needs to be sent to turn the light off.
|
|
|
+ * ***************************************************************************/
|
|
|
|
|
|
// <NT01995080>
|
|
|
// <NT01995090>
|
|
@@ -53,6 +72,13 @@ static void send0() {
|
|
|
trcvSendHighLowPulse( HIGH_PULSE, LOW_PULSE_1); // 1
|
|
|
}
|
|
|
|
|
|
+// Special 00-bit used when including 4 dim bits last in message
|
|
|
+static void send00() {
|
|
|
+
|
|
|
+ trcvSendHighLowPulse( HIGH_PULSE, LOW_PULSE_0 ); // 0
|
|
|
+ trcvSendHighLowPulse( HIGH_PULSE, LOW_PULSE_0); // 0
|
|
|
+}
|
|
|
+
|
|
|
static void sendSync() {
|
|
|
trcvSendHighLowPulse( HIGH_PULSE, SYNC_PULSE );
|
|
|
}
|
|
@@ -61,20 +87,24 @@ static void sendStop() {
|
|
|
trcvSendHighLowPulse( HIGH_PULSE, STOP_PULSE );
|
|
|
}
|
|
|
|
|
|
-static void sendNexaCodeNo(uint32_t orig_code) {
|
|
|
+static void sendNexaCodeNo(uint32_t orig_code, bool send_dim, uint8_t dim_level) {
|
|
|
|
|
|
uint32_t code=0;
|
|
|
int32_t i;
|
|
|
int32_t loop;
|
|
|
|
|
|
- ESP_LOGI("NEXA TX", "<NT%08lX>",(unsigned long int)orig_code);
|
|
|
+ if( send_dim == true )
|
|
|
+ ESP_LOGI("NEXA TX", "<NT%08lX> + Dim:%u",(unsigned long int)orig_code, dim_level);
|
|
|
+ else
|
|
|
+ ESP_LOGI("NEXA TX", "<NT%08lX>",(unsigned long int)orig_code);
|
|
|
+
|
|
|
blinkTheLED();
|
|
|
|
|
|
if( 1 ) {
|
|
|
|
|
|
trcvSwitch2transmit();
|
|
|
|
|
|
- for( loop=4; loop>0; loop--) {
|
|
|
+ for( loop=5; loop>0; loop--) {
|
|
|
|
|
|
code = orig_code;
|
|
|
|
|
@@ -82,54 +112,90 @@ static void sendNexaCodeNo(uint32_t orig_code) {
|
|
|
|
|
|
for(i=0; i < 32; i++) {
|
|
|
|
|
|
- if( code & 0x80000000 ) {
|
|
|
- send1();
|
|
|
+ // Bit 27 is the on/off/dim-bit
|
|
|
+ // Check if we should send it as a special dim-bit
|
|
|
+ if( i == 27 && send_dim == true ) {
|
|
|
+ send00();
|
|
|
}
|
|
|
else {
|
|
|
- send0();
|
|
|
+ // Normal on/off control
|
|
|
+ if( code & 0x80000000 ) send1(); else send0();
|
|
|
}
|
|
|
code = (code << 1);
|
|
|
}
|
|
|
+
|
|
|
+ code = dim_level;
|
|
|
+
|
|
|
+ // Check if we should send 4 extra dim-bits at the end
|
|
|
+ if( send_dim == true ) {
|
|
|
+ for(i=0; i < 4; i++) {
|
|
|
+ if( code & 0x00000008 ) send1(); else send0();
|
|
|
+ code = (code << 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
sendStop();
|
|
|
-
|
|
|
}
|
|
|
|
|
|
trcvSwitch2receive();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// Public interface for sending a NEXA Code
|
|
|
-void sendNexaCode(uint32_t data) {
|
|
|
+/**
|
|
|
+ * Public interface for sending a NEXA Code
|
|
|
+ */
|
|
|
+void sendNexaCode(uint32_t data, bool send_dim, uint8_t dim_level ) {
|
|
|
+
|
|
|
+ nexaCodeData_t txData;
|
|
|
+
|
|
|
+ txData.data = data;
|
|
|
+ txData.send_dim = send_dim;
|
|
|
+ txData.dim_level = dim_level;
|
|
|
|
|
|
- if( nexaTxQueue != NULL ) xQueueSend( nexaTxQueue, &data, 0 );
|
|
|
+ if( nexaTxQueue != NULL ) xQueueSend( nexaTxQueue, &txData, 0 );
|
|
|
}
|
|
|
|
|
|
// Public interface for sending a NEXA Code in string format. For example: <NT4C90AD91>
|
|
|
void sendNexaCodeStr(char *str) {
|
|
|
|
|
|
- if( str[0] == '<' && str[11] == '>' ) {
|
|
|
+ char diffLevel = '\0'; // 0-F = 0-15 Dim-level
|
|
|
+
|
|
|
+ if( strlen(str) == 13 && str[0] == '<' && str[12] == '>' ) {
|
|
|
+ diffLevel = str[11]; // 0-F = 0-15 Dim-level
|
|
|
+ str[11] = '>';
|
|
|
+ str[12] = '\0';
|
|
|
+ }
|
|
|
+
|
|
|
+ if( strlen(str) == 12 && str[0] == '<' && str[11] == '>' ) {
|
|
|
|
|
|
uint32_t code;
|
|
|
+
|
|
|
+ bool send_dim = (diffLevel == '\0') ? false : true;
|
|
|
+ uint8_t dim_level = (send_dim == true) ? diffLevel - '0' : 0;
|
|
|
|
|
|
sscanf((const char *)str,"<NT%08lX>",(long unsigned int *)&code);
|
|
|
|
|
|
- sendNexaCode(code);
|
|
|
+ sendNexaCode(code, send_dim, dim_level);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+// GIT ESP32 Before: 0ae960f2fe92de1ee9c7c624b7115d06faca119e
|
|
|
+
|
|
|
static void nexaTxTask(void *pvParameter)
|
|
|
{
|
|
|
ESP_LOGI("NEXA TX", "Task started.");
|
|
|
- uint32_t data;
|
|
|
+ nexaCodeData_t txData;
|
|
|
+
|
|
|
while (1)
|
|
|
{
|
|
|
- while( xQueueReceive( nexaTxQueue, &data, portMAX_DELAY ) == pdTRUE ) {
|
|
|
- sendNexaCodeNo(data);
|
|
|
+ while( xQueueReceive( nexaTxQueue, &txData, portMAX_DELAY ) == pdTRUE ) {
|
|
|
+
|
|
|
+ sendNexaCodeNo(txData.data, txData.send_dim, txData.dim_level); // Do the radio-transmission
|
|
|
|
|
|
// Forward the NEXA code to the next transceiver
|
|
|
char strCode[20];
|
|
|
- sprintf(strCode,"<NT%08lX>",(unsigned long int)data);
|
|
|
+ sprintf(strCode,"<NT%08lX>",(unsigned long int)txData.data);
|
|
|
forwardNEXAMessage(strCode);
|
|
|
|
|
|
vTaskDelay(200 / portTICK_PERIOD_MS); // Wait a while between transmits
|
|
@@ -140,7 +206,7 @@ static void nexaTxTask(void *pvParameter)
|
|
|
|
|
|
void initNexaTransmit() {
|
|
|
|
|
|
- nexaTxQueue = xQueueCreate( 20, sizeof( uint32_t ) );
|
|
|
+ nexaTxQueue = xQueueCreate( 20, sizeof( nexaCodeData_t ) );
|
|
|
|
|
|
xTaskCreatePinnedToCore(&nexaTxTask, "nexaTxTask", 8192, NULL, tskIDLE_PRIORITY + 10, NULL, 1);
|
|
|
}
|