diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/decoder.h | 26 | ||||
-rw-r--r-- | include/samsung_decoder.h | 38 |
2 files changed, 64 insertions, 0 deletions
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<typename T> +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<typename T> +class decoder { +public: + virtual void decode(iterator<sample> *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<sample> *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 |