Skip to content

Commit fba03b9

Browse files
committed
Trying to build roomnode. Few updates, cleanups.
1 parent 514266b commit fba03b9

File tree

3 files changed

+86
-39
lines changed

3 files changed

+86
-39
lines changed

Mpe/RoomNodeRF24/RoomNodeRF24.ino

+76-38
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,38 @@
1313
#include "printf.h"
1414

1515

16-
/** Globals and sketch configuration */
16+
/* *** Globals and sketch configuration *** */
1717
#define DEBUG 1 /* Enable trace statements */
1818
#define SERIAL 1 /* Enable serial */
1919

20-
#define MEASURE_PERIOD 600 // how often to measure, in tenths of seconds
21-
#define REPORT_EVERY 5 // report every N measurement cycles
22-
#define SMOOTH 5 // smoothing factor used for running averages
23-
#define MAXLENLINE 79
24-
#define SRAM_SIZE 0x800 // atmega328, for debugging
25-
2620
#define SHT11_PORT 0 // defined if SHT11 is connected to a port
2721
#define LDR_PORT 0 // defined if LDR is connected to a port's AIO pin
2822
#define PIR_PORT 0 // defined if PIR is connected to a port's DIO pin
29-
3023
#define _MEM 1 // Report free memory
3124
#define _RFM12B 0
3225
#define _RFM12BLOBAT 0
3326
#define _NRF24 1
3427

28+
#define MEASURE_PERIOD 600 // how often to measure, in tenths of seconds
29+
#define REPORT_EVERY 5 // report every N measurement cycles
30+
#define SMOOTH 5 // smoothing factor used for running averages
31+
32+
#define MAXLENLINE 79
33+
#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny85__)
34+
#define SRAM_SIZE 512
35+
#define EEPROM_SIZE 512
36+
#elif defined(__AVR_ATmega168__)
37+
#define SRAM_SIZE 1024
38+
#define EEPROM_SIZE 512
39+
#elif defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__)
40+
#define SRAM_SIZE 2048
41+
//#define SRAM_SIZE 0x800 // atmega328, for debugging
42+
#define EEPROM_SIZE 1024
43+
#endif
44+
3545

36-
String sketch = "RF24Test";
37-
String version = "0";
46+
const String sketch = "RF24Test";
47+
const int version = 0;
3848

3949
String node_id = "rf24tst-1";
4050

@@ -51,9 +61,12 @@ const byte rf24_csn = 8;
5161
MpeSerial mpeser (57600);
5262

5363

54-
// The scheduler makes it easy to perform various tasks at various times:
55-
enum { MEASURE, REPORT, STDBY };
56-
64+
/* Scheduled tasks */
65+
enum {
66+
MEASURE,
67+
REPORT,
68+
STDBY
69+
};
5770
// Scheduler.pollWaiting returns -1 or -2
5871
static const char WAITING = 0xFF; // -1: waiting to run
5972
static const char IDLE = 0xFE; // -2: no tasks running
@@ -64,6 +77,11 @@ Scheduler scheduler (schedbuf, STDBY);
6477
// has to be defined because we're using the watchdog for low-power waiting
6578
ISR(WDT_vect) { Sleepy::watchdogEvent(); }
6679

80+
81+
/* *** EEPROM config *** {{{ */
82+
83+
/* }}} *** */
84+
6785
// Other variables used in various places in the code:
6886
#if SHT11_PORT
6987
SHT11 sht11 (SHT11_PORT);
@@ -72,7 +90,17 @@ SHT11 sht11 (SHT11_PORT);
7290
#if LDR_PORT
7391
Port ldr (LDR_PORT);
7492
#endif
93+
#if _DHT
94+
/* DHT temp/rh sensor
95+
- AdafruitDHT
96+
*/
7597

98+
#endif //_DHT
99+
100+
#if _DS
101+
/* Dallas OneWire bus with registration for DS18B20 temperature sensors */
102+
103+
#endif // _DS
76104
#if _NRF24
77105
/* nRF24L01+: nordic 2.4Ghz digital radio */
78106

@@ -84,6 +112,7 @@ const uint64_t pipes[2] = {
84112
0xF0F0F0F0E1LL, /* dest id: central link node */
85113
0xF0F0F0F0D2LL /* src id: local node */
86114
};
115+
87116
#endif //_NRF24
88117

89118

@@ -104,8 +133,7 @@ struct {
104133
#endif
105134
} payload;
106135

107-
108-
/** AVR routines */
136+
/* *** AVR routines *** {{{ */
109137

