summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2017-06-04 17:33:51 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2017-06-04 17:33:51 +0200
commitd30e3fa68d7192da22c1569f56f564b92896170d (patch)
treefdbfbe53a9c9cb6f5136af53e17f831b069337a2 /src
parenta484b095fb03313f5f192b23c90d04972ca3b957 (diff)
downloadradio-controller-d30e3fa68d7192da22c1569f56f564b92896170d.tar.gz
radio-controller-d30e3fa68d7192da22c1569f56f564b92896170d.tar.bz2
radio-controller-d30e3fa68d7192da22c1569f56f564b92896170d.tar.xz
radio-controller-d30e3fa68d7192da22c1569f56f564b92896170d.zip
o Working decoder for Samsung remotes.
Diffstat (limited to 'src')
-rw-r--r--src/radio-controller.cpp39
1 files changed, 29 insertions, 10 deletions
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<typename T>
-class buffer_iterator : public iterator<T> {
+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<uint16_t>(htim->Instance->CCR1);
- debug_pin(2);
+// debug_pin(2);
} else if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_2) {
ir_value2 = static_cast<uint16_t>(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<uint16_t>(ir_value1);
auto pulse = values::to_us<uint16_t>(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();