Skip to content

Commit

Permalink
prototype for centralized car status print
Browse files Browse the repository at this point in the history
  • Loading branch information
dlyubimov committed Jun 30, 2017
1 parent cc9b3ce commit 8ca11cd
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 15 deletions.
35 changes: 25 additions & 10 deletions Hydra_EVSE/Hydra_EVSE.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// SW version
#define SW_VERSION "2.4.1"

// Define this for the basic unit tests run in a generica arduino uno board with a display shield.
// Define this for the basic unit tests run in a generica arduino uno board with a display shield.
#define UNIT_TESTS

// By historical accident, car B is actually
Expand Down Expand Up @@ -68,7 +68,7 @@
// Current production or unit test hardware (currently, version 2.3.1 in my posession).
#ifndef UNIT_TESTS
#include "hw_2_3_1.h"
#else
#else
#include "units.h"
#endif

Expand Down Expand Up @@ -98,11 +98,25 @@


// for things like erroring out a car
#define BOTH 0
#define CAR_A 1
#define CAR_B 2
#define BOTH 0x0
#define CAR_A 0x1
#define CAR_B 0x2
#define CAR_MASK 0x3
#define DEFAULT_TIEBREAK CAR_A

// display status to be combined with CAR_A, CAR_B, or BOTH
#define STATUS_TIEBREAK 0x4

// Mutually exclusive statuses
#define STATUS_UNPLUGGED (0x0u << 3)
#define STATUS_OFF (0x1u << 3)
#define STATUS_ON (0x2u << 3)
#define STATUS_WAIT (0x3u << 3)
#define STATUS_DONE (0x4u << 3)
#define STATUS_ERR (0x5u << 3)
#define STATUS_MASK ( -1u >> 16 - 4 << 3)


// Don't use 0 or 1 because that's the value of LOW and HIGH.
#define HALF 3
#define FULL 4
Expand Down Expand Up @@ -233,7 +247,7 @@
// simply include state transitions only), or 2 for debugging.
#ifdef UNIT_TESTS
#define SERIAL_LOG_LEVEL LOG_DEBUG
#else
#else
#define SERIAL_LOG_LEVEL LOG_NONE
#endif

Expand Down Expand Up @@ -302,8 +316,8 @@ typedef struct event_struct {
void reset() {
event_type = TE_NONE;
hour = 0;
minute = 0;
dow_mask = 0;
minute = 0;
dow_mask = 0;
}

} event_type;
Expand Down Expand Up @@ -344,7 +358,7 @@ typedef struct calib_struct {

// eprom persistence format signature (usually minimally compatible SW_VERSION):
// 2.4.1
#define PERSIST_SIG 241
#define PERSIST_SIG 241
#define EEPROM_OFFSET 0

struct persisted_struct {
Expand Down Expand Up @@ -379,13 +393,14 @@ struct persisted_struct {


////////////////////////////////////////////////////////////
// This is stuff from Hydra_EVSE.ino that unit tests use
// This is stuff from Hydra_EVSE.ino that unit tests use

extern boolean inMenu;
extern void doMenu(boolean);
extern void log(unsigned int level, const char * fmt_str, ...);
DISPLAY_DECL(display);
extern persisted_struct persisted;
extern void Delay(unsigned int);



Expand Down
2 changes: 1 addition & 1 deletion Hydra_EVSE/Hydra_EVSE.ino
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ unsigned int checkEvent() {
}

// Just like delay(), but petting the watchdog while we're at it
static void Delay(unsigned int t) {
void Delay(unsigned int t) {
while (t > 100) {
delay(100);
t -= 100;
Expand Down
65 changes: 61 additions & 4 deletions Hydra_EVSE/units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static void testEepromSetup() {
persisted.reset();
persisted.eepromWrite();


//read/write test
persisted.operatingMode = MODE_SEQUENTIAL;
persisted.eepromWrite();
Expand All @@ -40,19 +40,74 @@ static void testEepromSetup() {
}

// invalid signature reset test
persisted.signature=0xff;
persisted.signature = 0xff;
persisted.validate();

persisted_struct clone2;
if ( persisted.signature != PERSIST_SIG || clone2.signature != PERSIST_SIG || clone2.operatingMode != MODE_SHARED ) {
log(LOG_INFO, P("eeprom sig validation UNIT FAIL."));
return;
}
log(LOG_DEBUG, "eeprom UNIT OK.");

log(LOG_DEBUG, P("eeprom UNIT OK."));

}

// Status is combination of (CAR_A or CAR_B or CAR_BOTH) | (one of STATUS_XXX) [ | STATUS_TIEBREAK ]
void displayStatus(unsigned int status) {
unsigned int car = status & CAR_MASK;
int col;
char carLetter;
switch (car) {
case CAR_A: col = 0; carLetter = 'A'; break;
case CAR_B: col = 8; carLetter = 'B'; break;
default:
displayStatus( (status & ~CAR_MASK) | CAR_A);
displayStatus( (status & ~CAR_MASK) | CAR_B);
return;
}
// display.setCursor(col,1);
// for (int i = 0; i < 8; i++) display.print(' ');
display.setCursor(col, 1);
display.print(carLetter); // 1
display.print(P(": ")); // 3

log(LOG_DEBUG, P("status: %x, CAR:%c, status bits: %x, status mask: %x."), status, carLetter, status & STATUS_MASK, STATUS_MASK);

switch ( status & STATUS_MASK) { // 7
case STATUS_UNPLUGGED: display.print(P("--- ")); break;
case STATUS_OFF: display.print(P("off ")); break;
case STATUS_ON: display.print(P("on ")); break;
case STATUS_WAIT: display.print(P("wait")); break;
case STATUS_DONE: display.print(P("done")); break;
case STATUS_ERR:
default: display.print(P("ERR ")); break;
}
display.print(" "); // 8
if ( (status & STATUS_TIEBREAK) != 0) {
display.setCursor(col + 6, 1);
display.print('*');
}

}

static void testDS(char* desc, unsigned int status) {
display.clear();
display.print (desc);
displayStatus(status);
Delay(3000);
}

void testDisplayStatus() {
testDS(P("A&B UNPL"),BOTH|STATUS_UNPLUGGED);
testDS(P("A&B off"),BOTH|STATUS_OFF);
testDS(P("B off tie"),CAR_B|STATUS_OFF|STATUS_TIEBREAK);
testDS(P("A&B on"),BOTH|STATUS_ON);
testDS(P("A&B done"),BOTH|STATUS_DONE);
testDS(P("A&B wait"),BOTH|STATUS_WAIT);
}


static void testMenuSetup() {
inMenu = true;
doMenu(true);
Expand All @@ -61,6 +116,7 @@ static void testMenuSetup() {

int unitsSetup() {
testEepromSetup();
testDisplayStatus();
testMenuSetup();
return false;
}
Expand All @@ -70,3 +126,4 @@ int unitsLoop() {
return false;
}


0 comments on commit 8ca11cd

Please sign in to comment.