110138
int freeRam () {
111139
extern int __heap_start, *__brkval;
@@ -117,8 +145,9 @@ int usedRam () {
117145
return SRAM_SIZE - freeRam();
118146
}
119147

148+
/* }}} *** */
120149

121-
/** ATmega routines */
150+
/* *** ATmega routines *** {{{ */
122151

123152
double internalTemp(void)
124153
{
@@ -151,8 +180,9 @@ double internalTemp(void)
151180
return (t);
152181
}
153182

183+
/* }}} *** */
154184

155-
/** Generic routines */
185+
/* *** Generic routines *** {{{ */
156186

157187
static void serialFlush () {
158188
#if SERIAL
@@ -175,7 +205,7 @@ void blink(int led, int count, int length, int length_off=0) {
175205

176206
void debug_ticks(void)
177207
{
178-
#if DEBUG
208+
#if SERIAL && DEBUG
179209
tick++;
180210
// a bit less for non-waiting loops or always..?
181211
if ((tick % 20) == 0) {
@@ -190,6 +220,7 @@ void debug_ticks(void)
190220
pos = 0;
191221
Serial.println();
192222
}
223+
serialFlush();
193224
#endif
194225
#endif
195226
}
@@ -201,12 +232,15 @@ static int smoothedAverage(int prev, int next, byte firstTime =0) {
201232
return ((SMOOTH - 1) * prev + next + SMOOTH / 2) / SMOOTH;
202233
}
203234

204-
void debug(String msg) {
235+
void debugline(String msg) {
205236
#if DEBUG
206237
Serial.println(msg);
207238
#endif
208239
}
209240

241+
/* }}} *** */
242+
243+
/* *** Peripheral hardware routines *** {{{ */
210244

211245
#if PIR_PORT
212246

@@ -265,8 +299,9 @@ void rf24_run()
265299
}
266300
#endif //_NRF24
267301

302+
/* }}} *** */
268303

269-
/* Initialization routines */
304+
/* *** Initialization routines *** {{{ */
270305

271306
void doConfig(void)
272307
{
@@ -283,8 +318,9 @@ void initLibs()
283318
#endif
284319
}
285320

321+
/* }}} *** */
286322

287-
/* Run-time handlers */
323+
/* *** Run-time handlers *** {{{ */
288324

289325
bool doAnnounce()
290326
{
@@ -298,6 +334,7 @@ bool doAnnounce()
298334
Serial.print(F(" memfree"));
299335
#endif
300336
#endif
337+
return false;
301338
}
302339

303340
void doReset(void)
@@ -375,14 +412,13 @@ bool doReport(void)
375412
return ok;
376413
}
377414

378-
void runScheduler(char task)
415+
void runScheduler(byte task)
379416
{
380417
switch (task) {
381418

382419
case MEASURE:
383420
// reschedule these measurements periodically
384-
debug("MEASURE");
385-
scheduler.timer(MEASURE, MEASURE_PERIOD);
421+
debugline("MEASURE");
386422

387423
doMeasure();
388424

@@ -395,7 +431,7 @@ void runScheduler(char task)
395431
break;
396432

397433
case REPORT:
398-
debug("REPORT");
434+
debugline("REPORT");
399435
// payload.msgtype = REPORT_MSG;
400436
if (doReport()) {
401437
// XXX report again?
@@ -415,7 +451,6 @@ void runScheduler(char task)
415451
}
416452
}
417453

418-
419454
#if PIR_PORT
420455

421456
// send packet and wait for ack when there is a motion trigger
@@ -426,20 +461,21 @@ void doTrigger()
426461

427462

428463

429-
/* Main */
464+
/* }}} *** */
465+
466+
/* *** Main *** {{{ */
430467

431468
void setup(void)
432469
{
433470
#if SERIAL
434471
mpeser.begin();
435-
mpeser.startAnnounce(sketch, version);
472+
mpeser.startAnnounce(sketch, String(version));
436473
doAnnounce();
437-
serialFlush();
438-
439-
#if DEBUG
440-
Serial.print(F("SRAM used: "));
441-
Serial.println(usedRam());
474+
#if DEBUG || _MEM
475+
Serial.print(F("Free RAM: "));
476+
Serial.println(freeRam());
442477
#endif
478+
serialFlush();
443479
#endif
444480

445481
initLibs();
@@ -450,10 +486,12 @@ void setup(void)
450486
void loop(void)
451487
{
452488
debug_ticks();
453-
454-
char task = scheduler.pollWaiting();
455489
serialFlush();
456-
if (task == 0xFF) return; // -1
457-
if (task == 0xFE) return; // -2
458-
runScheduler(task);
490+
byte task = scheduler.pollWaiting();
491+
if (task == 0xFF) {} // -1
492+
else if (task == 0xFE) {} // -2
493+
else runScheduler(task);
459494
}
495+
496+
/* }}} *** */
497+

Mpe/RoomNodeRF24/radioPinFunctions.c

-1
This file was deleted.

Rules.old.mk

+10
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,11 @@ cassette328p: P := Mpe/Cassette328P/
611611
cassette328p: I := Mpe/Cassette328P/Cassette328P.hex
612612
cassette328p: jeenode upload
613613

614+
cassette328pmilli: C := m328p
615+
cassette328pmilli: P := Mpe/Cassette328P/Milli/
616+
cassette328pmilli: I := Mpe/Cassette328P/Milli/Milli.hex
617+
cassette328pmilli: jeenode upload
618+
614619
hanrun: C := m328p
615620
hanrun: P := Misc/HanrunENC28J60/
616621
hanrun: I := Misc/HanrunENC28J60/HanrunENC28J60.hex
@@ -863,6 +868,11 @@ roomnode: P := Mpe/RoomNode/
863868
roomnode: I := Mpe/RoomNode/RoomNode.hex
864869
roomnode: jeenode upload
865870

871+
roomnode24: C := m328p
872+
roomnode24: P := Mpe/RoomNodeRF24/
873+
roomnode24: I := Mpe/RoomNodeRF24/RoomNodeRF24.hex
874+
roomnode24: jeenode upload
875+
866876
magnetometer: C := m328p
867877
magnetometer: P := Prototype/Magnetometer/
868878
magnetometer: I := Prototype/Magnetometer/Magnetometer.hex

0 commit comments

Comments
 (0)