Skip to content

Commit 597b221

Browse files
committed
Syning. Fixing temp-cal and eeprom, serial
1 parent d33dfab commit 597b221

File tree

21 files changed

+1432
-638
lines changed

21 files changed

+1432
-638
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/usr/local/share/mkdoc/Mkdocs-minimal.mk
1+
/usr/local/share/mkdoc/Mkdoc-full.mk

Mpe/CarrierCase/CarrierCase.ino

+36-29
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ ToDo
6666
motion
6767
LDR
6868
69-
-
70-
*/
69+
*/
7170

7271
//#ifdef MYCMDLINE
7372

@@ -79,26 +78,28 @@ ToDo
7978
#define DEBUG 1 /* Enable trace statements */
8079

8180
#define _MEM 1 // Report free memory
82-
#define _RFM12B 1
83-
#define _RFM12BLOBAT 1 // Use JeeNode lowbat measurement
84-
#define _NRF24 0
85-
#define _HMC5883L 1
8681
#define _DHT 0
82+
#define LDR_PORT 0 // defined if LDR is connected to a port's AIO pin
8783
#define _DS 0
8884
#define DS_PIN A5
8985
#define DEBUG_DS 1
9086
//#define FIND_DS 1
91-
#define PIR_PORT 0
9287
#define DHT_PIN 0 // DIO for DHTxx
93-
#define LDR_PORT 0 // defined if LDR is connected to a port's AIO pin
88+
#define DHT_HIGH 1 // enable for DHT22/AM2302, low for DHT11
89+
#define PIR_PORT 0
90+
#define _HMC5883L 1
91+
#define _LCD84x48 0
92+
#define _RFM12B 1
93+
#define _RFM12LOBAT 1 // Use JeeNode lowbat measurement
94+
#define _NRF24 0
9495

9596
#define REPORT_EVERY 5 // report every N measurement cycles
9697
#define SMOOTH 5 // smoothing factor used for running averages
9798
#define MEASURE_PERIOD 50 // how often to measure, in tenths of seconds
9899
#define RETRY_PERIOD 10 // how soon to retry if ACK didn't come in
99100
#define RETRY_LIMIT 2 // maximum number of times to retry
100101
#define ACK_TIME 10 // number of milliseconds to wait for an ack
101-
#define UI_IDLE 4000 // tenths of seconds idle time, ...
102+
#define UI_SCHED_IDLE 4000 // tenths of seconds idle time, ...
102103
#define UI_STDBY 8000 // ms
103104

104105
#define MAXLENLINE 79
@@ -114,15 +115,17 @@ ToDo
114115
#include <avr/sleep.h>
115116
#include <util/atomic.h>
116117

118+
//#include <EEPROM.h>
119+
// include EEPROMEx.h
117120
// Adafruit DHT
118121
#include <DHT.h>
119122
#include <Wire.h>
120-
#include <JeeLib.h>
121123
#include <OneWire.h>
124+
#include <JeeLib.h>
125+
//#include <SPI.h>
126+
//#include <RF24.h>
122127
#include <DotmpeLib.h>
123128
#include <mpelib.h>
124-
//#include <EEPROM.h>
125-
// include EEPROMEx.h
126129
#include <EmBencode.h>
127130

128131

@@ -178,10 +181,10 @@ struct {
178181
int magny;
179182
int magnz;
180183
#endif //_HMC5883L
181-
#ifdef _MEM
184+
#if _MEM
182185
int memfree :16;
183186
#endif
184-
#ifdef _RFM12BLOBAT
187+
#if _RFM12LOBAT
185188
byte lobat :1; // supply voltage dropped under 3.1V: 0..1
186189
#endif
187190
} payload;
@@ -198,8 +201,8 @@ enum {
198201
TASK_END
199202
};
200203
// Scheduler.pollWaiting returns -1 or -2
201-
static const char WAITING = 0xFF; // -1: waiting to run
202-
static const char IDLE = 0xFE; // -2: no tasks running
204+
static const char SCHED_WAITING = 0xFF; // -1: waiting to run
205+
static const char SCHED_IDLE = 0xFE; // -2: no tasks running
203206

204207
static word schedbuf[TASK_END];
205208
Scheduler scheduler (schedbuf, TASK_END);
@@ -208,7 +211,7 @@ Scheduler scheduler (schedbuf, TASK_END);
208211
ISR(WDT_vect) { Sleepy::watchdogEvent(); }
209212

210213

211-
/* *** /Scheduled tasks }}} *** */
214+
/* *** /Scheduled tasks *** }}} */
212215

213216
/* *** EEPROM config *** {{{ */
214217

@@ -237,10 +240,14 @@ void writeConfig()
237240
}
238241

239242

240-
/* *** /EEPROM config }}} *** */
243+
/* *** /EEPROM config *** }}} */
241244

242245
/* *** Peripheral devices *** {{{ */
243246

