diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2017-06-04 10:00:57 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2017-06-04 10:00:57 +0200 |
commit | a484b095fb03313f5f192b23c90d04972ca3b957 (patch) | |
tree | 3f965869157a7901bc9c92e0dc0727e9ef8d5552 /include | |
parent | 0bc2a81c0aab3c89b534415d6f07d07e392260ce (diff) | |
download | radio-controller-a484b095fb03313f5f192b23c90d04972ca3b957.tar.gz radio-controller-a484b095fb03313f5f192b23c90d04972ca3b957.tar.bz2 radio-controller-a484b095fb03313f5f192b23c90d04972ca3b957.tar.xz radio-controller-a484b095fb03313f5f192b23c90d04972ca3b957.zip |
o Getting closer to a working decoder.
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 |