From d30e3fa68d7192da22c1569f56f564b92896170d Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 4 Jun 2017 17:33:51 +0200 Subject: o Working decoder for Samsung remotes. --- src/radio-controller.cpp | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/radio-controller.cpp b/src/radio-controller.cpp index d31f5b7..8d3149c 100644 --- a/src/radio-controller.cpp +++ b/src/radio-controller.cpp @@ -8,7 +8,7 @@ #include "mcu/util.h" #include "misc.h" #include "decoder.h" -#include "samsung_decoder.h" +#include "daewoo_decoder.h" using mcu::arm::mutex; using namespace radio_controller; @@ -22,7 +22,7 @@ mcu::stm32cube::uart::uart_port uart2(&huart2); mcu::stm32cube::debug::dbg<100> dbg(uart2); template -class buffer_iterator : public iterator { +class buffer_iterator : public sample_iterator { const T *values_; const int size_; int idx_; @@ -31,7 +31,16 @@ public: buffer_iterator(const T *values, int size) : values_(values), size_(size), idx_(-1) {}; - __noinline + int size() override + { + return size_; + } + + void reset() override + { + idx_ = -1; + } + bool next() override { if (has_next()) { @@ -224,9 +233,19 @@ void main_loop() HAL_NVIC_DisableIRQ(TIM2_IRQn); - samsung_decoder d; + daewoo_decoder d; auto it = ir_buffer.iterator(); - d.decode(&it); + auto result = d.decode(&it); + + if (result.state == decoding_state::TOO_SHORT) { + printf("Too short\n"); + } else if (result.state == decoding_state::SHORT_BODY) { + printf("Short body\n"); + } else if (result.state == decoding_state::BAD_START) { + printf("Bad start\n"); + } else if (result.state == 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)); + } ir_buffer.reset(); ir_buffer_lock.unlock(); @@ -283,10 +302,10 @@ void ir_rx(TIM_HandleTypeDef *htim) if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1) { ir_value1 = static_cast(htim->Instance->CCR1); - debug_pin(2); +// debug_pin(2); } else if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_2) { ir_value2 = static_cast(htim->Instance->CCR2); - debug_pin(3); +// debug_pin(3); } if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1 && ir_buffer.check_first()) { @@ -298,9 +317,9 @@ void ir_rx(TIM_HandleTypeDef *htim) if (ir_buffer_lock.try_lock()) { auto period = values::to_us(ir_value1); auto pulse = values::to_us(ir_value2); - if (ir_buffer.size() == 0) { - debug_pin(5); - } +// if (ir_buffer.size() == 0) { +// debug_pin(5); +// } ir_buffer.append({.period_us=period, .pulse_us=pulse}); ir_buffer_lock.unlock(); -- cgit v1.2.3