Some small updates
This commit is contained in:
parent
df6feb5597
commit
5f0800897c
5 changed files with 22 additions and 14 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,20 @@
|
|||
#include "SensorPhotocell.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue