Skip to content

Commit d37e63e

Browse files
Adapted folder structure to arduino 1.6.10
- shortened serial UI commands to save bytes - adapted folder structure to new limitation of arduino 1.6.10 whereby only source files in the ‘src’ subfolder of a sketch are being included => moved “subprojects” into a new ‘src’ folder (config, log, sensors, ble_gatt). For details see arduino/arduino-builder#148 - arduino 1.6.10 uses the latest AVR tooling => boiler controller with BLE uses only 25.5 KB now instead of 26.9 KB
1 parent 3786aed commit d37e63e

24 files changed

+71
-68
lines changed

bc_setup.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
// Uncomment AT MOST ONE (!) of the following lines:
55
// #define UNIT_TEST
6-
// #define BLE_UI
7-
#define SERIAL_UI
6+
#define BLE_UI
7+
// #define SERIAL_UI
88

99
#ifdef UNIT_TEST
1010
// Comment the following line to prevent execution of STATE tests:

boiler_controller.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "bc_setup.h"
2-
#include "math.h"
2+
#include "log.h"
33
#include "control.h"
44
#include "state.h"
55
#include "ui.h"

config.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#ifndef BC_CONFIG_H_INCLUDED
22
#define BC_CONFIG_H_INCLUDED
33

4-
#include "config/Configuration.h"
5-
#include "sensors/OneWireSensors.h"
4+
#include "src/config/Configuration.h"
5+
#include "src/sensors/OneWireSensors.h"
66

77
/*
88
* ID values are defined by ConfigParamEnum.

control.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#define WATER_MIN_TEMP -2000 // [°C * 100]
2424
#define WATER_MAX_TEMP 10000 // [°C * 100]
2525

26-
// Water min and max values used to check that ambient-temperature readout is plausible:
26+
// Ambient min and max values used to check that ambient-temperature readout is plausible:
2727
#define AMBIENT_MIN_TEMP -3000 // [°C * 100]
2828
#define AMBIENT_MAX_TEMP 5000 // [°C * 100]
2929

log.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define BC_LOG_H_INCLUDED
33

44
#include "config.h"
5-
#include "log/Logging.h"
5+
#include "src/log/Logging.h"
66

77

88
/*
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

ui_ble.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ const char BC_DEVICE_NAME[] = "Boiler Controller";
66
const char BC_CONTROLLER_SERVICE_ID[] = "4C-EF-DD-58-CB-95-44-50-90-FB-F4-04-DC-20-2F-7C";
77

88
void BLEUI::setup() {
9-
randomSeed(micros());
10-
119
ble.assertOK(ble.begin(DEBUG_BLE), F("Couldn't find Bluefruit, make sure it's in CoMmanD mode & check wiring?"));
1210

1311
/* Perform a factory reset to make sure everything is in a known state */

ui_ble.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
#define BC_UI_BLE_H_INCLUDED
33

44
#include "ui.h"
5-
#include "ble_gatt/Adafruit_BluefruitLE_GATT.h"
5+
#include "src/ble_gatt/Adafruit_BluefruitLE_GATT.h"
66

