From 4ee01dab6105e346b731a13321a3e6a5d111d3e4 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 4 Jun 2017 22:14:04 +0200 Subject: o Trying for a more generic decoder structure, should be able to be dynamically programmed later on. o Adding decoder for NEC. --- src/radio-controller.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/radio-controller.cpp b/src/radio-controller.cpp index e4218cc..11da06f 100644 --- a/src/radio-controller.cpp +++ b/src/radio-controller.cpp @@ -1,5 +1,6 @@ #include "decoder.h" -#include "samsung_decoder.h" +//#include "samsung_decoder.h" +#include "script_decoder.h" #include #include @@ -12,7 +13,10 @@ #include "misc.h" using mcu::arm::mutex; -using namespace radio_controller; +using radio_controller::sample_iterator; +using radio_controller::sample; +using radio_controller::instruction; +using radio_controller::script_decoder; extern IWDG_HandleTypeDef hiwdg; extern TIM_HandleTypeDef htim1; @@ -195,12 +199,42 @@ void main_post_init() static uint32_t tick_next = 0; +radio_controller::end end; + +/* +static const radio_controller::start samsung_start{9000, 4500}; +static const radio_controller::data samsung_data{2250, 560, 1125, 560}; + +static const instruction *const samsung_instructions[] = { + &samsung_start, + &samsung_data, + &end, +}; +*/ + +// NEC? +static const radio_controller::start nec_start{13500, 9000}; +static const radio_controller::data nec_data{2250, 560, 1125, 560}; + +static const instruction *const nec_instructions[] = { + &nec_start, + &nec_data, &nec_data, &nec_data, &nec_data, + &nec_data, &nec_data, &nec_data, &nec_data, + &nec_data, &nec_data, &nec_data, &nec_data, + &nec_data, &nec_data, &nec_data, &nec_data, + &nec_data, &nec_data, &nec_data, &nec_data, + &nec_data, &nec_data, &nec_data, &nec_data, + &nec_data, &nec_data, &nec_data, &nec_data, + &nec_data, &nec_data, &nec_data, &nec_data, + &end, +}; + void main_loop() { auto now = HAL_GetTick(); if (now >= tick_next) { - printf("now=%" PRIu32 "\n", now); +// printf("now=%" PRIu32 "\n", now); // auto *str = "1234567890\n"; // CDC_Transmit_FS(const_cast(reinterpret_cast(str)), 5); @@ -234,6 +268,7 @@ void main_loop() HAL_NVIC_DisableIRQ(TIM2_IRQn); + /* samsung_decoder d; auto it = ir_buffer.iterator(); auto result = d.decode(&it); @@ -252,6 +287,31 @@ void main_loop() printf("Samsung: Manufacturer=%" PRIu32 ", 0x%" PRIx32 ", command=%" PRIu32 ", 0x%" PRIx32 "\n", manufacturer, manufacturer, command, command); } + */ + +// script_decoder sd{samsung_instructions, SizeOfArray(samsung_instructions_)}; + script_decoder sd{nec_instructions, SizeOfArray(nec_instructions)}; + + auto it = ir_buffer.iterator(); + auto result = sd.decode(&it); + + if (result.state == radio_controller::decoding_state::FAIL) { + printf("FAIL\n"); + + it.reset(); + while (it.next()) { + auto s = it.value(); + printf("% 5d us % 5d us\n", s.period_us, s.pulse_us); + } + + } else if (result.state == radio_controller::decoding_state::OK) { + printf("OK: size=%d, value: 0x%08" PRIx32 "%08" PRIx32 "\n", result.data.size(), + result.data.u32(1), result.data.u32(0)); +// uint32_t manufacturer = result.data.extract_bits(0, 12); +// uint32_t command = result.data.extract_bits(12, 8); +// printf("Samsung: Manufacturer=%" PRIu32 ", 0x%" PRIx32 ", command=%" PRIu32 ", 0x%" PRIx32 "\n", +// manufacturer, manufacturer, command, command); + } ir_buffer.reset(); ir_buffer_lock.unlock(); -- cgit v1.2.3