Skip to content

Commit ffabc53

Browse files
author
JP
committed
added support for WT450 sensor, more code removed to reduce code space and
more, check README
1 parent 2037a83 commit ffabc53

File tree

11 files changed

+3952
-50
lines changed

11 files changed

+3952
-50
lines changed

Ninja/Ninja.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
// This part defines which version to use when compile
55
// Only one define is allowed.
66

7-
#define V11 1
8-
//#define V12 1
9-
#define VERSION_NO "0.43"
7+
//#define V11 1
8+
#define V12 1
9+
#define VERSION_NO "0.44"
1010
//#define TESTER 1
1111

1212
#if defined(V12) && defined(V11)

Ninja/NinjaArduino/NinjaArduino.ino

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,25 @@ void setup()
1515
pinMode(RED_LED_PIN, OUTPUT);
1616
pinMode(GREEN_LED_PIN, OUTPUT);
1717
pinMode(BLUE_LED_PIN, OUTPUT);
18-
digitalWrite(RED_LED_PIN, HIGH); // set the RED LED Off
19-
digitalWrite(GREEN_LED_PIN, HIGH); // set the GREEN LED Off
20-
digitalWrite(BLUE_LED_PIN, HIGH); // set the BLUE LED Off
18+
digitalWrite(RED_LED_PIN, HIGH); // set the RED LED Off
19+
digitalWrite(GREEN_LED_PIN, HIGH); // set the GREEN LED Off
20+
digitalWrite(BLUE_LED_PIN, HIGH); // set the BLUE LED Off
2121

22+
#ifdef V11
23+
digitalWrite(BLUE_LED_PIN, LOW); // Power on Status
24+
#endif
2225
#ifdef V12
2326
pinMode(RED_STAT_LED_PIN, OUTPUT);
2427
pinMode(GREEN_STAT_LED_PIN, OUTPUT);
2528
pinMode(BLUE_STAT_LED_PIN, OUTPUT);
2629
digitalWrite(RED_STAT_LED_PIN, HIGH); // set the RED STAT LED Off
27-
digitalWrite(GREEN_STAT_LED_PIN, HIGH); // set the GREEN STAT LED Off
28-
digitalWrite(BLUE_STAT_LED_PIN, HIGH); // set the BLUE STAT LED Off
30+
digitalWrite(GREEN_STAT_LED_PIN, HIGH); // set the GREEN STAT LED Off
31+
digitalWrite(BLUE_STAT_LED_PIN, LOW); // Power on Status
2932
#endif
3033
}
3134

3235
void loop()
3336
{
3437
nOBJECTS.sendObjects(); // Send Ninja Objects
3538
nOBJECTS.doReactors(); // Receive Ninja Objects reactors
36-
}
39+
}

NinjaObjects/NinjaObjects.cpp

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,21 @@ const char strWindDirection[16][4] =
3737
"W", "WNW", "NW", "NNW"
3838
};
3939

40+
/*
4041
struct __freelist
4142
{
4243
size_t sz;
4344
struct __freelist *nx;
4445
};
45-
46+
*/
4647

4748
// Variables need to be moved to private or public part of the object - TODO
48-
uint16_t biggest;
49+
//uint16_t biggest;
4950
NinjaObjects nOBJECTS;
5051
char serInStr[recvLEN]; // array to hold the incoming serial string bytes
5152

52-
extern char * const __brkval;
53-
extern struct __freelist *__flp;
53+
//extern char * const __brkval;
54+
//extern struct __freelist *__flp;
5455

5556
char strGUID[GUID_LEN];
5657
int intVID=0;
@@ -160,6 +161,8 @@ void dec2binWzerofill(char* bin, unsigned long long Dec, unsigned int bitLength)
160161
return;
161162
}
162163

164+
165+
/*
163166
// given a PROGMEM string, use Serial.print() to send it out
164167
// this is needed to save precious memory
165168
//thanks to todbot for this http://todbot.com/blog/category/programming/
@@ -175,7 +178,9 @@ void printProgStr(const prog_char* str) {
175178
str++;
176179
}
177180
}
181+
*/
178182

183+
/*
179184
uint16_t freeMem(uint16_t *biggest)
180185
{
181186
char *brkval;
@@ -211,6 +216,7 @@ void freeMem(char* message)
211216
Serial.print(":\t");
212217
Serial.println(freeMem(&biggest));
213218
}
219+
*/
214220

215221