77
class BLEUI : public NullUI {
88
public:
99
BLEUI(ExecutionContext *context) : NullUI(context) { }
10+
1011
void setup();
1112

1213
void readUserCommand();

ui_ser.cpp

+59-52
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ const char INT_CHARS[] = "0123456789";
1313
const char STR_NONE[] PROGMEM = "None";
1414
const char STR_ILLEGAL[] PROGMEM = "Illegal";
1515

16-
const char STR_CONFIG_SENSOR_ID_SWAP[] PROGMEM = "swap";
17-
const char STR_CONFIG_SENSOR_ID_CLR[] PROGMEM = "clr";
18-
const char STR_CONFIG_SENSOR_ID_ACK[] PROGMEM = "ack";
16+
const char STR_CONFIG_SET_VALUES[] PROGMEM = "set";
17+
const char STR_CONFIG_RESET_VALUES[] PROGMEM = "reset";
18+
const char STR_CONFIG_SENSOR_ID_SWAP[] PROGMEM = "swap ids";
19+
const char STR_CONFIG_SENSOR_ID_CLR[] PROGMEM = "clr ids";
20+
const char STR_CONFIG_SENSOR_ID_ACK[] PROGMEM = "ack ids";
1921

2022
/*
2123
* CONFIG PARAM NAMES
@@ -171,28 +173,27 @@ const __FlashStringHelper *getEventName(EventEnum literal) {
171173
/*
172174
* COMMANDS
173175
*/
174-
const char STR_CMD_SET_CONFIG[] PROGMEM = "set config";
175-
const char STR_CMD_REC_ON[] PROGMEM = "rec on";
176-
const char STR_CMD_REC_OFF[] PROGMEM = "rec off";
177-
const char STR_CMD_HELP[] PROGMEM = "help";
178-
const char STR_CMD_GET_LOG[] PROGMEM = "get log";
179-
const char STR_CMD_GET_CONFIG[] PROGMEM = "get config";
180-
const char STR_CMD_GET_STAT[] PROGMEM = "get stat";
181-
const char STR_CMD_HEAT_ON[] PROGMEM = "heat on";
176+
const char STR_CMD_CONFIG[] PROGMEM = "config";
177+
const char STR_CMD_REC_ON[] PROGMEM = "rec on";
178+
const char STR_CMD_REC_OFF[] PROGMEM = "rec off";
179+
const char STR_CMD_HELP[] PROGMEM = "help";
180+
const char STR_CMD_GET_LOG[] PROGMEM = "log";
181+
const char STR_CMD_GET_STAT[] PROGMEM = "stat";
182+
const char STR_CMD_HEAT_ON[] PROGMEM = "heat on";
182183
const char STR_CMD_HEAT_OFF[] PROGMEM = "heat off";
183-
const char STR_CMD_RESET[] PROGMEM = "reset";
184+
const char STR_CMD_RESET[] PROGMEM = "reset";
184185

185186
#define MAX_CMD_NAME_LEN 12
186187

187188
PGM_P getUserCommandNamePtr(UserCommandEnum literal) {
188189
switch(literal) {
189190
case CMD_NONE: return STR_NONE;
190-
case CMD_SET_CONFIG: return STR_CMD_SET_CONFIG;
191+
case CMD_HELP: return STR_CMD_HELP;
192+
case CMD_SET_CONFIG: return STR_CMD_CONFIG;
193+
case CMD_GET_CONFIG: return STR_CMD_CONFIG;
191194
case CMD_REC_ON: return STR_CMD_REC_ON;
192195
case CMD_REC_OFF: return STR_CMD_REC_OFF;
193-
case CMD_HELP: return STR_CMD_HELP;
194196
case CMD_GET_LOG: return STR_CMD_GET_LOG;
195-
case CMD_GET_CONFIG: return STR_CMD_GET_CONFIG;
196197
case CMD_GET_STAT: return STR_CMD_GET_STAT;
197198
case CMD_HEAT_ON: return STR_CMD_HEAT_ON;
198199
case CMD_HEAT_OFF: return STR_CMD_HEAT_OFF;
@@ -223,51 +224,53 @@ const __FlashStringHelper *getSensorStatusName(SensorStatusEnum literal) {
223224
/*
224225
* USER COMMANDS
225226
*/
226-
UserCommandEnum parseUserCommand(char buf[], uint8_t bufSize) {
227-
switch (bufSize) {
227+
UserCommandEnum parseUserCommand(char cmd[], uint8_t cmdLen, char args[]) {
228+
switch (cmdLen) {
228229
case 1:
229-
if (!strcmp(buf, "?")) {
230+
if (!strcmp(cmd, "?")) {
230231
return CMD_HELP;
231232
}
232233
break;
234+
case 3:
235+
if (!strcmp_P(cmd, STR_CMD_GET_LOG)) {
236+
return CMD_GET_LOG;
237+
}
238+
break;
233239
case 4:
234-
if (!strcmp_P(buf, STR_CMD_HELP)) {
240+
if (!strcmp_P(cmd, STR_CMD_HELP)) {
235241
return CMD_HELP;
242+
} else if (!strcmp_P(cmd, STR_CMD_GET_STAT)) {
243+
return CMD_GET_STAT;
236244
}
237245
break;
238246
case 5:
239-
if (!strcmp_P(buf, STR_CMD_RESET)) {
247+
if (!strcmp_P(cmd, STR_CMD_RESET)) {
240248
return CMD_RESET;
241249
}
242250
break;
243251
case 6:
244-
if (!strcmp_P(buf, STR_CMD_REC_ON)) {
252+
if (!strcmp_P(cmd, STR_CMD_REC_ON)) {
245253
return CMD_REC_ON;
254+
} else if (!strcmp_P(cmd, STR_CMD_CONFIG)) {
255+
if (strlen(args) > 0) {
256+
return CMD_GET_CONFIG;
257+
} else {
258+
return CMD_SET_CONFIG;
259+
}
246260
}
247261
break;
248262
case 7:
249-
if (!strcmp_P(buf, STR_CMD_REC_OFF)) {
263+
if (!strcmp_P(cmd, STR_CMD_REC_OFF)) {
250264
return CMD_REC_OFF;
251-
} else if (!strcmp_P(buf, STR_CMD_HEAT_ON)) {
265+
} else if (!strcmp_P(cmd, STR_CMD_HEAT_ON)) {
252266
return CMD_HEAT_ON;
253-
} else if (!strcmp_P(buf, STR_CMD_GET_LOG)) {
254-
return CMD_GET_LOG;
255267
}
256268
break;
257269
case 8:
258-
if (!strcmp_P(buf, STR_CMD_HEAT_OFF)) {
270+
if (!strcmp_P(cmd, STR_CMD_HEAT_OFF)) {
259271
return CMD_HEAT_OFF;
260-
} else if (!strcmp_P(buf, STR_CMD_GET_STAT)) {
261-
return CMD_GET_STAT;
262272
}
263273
break;
264-
case 10:
265-
if (!strcmp_P(buf, STR_CMD_SET_CONFIG)) {
266-
return CMD_SET_CONFIG;
267-
} if (!strcmp_P(buf, STR_CMD_GET_CONFIG)) {
268-
return CMD_GET_CONFIG;
269-
}
270-
break;
271274
default:
272275
break;
273276
}
@@ -287,22 +290,22 @@ void SerialUI::setup() {
287290
}
288291

289292
void SerialUI::readUserCommand() {
290-
char buf[COMMAND_BUF_SIZE+1];
293+
char cmd[COMMAND_BUF_SIZE+1];
291294
// fill buffer with 0's => always \0-terminated!
292-
memset(buf, 0, COMMAND_BUF_SIZE);
295+
memset(cmd, 0, COMMAND_BUF_SIZE);
293296
if( Serial.peek() < 0 ) {
294297
return;
295298
}
296299
delay(2);
297300

298301
uint8_t count = 0;
299302
do {
300-
count += Serial.readBytes(&buf[count], COMMAND_BUF_SIZE);
303+
count += Serial.readBytes(&cmd[count], COMMAND_BUF_SIZE);
301304
delay(2);
302305
} while( (count < COMMAND_BUF_SIZE) && !(Serial.peek() < 0) );
303306
#ifdef DEBUG_UI
304307
Serial.print(F("DEBUG_UI: read cmd string: '"));
305-
Serial.print(buf);
308+
Serial.print(cmd);
306309
Serial.print(F("', len: "));
307310
Serial.println(count);
308311
#endif
@@ -311,30 +314,30 @@ void SerialUI::readUserCommand() {
311314
uint8_t len = 0;
312315
boolean prevSpace = false;
313316
for (uint8_t i = 0; i< count; i++) {
314-
if (isspace(buf[i]) && prevSpace) {
317+
if (isspace(cmd[i]) && prevSpace) {
315318
// skip
316319
} else {
317-
buf[len++] = buf[i];
320+
cmd[len++] = cmd[i];
318321
}
319-
prevSpace = isspace(buf[i]);
322+
prevSpace = isspace(cmd[i]);
320323
}
321-
buf[len] = '\0';
324+
cmd[len] = '\0';
322325

323326
// convert to lower case:
324-
char *lower = strlwr(buf);
327+
char *lower = strlwr(cmd);
325328

326329
OperationalParams *op = context->op;
327330
// count the command characters up to the trailing numeric arguments (if any):
328-
uint8_t commandLength = strspn(lower, COMMAND_CHARS);
329-
if (len > commandLength) {
330-
strcpy(op->command->args, &lower[commandLength]);
331+
uint8_t cmdLen = strspn(lower, COMMAND_CHARS);
332+
if (len > cmdLen) {
333+
strcpy(op->command->args, &lower[cmdLen]);
331334
}
332335

333-
if (isspace(lower[commandLength - 1])) {
334-
commandLength--;
336+
if (isspace(lower[cmdLen - 1])) {
337+
cmdLen--;
335338
}
336-
lower[commandLength] = '\0';
337-
op->command->command = parseUserCommand(buf, commandLength);
339+
lower[cmdLen] = '\0';
340+
op->command->command = parseUserCommand(cmd, cmdLen, op->command->args);
338341

339342
#ifdef DEBUG_UI
340343
Serial.print(F("DEBUG_UI: parsed cmd: 0x"));
@@ -434,7 +437,11 @@ void SerialUI::processReadWriteRequests(ReadWriteRequests requests, BoilerStateA
434437
for(uint8_t i=0; i< NUM_USER_COMMANDS; i++) {
435438
if (commands & cmd) {
436439
Serial.print(" - ");
437-
Serial.println(getUserCommandName((UserCommandEnum) cmd, buf));
440+
Serial.print(getUserCommandName((UserCommandEnum) cmd, buf));
441+
if (cmd == CMD_SET_CONFIG) {
442+
Serial.print(F(" <modifiers>"));
443+
}
444+
Serial.println();
438445
}
439446
cmd = cmd << 1;
440447
}

ut_state.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -86,29 +86,26 @@
8686
}
8787

8888

89-
Timestamp MockLog::logMessage(MessageID msg, int16_t param1, int16_t param2) {
89+
Timestamp MockLog::logMessage(MessageID, int16_t, int16_t) {
9090
#ifdef DEBUG_UT_STATE
9191
Serial.println(F("DEBUG_UT_STATE: logMessage(...)"));
9292
#endif
93-
if (msg == 0 || param1 == 0 || param2 == 0) { } // prevent warning "unused parameter ..."
9493
logMessageCount++;
9594
return logTime.timestamp();
9695
}
9796

98-
Timestamp MockLog::logValues(Temperature water, Temperature ambient, Flags flags) {
97+
Timestamp MockLog::logValues(Temperature, Temperature, Flags) {
9998
#ifdef DEBUG_UT_STATE
10099
Serial.println(F("DEBUG_UT_STATE: logValues(...)"));
101100
#endif
102-
if (water == 0 || ambient == 0 || flags == 0) { } // prevent warning "unused parameter ..."
103101
logValuesCount++;
104102
return logTime.timestamp();
105103
}
106104

107-
Timestamp MockLog::logState(StateID previous, StateID current, EventID event) {
105+
Timestamp MockLog::logState(StateID, StateID, EventID) {
108106
#ifdef DEBUG_UT_STATE
109107
Serial.println(F("DEBUG_UT_STATE: logState(...)"));
110108
#endif
111-
if (previous == 0 || current == 0 || event == 0) { } // prevent warning "unused parameter ..."
112109
logStateCount++;
113110
return logTime.timestamp();
114111
}

0 commit comments

Comments
 (0)