summaryrefslogtreecommitdiff
path: root/include/decoder.h
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2017-06-04 22:14:04 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2017-06-04 22:14:04 +0200
commit4ee01dab6105e346b731a13321a3e6a5d111d3e4 (patch)
treec5e3b6293a16f83f32f348705e946536a1b955d1 /include/decoder.h
parente758988579c3bf058214bf6e4ae56cf27b52bcfb (diff)
downloadradio-controller-4ee01dab6105e346b731a13321a3e6a5d111d3e4.tar.gz
radio-controller-4ee01dab6105e346b731a13321a3e6a5d111d3e4.tar.bz2
radio-controller-4ee01dab6105e346b731a13321a3e6a5d111d3e4.tar.xz
radio-controller-4ee01dab6105e346b731a13321a3e6a5d111d3e4.zip
o Trying for a more generic decoder structure, should be able to be dynamically programmed later on.
o Adding decoder for NEC.
Diffstat (limited to 'include/decoder.h')
-rw-r--r--include/decoder.h29
1 files changed, 26 insertions, 3 deletions
diff --git a/include/decoder.h b/include/decoder.h
index 9aee34d..4ae723c 100644
--- a/include/decoder.h
+++ b/include/decoder.h
@@ -2,6 +2,7 @@
#include <cstdint>
#include <mcu/init.h>
+#include <cstdio>
namespace radio_controller {
@@ -10,6 +11,26 @@ struct sample {
uint16_t pulse_us;
};
+namespace decoder_ns {
+
+inline static
+bool between(uint16_t smallest, uint16_t biggest, uint16_t value)
+{
+ return smallest <= value && value <= biggest;
+}
+
+inline static
+bool check_pulse(sample s, uint16_t period_time, uint16_t pulse_time)
+{
+ printf("check_pulse: between(%d, %d, %d) && between(%d, %d, %d)\n",
+ uint16_t(period_time * 0.8), uint16_t(period_time * 1.2), s.period_us,
+ uint16_t(pulse_time * 0.8), uint16_t(pulse_time * 1.2), s.pulse_us);
+
+ return between(uint16_t(period_time * 0.8), uint16_t(period_time * 1.2), s.period_us) &&
+ between(uint16_t(pulse_time * 0.8), uint16_t(pulse_time * 1.2), s.pulse_us);
+}
+} // namespace decoder_ns
+
class sample_iterator {
public:
virtual int size() = 0;
@@ -77,9 +98,11 @@ public:
enum class decoding_state {
OK,
- TOO_SHORT,
- BAD_START,
- SHORT_BODY
+ FAIL,
+// TOO_SHORT,
+// BAD_START,
+// SHORT_BODY,
+// UNKNOWN_TOKEN,
};
class decoding_result {