From 5f0800897cc47bb708ca533bdf3fbba0b30000db Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Wed, 18 May 2016 17:06:34 +0200 Subject: [PATCH] Some small updates --- arduino/HalMultiSensor/SensorBH1750.cpp | 2 +- arduino/HalMultiSensor/SensorPhotocell.cpp | 12 +++++++----- arduino/HalMultiSensor/SensorPhotocell.h | 5 +++-- .../plugin/tellstick/protocols/NexaSelfLearning.java | 12 ++++++++---- .../tellstick/protocols/NexaSelfLearningTest.java | 5 +++-- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/arduino/HalMultiSensor/SensorBH1750.cpp b/arduino/HalMultiSensor/SensorBH1750.cpp index 4562e1b3..f8461515 100755 --- a/arduino/HalMultiSensor/SensorBH1750.cpp +++ b/arduino/HalMultiSensor/SensorBH1750.cpp @@ -51,7 +51,7 @@ based on Christopher Laws, March, 2013 code. void SensorBH1750::setup() { Wire.begin(); - configure(BH1750_CONTINUOUS_HIGH_RES_MODE); + configure(BH1750_ONE_TIME_HIGH_RES_MODE); } diff --git a/arduino/HalMultiSensor/SensorPhotocell.cpp b/arduino/HalMultiSensor/SensorPhotocell.cpp index 22a7c4c9..518e4775 100755 --- a/arduino/HalMultiSensor/SensorPhotocell.cpp +++ b/arduino/HalMultiSensor/SensorPhotocell.cpp @@ -1,18 +1,20 @@ #include "SensorPhotocell.h" #include +void SensorPhotocell::interruptHandler() +{ + ++pulse; +} + void SensorPhotocell::setup() { + Interrupt::setCallback(SensorPhotocell::interruptHandler); Interrupt::setupPinInterrupt(PC2); //PC3 } void SensorPhotocell::read(PowerData& data) { data.consumption = pulse; -} - -void SensorPhotocell::reset() -{ pulse = 0; -} \ No newline at end of file +} diff --git a/arduino/HalMultiSensor/SensorPhotocell.h b/arduino/HalMultiSensor/SensorPhotocell.h index 359c8916..e84ecda1 100755 --- a/arduino/HalMultiSensor/SensorPhotocell.h +++ b/arduino/HalMultiSensor/SensorPhotocell.h @@ -10,10 +10,11 @@ class SensorPhotocell : public SensorPowerConsumption public: virtual void setup(); virtual void read(PowerData& data); - virtual void reset(); private: - unsigned int pulse; + static unsigned int pulse; + + static void interruptHandler(); }; #endif // SensorPhotocell_H diff --git a/src/se/hal/plugin/tellstick/protocols/NexaSelfLearning.java b/src/se/hal/plugin/tellstick/protocols/NexaSelfLearning.java index 8f5759fa..e8583ba0 100755 --- a/src/se/hal/plugin/tellstick/protocols/NexaSelfLearning.java +++ b/src/se/hal/plugin/tellstick/protocols/NexaSelfLearning.java @@ -63,11 +63,13 @@ public class NexaSelfLearning extends TellstickProtocol public String encode(){ try { - StringBuilder enc = new StringBuilder(); - enc.append(new char[]{'T', 127, 255, 24, 1}); - enc.append((char)132); // length + // T[t0][t1][t2][t3][length][d1]..[dn]+ + StringBuilder enc = new StringBuilder(90); // Tellstick supports max 74 bytes + enc.append(new char[]{'T', 127, 255, 24, 0}); + enc.append((char)0); // length - enc.append((char)0b0000_1001); // preamble + enc.append((char)0b1111_1001); // preamble + int length = 4; byte[] data = BinaryStructOutputStream.serialize(this); for (byte b : data){ for (int i=7; i>=0; --i){ @@ -75,8 +77,10 @@ public class NexaSelfLearning extends TellstickProtocol enc.append((char) 0b1010_1000); // 0b1010_1000 else // 1 enc.append((char) 0b1000_1010); // 0b1000_1010 + length += 4; } } + enc.setCharAt(5, (char)length); // Set calculated length enc.append("+"); return enc.toString(); diff --git a/test/se/hal/plugin/tellstick/protocols/NexaSelfLearningTest.java b/test/se/hal/plugin/tellstick/protocols/NexaSelfLearningTest.java index 7e5c61f7..844d2c5a 100755 --- a/test/se/hal/plugin/tellstick/protocols/NexaSelfLearningTest.java +++ b/test/se/hal/plugin/tellstick/protocols/NexaSelfLearningTest.java @@ -40,9 +40,10 @@ public class NexaSelfLearningTest { byte[] expected = Converter.toBytes(new char[]{ 84, // T - 127, 255, 24, 1, 132, // timings + 127, 255, 24, 0, // timings + 132, // length - 9, // preamble + 0xF9, // preamble 168, 168, 138, 168, 138, 138, 168, 168, 138, 138, 138, 168, 138, 168, 168, 168, 168, 168, 168, 138, 138, 168, 168, 138, 138, 168, 168, 138, 168, 168,