Skip to content

Commit

Permalink
Stability improvements and Optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
myTonino committed Aug 14, 2015
1 parent d95847a commit 1e4a19c
Show file tree
Hide file tree
Showing 8 changed files with 311 additions and 115 deletions.
42 changes: 20 additions & 22 deletions Tonino.ino
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// ------------------------------------------------------------------------------------------

#define VERSION "1 0 9"
#define VERSION "1 1 2"

#include <tonino.h>
#include <tonino_lcd.h>
Expand Down Expand Up @@ -86,8 +86,8 @@ ToninoConfig tConfig = ToninoConfig(&colorSense, &display);
// object for serial communication
ToninoSerial tSerial = ToninoSerial(&colorSense, &display, &tConfig, VERSION);

// flag whether display brightness has been reduced in power save mode
bool lowBrightness = false;
// stores original display brightness if it has been reduced in power save mode
int8_t origBrightness = -1;


void setup() {
Expand Down Expand Up @@ -202,7 +202,7 @@ void loop() {
lastTimestamp = checkLowPowerMode(true, lastTimestamp);
}
// short wait because it might already be dark before
// the can is fully placed on the surface
// the can is fully placed on the surface
delay(500);
display.circle(1, 300);
display.clear();
Expand Down Expand Up @@ -249,29 +249,27 @@ inline uint32_t checkLowPowerMode(bool isLight, uint32_t lastTimestamp) {
return millis();

} else if (millis() - lastTimestamp > TIME_TILL_DIM) {
if (!lowBrightness) {
if (origBrightness < 0) {
// temporarily set low brightness
origBrightness = tConfig.getBrightness();
display.setBrightness(1);
lowBrightness = true;
}
return lastTimestamp;

} else {
if (lowBrightness) {
// restore original brightness
display.setBrightness(tConfig.getBrightness());
lowBrightness = false;
}
return lastTimestamp;
} else if (origBrightness >= 0) {
// restore original brightness
display.setBrightness(origBrightness);
origBrightness = -1;
}
return lastTimestamp;
}

// called when detected first calibration plate with quick scan
boolean calibrate() {
sensorData sd;

display.calibration1();
WRITEDEBUG("Calibrating ... ");
WRITEDEBUGLN("Cal.");
delay(500);

// scan plate 1
Expand Down Expand Up @@ -328,15 +326,15 @@ boolean calibrate() {
cal[0] = (HIGH_TARGET - LOW_TARGET) / (rb_high - rb_low);
cal[1] = LOW_TARGET - cal[0]*rb_low;

WRITEDEBUG((sd_1.value[RED_IDX] + sd_2.value[RED_IDX] - 2*sd_d.value[RED_IDX]) / 2);
WRITEDEBUG(redavg);
WRITEDEBUG("/");
WRITEDEBUG((sd_1.value[BLUE_IDX] + sd_2.value[BLUE_IDX] - 2*sd_d.value[BLUE_IDX]) / 2);
WRITEDEBUG(blueavg);
WRITEDEBUG("=");
WRITEDEBUGF(rb_high, 5);

WRITEDEBUG(" => ");
WRITEDEBUG("=>");
WRITEDEBUGF(cal[0], 5);
WRITEDEBUG(", ");
WRITEDEBUG(",");
WRITEDEBUGLNF(cal[1], 5);

if (checkCommands()) return false;
Expand All @@ -357,10 +355,10 @@ boolean calibrate() {
// make a full scan and display on LCD
inline void scanAndDisplay() {
// make a measurement with stored configuration, parameters:
// 1: NULL: not interested in raw values
// 2: false: no display animation during scan
// 3: NULL: not interested in raw values
// 4: true: switch on LEDs
// 1: NULL: not interested in raw values
// 2: false: no display animation during scan
// 3: NULL: not interested in raw values
// 4: true: switch on LEDs
// 5: false: no explicit external light removal
int32_t tval = colorSense.scan(NULL, false, NULL, true, false);

Expand Down
4 changes: 4 additions & 0 deletions Tonino/tonino.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
// ------------------------------------------------------------------------------------------

#define DODEBUG false
// values will be stored in EEPROM value+1 timez; set to 0 for no redundancy
// pay attention that EEPROM_START_ADDRESS + (EEPROM_REDUNDANT_CYCLES+1)*EEPROM_SIZE
// is still within EEPROM limits
#define EEPROM_REDUNDANT_CYCLES 2

// separator between multiple values in one line
#define SEPARATOR " "
Expand Down
Loading

0 comments on commit 1e4a19c

Please sign in to comment.