247+
#if SHT11_PORT
248+
SHT11 sht11 (SHT11_PORT);
249+
#endif
250+
244251
#if LDR_PORT
245252
Port ldr (LDR_PORT);
246253
#endif
@@ -417,12 +424,13 @@ void freeEmbencBuff() {
417424

418425
/* *** Peripheral hardware routines *** {{{ */
419426

427+
420428
#if LDR_PORT
421429
#endif
422430

423431
/* *** PIR support *** {{{ */
424432
#if PIR_PORT
425-
#endif
433+
#endif // PIR_PORT
426434
/* *** /PIR support *** }}} */
427435

428436
#if _DHT
@@ -443,7 +451,7 @@ static bool waitForAck() {
443451
// see http://talk.jeelabs.net/topic/811#post-4712
444452
rf12_hdr == (RF12_HDR_DST | RF12_HDR_CTL | rf12_id))
445453
return 1;
446-
set_sleep_mode(SLEEP_MODE_IDLE);
454+
set_sleep_mode(SLEEP_MODE_SCHED_IDLE);
447455
sleep_mode();
448456
}
449457
return 0;
@@ -454,7 +462,6 @@ static bool waitForAck() {
454462

455463
#if _LCD84x48
456464

457-
458465
#endif // LCD84x48
459466

460467
#if _DS
@@ -1071,14 +1078,14 @@ void doMeasure()
10711078
Serial.println(payload.memfree);
10721079
#endif
10731080
#endif //_MEM
1074-
#if _RFM12BLOBAT
1081+
#if _RFM12LOBAT
10751082
payload.lobat = rf12_lowbat();
10761083
#if SERIAL && DEBUG_MEASURE
10771084
if (payload.lobat) {
10781085
Serial.println("Low battery");
10791086
}
10801087
#endif
1081-
#endif //_RFM12BLOBAT
1088+
#endif //_RFM12LOBAT
10821089
}
10831090

10841091
// periodic report, i.e. send out a packet and optionally report on serial port
@@ -1130,10 +1137,10 @@ void doReport(void)
11301137
Serial.print(' ');
11311138
Serial.print((int) payload.memfree);
11321139
#endif //_MEM
1133-
#if _RFM12BLOBAT
1140+
#if _RFM12LOBAT
11341141
Serial.print(' ');
11351142
Serial.print((int) payload.lobat);
1136-
#endif //_RFM12BLOBAT
1143+
#endif //_RFM12LOBAT
11371144

11381145
Serial.println();
11391146
#endif //SERIAL
@@ -1186,7 +1193,7 @@ void doTrigger(void)
11861193
// Add UI or not..
11871194
//void uiStart()
11881195
//{
1189-
// idle.set(UI_IDLE);
1196+
// idle.set(UI_SCHED_IDLE);
11901197
// if (!ui) {
11911198
// ui = true;
11921199
// }
@@ -1233,8 +1240,8 @@ void runScheduler(char task)
12331240
break;
12341241

12351242
#if DEBUG && SERIAL
1236-
case WAITING:
1237-
case IDLE:
1243+
case SCHED_WAITING:
1244+
case SCHED_IDLE:
12381245
Serial.print("!");
12391246
serialFlush();
12401247
break;
@@ -1347,7 +1354,7 @@ void loop(void)
13471354
#endif
13481355

