#include #include #include #include #include #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_sleep.h" #include "esp_log.h" #include "driver/uart.h" #include "driver/rtc_io.h" #include "esp_intr_alloc.h" #include "esp_attr.h" #include "driver/timer.h" #include #include "esp_intr_alloc.h" #include "transceiver.h" #include "rxTimer.h" #include "led.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. // // // Timing for NEXA Remote controls #define HIGH_PULSE 230 #define LOW_PULSE_0 340 #define LOW_PULSE_1 1410 #define SYNC_PULSE 2890 #define STOP_PULSE 10000 static void send1() { trcvSendHighLowPulse( HIGH_PULSE, LOW_PULSE_1); // 1 trcvSendHighLowPulse( HIGH_PULSE, LOW_PULSE_0 ); // 0 } static void send0() { trcvSendHighLowPulse( HIGH_PULSE, LOW_PULSE_0 ); // 0 trcvSendHighLowPulse( HIGH_PULSE, LOW_PULSE_1); // 1 } static void sendSync() { trcvSendHighLowPulse( HIGH_PULSE, SYNC_PULSE ); } static void sendStop() { trcvSendHighLowPulse( HIGH_PULSE, STOP_PULSE ); } static void sendNexaCodeNo(uint32_t orig_code) { uint32_t code=0; int32_t i; int32_t loop; ESP_LOGI("NEXA TX", "",(unsigned long int)orig_code); blinkTheLED(); if( 1 ) { trcvSwitch2transmit(); for( loop=4; loop>0; loop--) { code = orig_code; sendSync(); for(i=0; i < 32; i++) { if( code & 0x80000000 ) { send1(); } else { send0(); } code = (code << 1); } sendStop(); } trcvSwitch2receive(); } } // Public interface for sending a NEXA Code void sendNexaCode(uint32_t data) { if( nexaTxQueue != NULL ) xQueueSend( nexaTxQueue, &data, 0 ); } // Public interface for sending a NEXA Code in string format. For example: void sendNexaCodeStr(char *str) { if( str[0] == '<' && str[11] == '>' ) { uint32_t code; sscanf((const char *)str,"",(long unsigned int *)&code); sendNexaCode(code); } } static void nexaTxTask(void *pvParameter) { ESP_LOGI("NEXA TX", "Task started."); uint32_t data; while (1) { while( xQueueReceive( nexaTxQueue, &data, portMAX_DELAY ) == pdTRUE ) { sendNexaCodeNo(data); } } vTaskDelete(NULL); } void initNexaTransmit() { nexaTxQueue = xQueueCreate( 20, sizeof( uint32_t ) ); xTaskCreatePinnedToCore(&nexaTxTask, "nexaTxTask", 8192, NULL, tskIDLE_PRIORITY + 2, NULL, 0); }