216222
//read a string from the serial and store it in an array
@@ -589,7 +595,7 @@ void NinjaObjects::doJSONError(int errorCode)
589595
aJsonObject* root = aJson.createObject();
590596
if (root == NULL)
591597
{
592-
Serial.println("error root");
598+
//Serial.println("error root");
593599
return;
594600
}
595601

@@ -615,7 +621,7 @@ void NinjaObjects::doJSONResponse()
615621
aJsonObject* root = aJson.createObject();
616622
if (root == NULL)
617623
{
618-
Serial.println("error root");
624+
//Serial.println("error root");
619625
return;
620626
}
621627

@@ -653,7 +659,7 @@ void NinjaObjects::doJSONData(char * strGUID, int intVID, int intDID, char * str
653659
aJsonObject* root = aJson.createObject();
654660
if (root == NULL)
655661
{
656-
Serial.println("error root");
662+
//Serial.println("error root");
657663
return;
658664
}
659665

@@ -794,6 +800,37 @@ void NinjaObjects::doOnBoardAccelerometer()
794800
}
795801
#endif
796802

803+
void NinjaObjects::doWT450(unsigned long long value)
804+
{
805+
char strAddress[5];
806+
unsigned long data;
807+
int house=0;
808+
byte station=0;
809+
int humidity=0;
810+
double temperature=0;
811+
double tempdecimal=0;
812+
byte tempfraction=0;
813+
814+
data=(unsigned long)value;
815+
816+
house=(data>>28) & (0x0f);
817+
station=((data>>26) & (0x03))+1;
818+
humidity=(data>>16)&(0xff);
819+
temperature=((data>>8) & (0xff))-50;
820+
tempfraction=(data>>4) & (0x0f);
821+
822+
tempdecimal=((tempfraction>>3 & 1) * 0.5) + ((tempfraction>>2 & 1) * 0.25) + ((tempfraction>>1 & 1) * 0.125) + ((tempfraction & 1) * 0.0625);
823+
temperature=temperature+tempdecimal;
824+
temperature=(int)(temperature*10);
825+
temperature=temperature/10;
826+
827+
sprintf(strAddress,"%02d%02d", house, station);
828+
829+
doJSONData(strAddress, 0, 30, NULL, humidity, false,0);
830+
doJSONData(strAddress, 0, 31, NULL, temperature, false,0);
831+
832+
}
833+
797834
void NinjaObjects::doLacrosseTX3(unsigned long long tx3value)
798835
{
799836
byte nibble[10];
@@ -904,7 +941,7 @@ void NinjaObjects::do433(void)
904941

905942
mySwitch.enableReceive(RX433_INT);
906943

907-
if (mySwitch.available())
944+
if (mySwitch.available() && (mySwitch.getReceivedProtocol()>0 && mySwitch.getReceivedProtocol()<6))
908945
{
909946
unsigned long long value = mySwitch.getReceivedValue();
910947
if (value == 0) // unknown encoding
@@ -932,6 +969,8 @@ void NinjaObjects::do433(void)
932969
doLacrosseTX3(value);
933970
else if (mySwitch.getReceivedProtocol()==4)
934971
doLacrosseWS2355(value);
972+
else if(mySwitch.getReceivedProtocol()==5)
973+
doWT450(value);
935974
else
936975
{
937976
if (mySwitch.getReceivedBitlength()> (DATA_LEN/2))
@@ -1196,6 +1235,7 @@ boolean NinjaObjects::doPort3(byte* DHT22_PORT)
11961235
return IsDHT22;
11971236
}
11981237

1238+
11991239
void NinjaObjects::doDHT22(byte port)
12001240
{
12011241
int intTemperature;

NinjaObjects/NinjaObjects.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class NinjaObjects {
5353
void do433(void);
5454
void doLacrosseTX3(unsigned long long tx3value);
5555
void doLacrosseWS2355(unsigned long long ws2344value);
56+
void doWT450(unsigned long long value);
5657
};
5758

5859
extern NinjaObjects nOBJECTS;

NinjaObjects/README

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ NinjaObjects.cpp - Ninja Objects library
22

33
Based on the aJson example from http://interactive-matter.eu/how-to/ajson-arduino-json-library/
44

5+
8th October 2012 by JP Liew
6+
- added doWT450()to decode house, station, humidity & temp from raw data
7+
58
2nd October 2012 by JP Liew
69
- added TESTER code for Ninja Cape to test another fresh cape out from production
710
- added DID 8888,8889,8890 to support special command for TESTER to send/receive signal

0 commit comments

Comments
 (0)