123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <time.h>
- #include <sys/time.h>
- #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 <stddef.h>
- #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.
- // <NT01995080>
- // <NT01995090>
- // 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", "<NT%08lX>",(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: <NT4C90AD91>
- void sendNexaCodeStr(char *str) {
- if( str[0] == '<' && str[11] == '>' ) {
- uint32_t code;
-
- sscanf((const char *)str,"<NT%08lX>",(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);
- }
|