From a484b095fb03313f5f192b23c90d04972ca3b957 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 4 Jun 2017 10:00:57 +0200 Subject: o Getting closer to a working decoder. --- include/decoder.h | 26 ++++++++++++++++++++++++++ include/samsung_decoder.h | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 include/decoder.h create mode 100644 include/samsung_decoder.h (limited to 'include') diff --git a/include/decoder.h b/include/decoder.h new file mode 100644 index 0000000..2a8c58e --- /dev/null +++ b/include/decoder.h @@ -0,0 +1,26 @@ +#pragma once + +namespace radio_controller { + +template +class iterator { +public: + virtual bool next() = 0; + + virtual bool has_next() const = 0; + + virtual const T &value() const = 0; +}; + +struct sample { + uint16_t period_us; + uint16_t pulse_us; +}; + +//template +class decoder { +public: + virtual void decode(iterator *it) = 0; +}; + +} // namespace radio_controller diff --git a/include/samsung_decoder.h b/include/samsung_decoder.h new file mode 100644 index 0000000..5d2b555 --- /dev/null +++ b/include/samsung_decoder.h @@ -0,0 +1,38 @@ +#pragma + +#include "decoder.h" + +namespace radio_controller { + +class samsung_decoder : public decoder { + + inline + bool between(uint16_t smallest, uint16_t biggest, uint16_t value) + { + return smallest <= value && value <= biggest; + } + + inline + bool start_bit(uint16_t time) + { + return between(4200, 4700, time); + } + + inline + bool one_bit(uint16_t time) + { + return between(4200, 4700, time); + } + +public: + void decode(iterator *it) override + { + printf("Samsung\n"); + while (it->next()) { + auto s = it->value(); + printf("% 5d us % 5d us, %.02d%%\n", s.period_us, s.pulse_us, int(s.pulse_us / double(s.period_us) * 100)); + } + } +}; + +} // namespace radio_controller -- cgit v1.2.3