From 65ae2048c549361e3c39e9e4e84c3896fffdd405 Mon Sep 17 00:00:00 2001 From: sinseman Date: Sat, 21 Feb 2015 14:12:27 +0100 Subject: [PATCH] more & more memory optimizations --- README.md | 2 +- Variometer/Variometer.ino | 46 ++++++++++------ libraries/EEPROMAnything/EEPROMAnything.h | 14 +++-- libraries/MenuBackend/MenuBackend.h | 65 +++++++++++++---------- 4 files changed, 79 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index be30064..aedeecd 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ Lorsqu'il n'y a pas de baisse ou de prise d'altitude significative pendant un ce A la fin du vol les statistiques sont sauvegardées et ne sont pas perdues à l'extinction du variomètre. -Ce programme peut enregistrer 5 rapports de vol. Une fois un vol terminé, la piste suivante d'enregistrement est sélectionnée. Si celle-ci n'est pas vide elle n'est pas écrasée. Il faut alors manuellement effacer la plage de stat en cours ou reset toutes les plages. +Ce programme peut enregistrer 7 rapports de vol. Une fois un vol terminé, la piste suivante d'enregistrement est sélectionnée. Si celle-ci n'est pas vide elle n'est pas écrasée. Il faut alors manuellement effacer la plage de stat en cours (avec un appui long sur le bouton depuis l'interface Vario) ou reset toutes les plages (Menu Stats --> Reset). **Statistique** diff --git a/Variometer/Variometer.ino b/Variometer/Variometer.ino index 161302c..1f2e69d 100644 --- a/Variometer/Variometer.ino +++ b/Variometer/Variometer.ino @@ -119,11 +119,11 @@ float alt; float tim; #define memoryBase 32 -// Configuration structure (137 bits) +// Configuration structure (89 bits) struct Conf { - float vario_climb_rate_start; //minimum climb beeping value(ex. start climbing beeping at 0.4m/s) - float vario_sink_rate_start; //maximum sink beeping value (ex. start sink beep at -1.1m/s) + int8_t vario_climb_rate_start; //minimum climb beeping value(ex. start climbing beeping at 0.4m/s) + int8_t vario_sink_rate_start; //maximum sink beeping value (ex. start sink beep at -1.1m/s) int currentAltitude; uint8_t light_cpt; uint8_t contrast_default; @@ -131,11 +131,21 @@ struct Conf float p0; uint8_t stat_index; } conf = { - 0.3, -1.1 , 0, 0, 50, true, 1040.00, 0 + 3, -11 , 0, 0, 50, true, 1040.00, 0 }; +float getVarioClimbRateStart() +{ + return (float)conf.vario_climb_rate_start/10; +} + +float getVarioSinkRateStart() +{ + return (float)conf.vario_sink_rate_start/10; +} + // Statistic structure (128 bits) -#define NB_STATS 6 +#define NB_STATS 7 struct Stat { uint32_t chrono_start; @@ -202,7 +212,7 @@ void resetAllStats() void playConfirmMelody() { if (true == conf.volume){ - toneAC(700, 300); + toneAC(700, 500); } } @@ -481,14 +491,14 @@ void renderMenu(MenuItem newMenuItem = menu.getCurrent(), uint8_t dir = 2) case MENU_MONTEE: { - conf.vario_climb_rate_start = updateConfItem(conf.vario_climb_rate_start, dir, 0.1); + conf.vario_climb_rate_start = updateConfItem(conf.vario_climb_rate_start, dir, 1); - if (conf.vario_climb_rate_start < 0.1) { + if (conf.vario_climb_rate_start < 1) { conf.vario_climb_rate_start = 0; display.print(F("Off")); } else { - display.print(conf.vario_climb_rate_start); + display.print(getVarioClimbRateStart(), 1); display.setTextSize(1); display.print(F("m/s")); } @@ -497,14 +507,14 @@ void renderMenu(MenuItem newMenuItem = menu.getCurrent(), uint8_t dir = 2) case MENU_DESCENTE: { - conf.vario_sink_rate_start = updateConfItem(conf.vario_sink_rate_start, dir, 0.1); + conf.vario_sink_rate_start = updateConfItem(conf.vario_sink_rate_start, dir, 1); if (conf.vario_sink_rate_start >= 0) { conf.vario_sink_rate_start = 0; display.print(F("Off")); } else { - display.print(conf.vario_sink_rate_start); + display.print(getVarioSinkRateStart(), 1); display.setTextSize(1); display.print(F("m/s")); } @@ -717,7 +727,6 @@ void menuSetup() */ m_vario.addAfter(m_stats); - m_stats.addAfter(m_options); m_stats.addRight(m_stat); m_stat.addBefore(m_retour2); @@ -834,8 +843,12 @@ void makeBeeps() noSound = (timeNoPauseBeep <= 30)? false: !noSound; if (false == noSound){ + + float varioClimbRateStart = getVarioClimbRateStart(); + float varioSinkRateStart = getVarioSinkRateStart(); + //beep even if vario has negative value but vario is climbing - float variation = (vario < conf.vario_climb_rate_start && vario_diff >= conf.vario_climb_rate_start && conf.vario_climb_rate_start != 0)? vario_diff: vario; + float variation = (vario < varioClimbRateStart && vario_diff >= varioClimbRateStart && varioClimbRateStart != 0)? vario_diff: vario; if (timeNoPauseBeep <= 30){ timeNoPauseBeep++; @@ -845,7 +858,7 @@ void makeBeeps() beepLatency = getBeepLatency(variation); } - if ((vario > conf.vario_climb_rate_start && conf.vario_climb_rate_start != 0) || (vario < conf.vario_sink_rate_start && conf.vario_sink_rate_start != 0)) { + if ((vario > varioClimbRateStart && varioClimbRateStart != 0) || (vario < varioSinkRateStart && varioSinkRateStart != 0)) { //when climbing make faster and shorter beeps //toneAC(getBeepFrequency(variation), 10, beepLatency, true); toneAC(getBeepFrequency(variation), beepLatency); @@ -912,7 +925,7 @@ void loop() vario = vario + 0.01; if (vario > 4) vario = 0; - */ + */ // Update stats if chrono is running if (stat.chrono_start != 0) { @@ -1008,8 +1021,7 @@ void loop() } //correction beep latency makeBeeps(); - } - + } //Serial.println((tempo - micros())); } diff --git a/libraries/EEPROMAnything/EEPROMAnything.h b/libraries/EEPROMAnything/EEPROMAnything.h index bc70898..8047575 100644 --- a/libraries/EEPROMAnything/EEPROMAnything.h +++ b/libraries/EEPROMAnything/EEPROMAnything.h @@ -1,5 +1,11 @@ -#include -#include // for type definitions +#ifndef __EEPROMAnything__ +#define __EEPROMAnything__ + +#if (ARDUINO >= 100) + #include "Arduino.h" +#else + #include "WProgram.h" +#endif template int EEPROM_writeAnything(int ee, const T& value) { @@ -17,4 +23,6 @@ template int EEPROM_readAnything(int ee, T& value) for (i = 0; i < sizeof(value); i++) *p++ = EEPROM.read(ee++); return i; -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/libraries/MenuBackend/MenuBackend.h b/libraries/MenuBackend/MenuBackend.h index ed43ac3..5effec0 100644 --- a/libraries/MenuBackend/MenuBackend.h +++ b/libraries/MenuBackend/MenuBackend.h @@ -30,7 +30,7 @@ class MenuItem; //forward declaration of the menu item struct MenuChangeEvent { - const MenuItem &from; + //const MenuItem &from; const MenuItem &to; }; @@ -264,11 +264,12 @@ class MenuItem || @paramter cb The callback to be fired || @return this MenuItem */ + /* MenuItem &onChangeFrom(cb_change cb) { cb_onChangeFrom = cb; return *this; - } + }*/ /* || @description || | Set a callback to be fired after any 'move' function is called with this item @@ -278,12 +279,13 @@ class MenuItem || @paramter cb The callback to be fired || @return this MenuItem */ + /* MenuItem &onChangeTo(cb_change cb) { cb_onChangeTo = cb; return *this; } - + */ /* || @description || | Set a callback to be fired when 'moveUp' is called with this item as the current MenuItem @@ -292,11 +294,12 @@ class MenuItem || @paramter cb The callback to be fired || @return this MenuItem */ + /* MenuItem &onUp(cb_move cb) { cb_onUp = cb; return *this; - } + }*/ /* || @description || | Set a callback to be fired when 'moveDown' is called with this item as the current MenuItem @@ -305,11 +308,12 @@ class MenuItem || @paramter cb The callback to be fired || @return this MenuItem */ + /* MenuItem &onDown(cb_move cb) { cb_onDown = cb; return *this; - } + }*/ /* || @description || | Set a callback to be fired when 'moveLeft' is called with this item as the current MenuItem @@ -318,11 +322,12 @@ class MenuItem || @paramter cb The callback to be fired || @return this MenuItem */ + /* MenuItem &onLeft(cb_move cb) { cb_onLeft = cb; return *this; - } + }*/ /* || @description || | Set a callback to be fired when 'moveRight' is called with this item as the current MenuItem @@ -331,11 +336,12 @@ class MenuItem || @paramter cb The callback to be fired || @return this MenuItem */ + /* MenuItem &onRight(cb_move cb) { cb_onRight = cb; return *this; - } + }*/ /* || @description || | Set a callback to be fired when 'use' is called with this item as the current MenuItem @@ -344,11 +350,12 @@ class MenuItem || @paramter cb The callback to be fired || @return this MenuItem */ + /* MenuItem &onUse(cb_use cb) { cb_onUse = cb; return *this; - } + }*/ protected: uint8_t shortkey; @@ -358,13 +365,13 @@ class MenuItem MenuItem *after; MenuItem *left; - cb_change cb_onChangeFrom; - cb_change cb_onChangeTo; - cb_move cb_onUp; - cb_move cb_onDown; - cb_move cb_onLeft; - cb_move cb_onRight; - cb_use cb_onUse; + //cb_change cb_onChangeFrom; + // cb_change cb_onChangeTo; + // cb_move cb_onUp; + // cb_move cb_onDown; + // cb_move cb_onLeft; + // cb_move cb_onRight; + // cb_use cb_onUse; MenuBackend *menuBackend; @@ -396,7 +403,7 @@ class MenuItem class MenuBackend { public: - MenuBackend(cb_use menuUse, cb_change menuChange = 0) : root(F("MenuRoot")) + MenuBackend(cb_use menuUse, cb_change menuChange = 0) : root(F("")) { current = &root; cb_menuChange = menuChange; @@ -432,12 +439,12 @@ class MenuBackend || # */ void moveUp() - { + {/* if (current->cb_onUp) { MenuMoveEvent mme = { *current }; (*current->cb_onUp)(mme); - } + }*/ setCurrent(current->moveUp()); } /* @@ -446,12 +453,12 @@ class MenuBackend || # */ void moveDown() - { + {/* if (current->cb_onDown) { MenuMoveEvent mme = { *current }; (*current->cb_onDown)(mme); - } + }*/ setCurrent(current->moveDown()); } /* @@ -461,11 +468,12 @@ class MenuBackend */ void moveLeft() { + /* if (current->cb_onLeft) { MenuMoveEvent mme = { *current }; (*current->cb_onLeft)(mme); - } + }*/ setCurrent(current->moveLeft()); } /* @@ -474,12 +482,12 @@ class MenuBackend || # */ void moveRight() - { + {/* if (current->cb_onRight) { MenuMoveEvent mme = { *current }; (*current->cb_onRight)(mme); - } + }*/ setCurrent(current->moveRight()); } /* @@ -514,11 +522,12 @@ class MenuBackend void use() { //current->use(); + /* if (current->cb_onUse) { MenuUseEvent mue = { *current }; (*current->cb_onUse)(mue); - } + }*/ if (cb_menuUse) { MenuUseEvent mue = { *current }; @@ -540,15 +549,17 @@ class MenuBackend { if (next) { - MenuChangeEvent mce = { *current, *next }; + MenuChangeEvent mce = { *next }; + /* if (current->cb_onChangeFrom) { (*current->cb_onChangeFrom)(mce); - } + }*/ + /* if (next->cb_onChangeTo) { (*next->cb_onChangeTo)(mce); - } + }*/ if (cb_menuChange) { (*cb_menuChange)(mce);