13491356
char task = scheduler.poll();
1350-
if (-1 < task && task < IDLE) {
1357+
if (-1 < task && task < SCHED_IDLE) {
13511358
runScheduler(task);
13521359
}
13531360

Mpe/Cassette328P/Cassette328P.ino

+27-26
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ An atmega328p TQFP chip with various peripherals:
1212
* Voltage is 3.3v and speed 16Mhz, external ceramic resonator.
1313
Hope this will keep working as such.
1414
* Arduino library is used while I'm learning from chip datasheets,
15-
perhaps where needed there is time for more efficient and low-power
16-
implementation.
15+
perhaps where needed there is time for more efficient and low-power
16+
implementation.
1717
1818
Plans
1919
- Hookup a low-pass filter and play with PWM, sine generation at D10 (m328p: PB2).
@@ -29,7 +29,8 @@ Free pins
2929
- D4 PD4
3030
- D10 PB2 PWM
3131
- D20 A6 ADC6
32-
*/
32+
33+
*/
3334

3435
#include <avr/io.h>
3536
#include <avr/sleep.h>
@@ -40,7 +41,7 @@ Free pins
4041
#include <Wire.h>
4142
#include <SPI.h>
4243
#include <EEPROM.h>
43-
//include <RF24.h>
44+
#include <RF24.h>
4445
//include <LiquidCrystalTmp_I2C.h>
4546
#include <SimpleFIFO.h> //code.google.com/p/alexanderbrevig/downloads/list
4647

@@ -50,8 +51,8 @@ Free pins
5051
/* *** Globals and sketch configuration *** */
5152
#define DEBUG 1 /* Enable trace statements */
5253
#define SERIAL 1 /* Enable serial */
53-
54-
#define _MEM 1 // Report free memory
54+
55+
#define _MEM 1 // Report free memory
5556
//#define LDR_PORT 0 // defined if LDR is connected to a port's AIO pin
5657
#define _DHT 1
5758
#define DHT_PIN 14
@@ -60,27 +61,27 @@ Free pins
6061
#define _LCD84x48 0
6162
#define _RTC 0
6263
#define _RFM12 0
63-
#define _NRF24 0
64-
64+
#define _NRF24 1
65+
6566
#define REPORT_EVERY 5 // report every N measurement cycles
6667
#define SMOOTH 5 // smoothing factor used for running averages
6768
#define MEASURE_PERIOD 50 // how often to measure, in tenths of seconds
6869
#define DEBUG_MEASURE 1
69-
70+
7071
#define RETRY_PERIOD 10 // how soon to retry if ACK didn't come in
7172
#define RETRY_LIMIT 5 // maximum number of times to retry
7273
#define ACK_TIME 10 // number of milliseconds to wait for an ack
73-
74+
7475
#define RADIO_SYNC_MODE 2
75-
76+
7677
#if defined(__AVR_ATtiny84__)
7778
#define SRAM_SIZE 512
7879
#elif defined(__AVR_ATmega168__)
7980
#define SRAM_SIZE 1024
8081
#elif defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__)
8182
#define SRAM_SIZE 2048
8283
#endif
83-
84+
8485

8586
const String sketch = "Cassette328P";
8687
const int version = 0;
@@ -115,7 +116,7 @@ struct Config {
115116

116117
Config config;
117118

118-
bool loadConfig(Config &c)
119+
bool loadConfig(Config &c)
119120
{
120121
int w = sizeof(c);
121122

@@ -143,7 +144,7 @@ bool loadConfig(Config &c)
143144
void writeConfig(Config &c)
144145
{
145146
for (unsigned int t=0; t<sizeof(c); t++) {
146-
147+
147148
EEPROM.write(CONFIG_START + t, *((char*)&c + t));
148149

149150
// verify
@@ -168,8 +169,8 @@ static byte reportCount; // count up until next report, i.e. packet send
168169
/* Allow invokation of commands with up to 7 args */
169170
SimpleFIFO<uint8_t,8> cmdseq; //store 10 ints
170171

171-
typedef enum {
172-
cmd_wait_for_command = 0x01,
172+
typedef enum {
173+
cmd_wait_for_command = 0x01,
173174
cmd_stand_by = 0x20,
174175
cmd_report_all = 0x10,
175176
cmd_read_time = 0x11,
@@ -195,14 +196,14 @@ int service_mode = 0;
195196
ISR(WDT_vect) { Sleepy::watchdogEvent(); }
196197

197198
/* Roles supported by this sketch */
198-
typedef enum {
199+
typedef enum {
199200
role_reporter = 1, /* start enum at 1, 0 is reserved for invalid */
200201
role_logger
201202
} Role;
202203

203-
const char* role_friendly_name[] = {
204-
"invalid",
205-
"Reporter",
204+
const char* role_friendly_name[] = {
205+
"invalid",
206+
"Reporter",
206207
"Logger"
207208
};
208209

@@ -252,9 +253,9 @@ DHT dht(DHT_PIN, DHTTYPE);
252253
/* *** AVR routines *** {{{ */
253254

254255
int freeRam () {
255-
extern int __heap_start, *__brkval;
256+
extern int __heap_start, *__brkval;
256257
int v;
257-
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
258+
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
258259
}
259260

260261
int usedRam () {
@@ -510,7 +511,7 @@ void i2c_lcd_init()
510511
//lcd.noBacklight();
511512
lcd.off();
512513
//lcd.setBacklight(LED_ON);
513-
lcd.leftToRight();
514+
lcd.leftToRight();
514515
lcd.noBlink();
515516
lcd.noCursor();
516517
//lcd.createChar(0, bell);
@@ -672,7 +673,7 @@ void initLibs()
672673
#endif
673674
#if _DHT
674675
dht.begin();
675-
#if DEBUG
676+
#if DEBUG
676677
Serial.println("Initialized DHT");
677678
float t = dht.readTemperature();
678679
Serial.println(t);
@@ -721,7 +722,7 @@ void serialEvent()
721722
* Using this to wake up chip by hardware jumper.
722723
* Need to look for an interrupt.
723724
*/
724-
int serviceMode(void)
725+
int serviceMode(void)
725726
{
726727
pinMode(LED_RED, INPUT);
727728
digitalWrite( LED_RED, LOW);
@@ -980,7 +981,7 @@ void setup(void)
980981
rf12_sleep(RF12_SLEEP); // power down
981982

982983
/* Read config from memory, or initialize with defaults */
983-
// if (!loadConfig(config))
984+
// if (!loadConfig(config))
984985
// {
985986
// saveRF24Config(static_config);
986987
// config = static_config;

Mpe/Cassette328P/Cassette328P.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ modes
1212
reporter
1313
rf12, serial
1414
repeater
15-
rf12,
16-
15+
rf12,
16+
1717

0 commit comments

Comments
 (0)