Optimizations
improve stats rendering and cumulative altitude
This commit is contained in:
@@ -45,7 +45,7 @@ bool menuUsed = false;
|
|||||||
bool menuUsed_last = false;
|
bool menuUsed_last = false;
|
||||||
bool varioState = false;
|
bool varioState = false;
|
||||||
uint8_t stat_displayed = 1;
|
uint8_t stat_displayed = 1;
|
||||||
//bool stat_blink_status = false;
|
bool stat_blink_status = false;
|
||||||
|
|
||||||
#define MENU_RIGHT 0
|
#define MENU_RIGHT 0
|
||||||
#define MENU_LEFT 1
|
#define MENU_LEFT 1
|
||||||
@@ -138,12 +138,12 @@ struct Conf
|
|||||||
|
|
||||||
float getVarioClimbRateStart()
|
float getVarioClimbRateStart()
|
||||||
{
|
{
|
||||||
return (float)conf.vario_climb_rate_start/10;
|
return (float)conf.vario_climb_rate_start / 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
float getVarioSinkRateStart()
|
float getVarioSinkRateStart()
|
||||||
{
|
{
|
||||||
return (float)conf.vario_sink_rate_start/10;
|
return (float)conf.vario_sink_rate_start / 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Statistic structure (128 bits)
|
// Statistic structure (128 bits)
|
||||||
@@ -173,7 +173,7 @@ void writeStat(uint8_t index = conf.stat_index, Stat &value = stat)
|
|||||||
|
|
||||||
void incrementStatIndex()
|
void incrementStatIndex()
|
||||||
{
|
{
|
||||||
conf.stat_index = (conf.stat_index == NB_STATS - 1)? 0 : conf.stat_index + 1;
|
conf.stat_index = (conf.stat_index == NB_STATS - 1) ? 0 : conf.stat_index + 1;
|
||||||
EEPROM_writeAnything(0, conf);
|
EEPROM_writeAnything(0, conf);
|
||||||
readStat();
|
readStat();
|
||||||
}
|
}
|
||||||
@@ -213,15 +213,19 @@ void resetAllStats()
|
|||||||
|
|
||||||
void playConfirmMelody()
|
void playConfirmMelody()
|
||||||
{
|
{
|
||||||
if (true == conf.volume){
|
if (true == conf.volume) {
|
||||||
toneAC(700, 500);
|
toneAC(700, 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void resetTimer(unsigned long &timer)
|
||||||
|
{
|
||||||
|
timer = millis();
|
||||||
|
}
|
||||||
|
|
||||||
void renderChrono(Stat value = stat)
|
void renderChrono(Stat value = stat)
|
||||||
{
|
{
|
||||||
uint16_t s = (value.chrono == 0 && value.chrono_start != 0)? rtc.now().unixtime() - value.chrono_start: value.chrono;
|
uint16_t s = (value.chrono == 0 && value.chrono_start != 0) ? rtc.now().unixtime() - value.chrono_start : value.chrono;
|
||||||
uint8_t h = floor(s / 3600);
|
uint8_t h = floor(s / 3600);
|
||||||
s -= h * 3600;
|
s -= h * 3600;
|
||||||
uint8_t m = floor(s / 60);
|
uint8_t m = floor(s / 60);
|
||||||
@@ -238,8 +242,9 @@ void renderChrono(Stat value = stat)
|
|||||||
|
|
||||||
void renderVario()
|
void renderVario()
|
||||||
{
|
{
|
||||||
if (true == varioState){
|
if (true == varioState) {
|
||||||
|
|
||||||
|
DateTime now = rtc.now();
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
|
|
||||||
//ALtitude
|
//ALtitude
|
||||||
@@ -250,7 +255,6 @@ void renderVario()
|
|||||||
display.print(F("m"));
|
display.print(F("m"));
|
||||||
|
|
||||||
//Time
|
//Time
|
||||||
DateTime now = rtc.now();
|
|
||||||
display.setCursor(55, 0);
|
display.setCursor(55, 0);
|
||||||
renderZero(now.hour());
|
renderZero(now.hour());
|
||||||
display.print(now.hour());
|
display.print(now.hour());
|
||||||
@@ -327,7 +331,7 @@ void renderVolume(bool volume)
|
|||||||
conf.volume = volume;
|
conf.volume = volume;
|
||||||
|
|
||||||
push_write_eeprom = 0;
|
push_write_eeprom = 0;
|
||||||
get_time1 = millis(); //stop the refresh rendering vario
|
resetTimer(get_time1); //stop the refresh rendering vario
|
||||||
|
|
||||||
display.println(F("Sons:"));
|
display.println(F("Sons:"));
|
||||||
(false == conf.volume) ? display.print(F("Off")) : display.print(F("On"));
|
(false == conf.volume) ? display.print(F("Off")) : display.print(F("On"));
|
||||||
@@ -424,7 +428,7 @@ void renderMenu(MenuItem newMenuItem = menu.getCurrent(), uint8_t dir = 2)
|
|||||||
display.setTextSize(1);
|
display.setTextSize(1);
|
||||||
display.setTextColor(WHITE, BLACK);
|
display.setTextColor(WHITE, BLACK);
|
||||||
|
|
||||||
if (newMenuItem.getShortkey() != MENU_LEFT){
|
if (newMenuItem.getShortkey() != MENU_LEFT) {
|
||||||
if (newMenuItem.getShortkey() < 10)
|
if (newMenuItem.getShortkey() < 10)
|
||||||
display.println(F("Accueil"));
|
display.println(F("Accueil"));
|
||||||
else if (newMenuItem.getShortkey() >= 10 && newMenuItem.getShortkey() < 20)
|
else if (newMenuItem.getShortkey() >= 10 && newMenuItem.getShortkey() < 20)
|
||||||
@@ -433,7 +437,7 @@ void renderMenu(MenuItem newMenuItem = menu.getCurrent(), uint8_t dir = 2)
|
|||||||
display.println(F("Statistiques"));
|
display.println(F("Statistiques"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newMenuItem.getShortkey() != MENU_STAT){
|
if (newMenuItem.getShortkey() != MENU_STAT) {
|
||||||
|
|
||||||
display.setTextSize(2);
|
display.setTextSize(2);
|
||||||
display.println(newMenuItem.getName());
|
display.println(newMenuItem.getName());
|
||||||
@@ -656,20 +660,23 @@ void renderMenu(MenuItem newMenuItem = menu.getCurrent(), uint8_t dir = 2)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
//if (stat_blink_status) {
|
if (!stat_blink_status) {
|
||||||
display.setTextColor(BLACK);
|
display.setTextColor(BLACK);
|
||||||
renderDateTime(DateTime(stat_to_display.chrono_start));
|
renderDateTime(DateTime(stat_to_display.chrono_start));
|
||||||
display.println();
|
}
|
||||||
//}
|
else {
|
||||||
//else {
|
display.print(F("M"));
|
||||||
|
display.print(stat_displayed);
|
||||||
|
display.setTextColor(BLACK);
|
||||||
|
}
|
||||||
|
|
||||||
|
stat_blink_status = !stat_blink_status;
|
||||||
|
display.println();
|
||||||
|
|
||||||
display.print(F("Chrono:"));
|
display.print(F("Chrono:"));
|
||||||
renderChrono(stat_to_display);
|
renderChrono(stat_to_display);
|
||||||
display.println();
|
display.println();
|
||||||
|
|
||||||
//}
|
|
||||||
//stat_blink_status = !stat_blink_status;
|
|
||||||
|
|
||||||
display.print(F("Alt max:"));
|
display.print(F("Alt max:"));
|
||||||
renderStatItem(stat_to_display.alti_max, F("m"), true);
|
renderStatItem(stat_to_display.alti_max, F("m"), true);
|
||||||
display.println();
|
display.println();
|
||||||
@@ -679,8 +686,8 @@ void renderMenu(MenuItem newMenuItem = menu.getCurrent(), uint8_t dir = 2)
|
|||||||
display.println();
|
display.println();
|
||||||
|
|
||||||
display.print(F("m/s:"));
|
display.print(F("m/s:"));
|
||||||
renderStatItem(-(float)stat_to_display.txchutemax/10, F("|"));
|
renderStatItem(-(float)stat_to_display.txchutemax / 10, F("|"));
|
||||||
renderStatItem((float)stat_to_display.txchutemin/10, F(""));
|
renderStatItem((float)stat_to_display.txchutemin / 10, F(""));
|
||||||
display.println();
|
display.println();
|
||||||
|
|
||||||
display.print(F("Cumul:"));
|
display.print(F("Cumul:"));
|
||||||
@@ -804,7 +811,7 @@ uint8_t getVccPixels()
|
|||||||
//Serial.println(real_bat);
|
//Serial.println(real_bat);
|
||||||
average_vcc = (average_vcc == 0) ? real_bat : (int)(average_vcc * 0.94 + real_bat * 0.06);
|
average_vcc = (average_vcc == 0) ? real_bat : (int)(average_vcc * 0.94 + real_bat * 0.06);
|
||||||
|
|
||||||
uint8_t pixels = map(average_vcc,3100,4100,0,8);
|
uint8_t pixels = map(average_vcc, 3100, 4100, 0, 8);
|
||||||
if (pixels > 8)
|
if (pixels > 8)
|
||||||
pixels = 8;
|
pixels = 8;
|
||||||
else if (pixels < 1)
|
else if (pixels < 1)
|
||||||
@@ -816,15 +823,15 @@ uint8_t getVccPixels()
|
|||||||
|
|
||||||
uint8_t getBeepLatency(float variation)
|
uint8_t getBeepLatency(float variation)
|
||||||
{
|
{
|
||||||
int latency = 150 - (variation * 30);
|
int latency = 150 - (variation * 30);
|
||||||
return (latency < 70)? 70: (latency > 150)? 150: latency;
|
return (latency < 70) ? 70 : (latency > 150) ? 150 : latency;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint16_t getBeepFrequency(float variation)
|
uint16_t getBeepFrequency(float variation)
|
||||||
{
|
{
|
||||||
int frequency = 690 + (150 * variation);
|
int frequency = 690 + (150 * variation);
|
||||||
return (frequency < 100)? 100: (frequency > 1300)? 1300 :frequency;
|
return (frequency < 100) ? 100 : (frequency > 1300) ? 1300 : frequency;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -834,7 +841,7 @@ void updateAltitude(bool reset = false)
|
|||||||
sensors_event_t event;
|
sensors_event_t event;
|
||||||
bmp085.getEvent(&event);
|
bmp085.getEvent(&event);
|
||||||
// put it in smooth filter and take average
|
// put it in smooth filter and take average
|
||||||
average_pressure = (true == reset)? event.pressure : average_pressure * 0.95 + event.pressure * 0.05;
|
average_pressure = (true == reset) ? event.pressure : average_pressure * 0.95 + event.pressure * 0.05;
|
||||||
// take new altitude in meters
|
// take new altitude in meters
|
||||||
Altitude = bmp085.pressureToAltitude(conf.p0, average_pressure) + conf.currentAltitude;
|
Altitude = bmp085.pressureToAltitude(conf.p0, average_pressure) + conf.currentAltitude;
|
||||||
}
|
}
|
||||||
@@ -853,21 +860,21 @@ void resetAltitudeSensor()
|
|||||||
*/
|
*/
|
||||||
void makeBeeps()
|
void makeBeeps()
|
||||||
{
|
{
|
||||||
if (true == conf.volume && (millis() >= (get_timeBeep + beepLatency) || timeNoPauseBeep <= 30))
|
if (true == conf.volume && (millis() >= (get_timeBeep + beepLatency) || timeNoPauseBeep <= 40))
|
||||||
{
|
{
|
||||||
get_timeBeep = millis();
|
resetTimer(get_timeBeep);
|
||||||
|
|
||||||
noSound = (timeNoPauseBeep <= 30)? false: !noSound;
|
noSound = (timeNoPauseBeep <= 40) ? false : !noSound;
|
||||||
|
|
||||||
if (false == noSound){
|
if (false == noSound) {
|
||||||
|
|
||||||
float varioClimbRateStart = getVarioClimbRateStart();
|
float varioClimbRateStart = getVarioClimbRateStart();
|
||||||
float varioSinkRateStart = getVarioSinkRateStart();
|
float varioSinkRateStart = getVarioSinkRateStart();
|
||||||
|
|
||||||
//beep even if vario has negative value but vario is climbing
|
//beep even if vario has negative value but vario is climbing
|
||||||
float variation = (vario < varioClimbRateStart && vario_diff >= varioClimbRateStart && varioClimbRateStart != 0)? vario_diff: vario;
|
float variation = (vario < varioClimbRateStart && vario_diff >= varioClimbRateStart && varioClimbRateStart != 0) ? vario_diff : vario;
|
||||||
|
|
||||||
if (timeNoPauseBeep <= 30){
|
if (timeNoPauseBeep <= 40) {
|
||||||
timeNoPauseBeep++;
|
timeNoPauseBeep++;
|
||||||
beepLatency = 150;
|
beepLatency = 150;
|
||||||
}
|
}
|
||||||
@@ -896,7 +903,7 @@ void setup()
|
|||||||
//Serial.begin(9600);
|
//Serial.begin(9600);
|
||||||
|
|
||||||
// clear the configuration
|
// clear the configuration
|
||||||
if (initialisation){
|
if (initialisation) {
|
||||||
EEPROM_writeAnything(0, conf);
|
EEPROM_writeAnything(0, conf);
|
||||||
resetAllStats();
|
resetAllStats();
|
||||||
}
|
}
|
||||||
@@ -929,17 +936,20 @@ void setup()
|
|||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
float tempo = micros();
|
|
||||||
|
|
||||||
readButtons();
|
readButtons();
|
||||||
updateAltitude();
|
updateAltitude();
|
||||||
|
|
||||||
|
float tempo = micros();
|
||||||
|
|
||||||
|
/* TEST BLOC */
|
||||||
|
//Altitude = alt + 0.05;
|
||||||
|
|
||||||
// put it in smooth filter and take average
|
// put it in smooth filter and take average
|
||||||
vario = vario * 0.8 + (200000 * ((alt - Altitude) / (tim - tempo)));
|
vario = vario * 0.8 + (200000 * ((Altitude - alt) / (tempo - tim)));
|
||||||
|
|
||||||
/* TEST BLOC */
|
/* TEST BLOC */
|
||||||
/*
|
/*
|
||||||
vario = vario + 0.01;
|
vario = vario + 0.005;
|
||||||
if (vario > 4)
|
if (vario > 4)
|
||||||
vario = 0;
|
vario = 0;
|
||||||
*/
|
*/
|
||||||
@@ -948,14 +958,14 @@ void loop()
|
|||||||
if (stat.chrono_start != 0) {
|
if (stat.chrono_start != 0) {
|
||||||
|
|
||||||
if (vario > 0)
|
if (vario > 0)
|
||||||
stat.cumul_alt += vario * (1000 /(tempo - tim));
|
stat.cumul_alt += Altitude - alt;
|
||||||
|
|
||||||
if (Altitude > stat.alti_max)
|
if (Altitude > stat.alti_max)
|
||||||
stat.alti_max = Altitude;
|
stat.alti_max = Altitude;
|
||||||
if (Altitude < stat.alti_min)
|
if (Altitude < stat.alti_min)
|
||||||
stat.alti_min = Altitude;
|
stat.alti_min = Altitude;
|
||||||
|
|
||||||
int decivario = (int)(vario*10);
|
int decivario = (int)(vario * 10);
|
||||||
if (decivario < -stat.txchutemax)
|
if (decivario < -stat.txchutemax)
|
||||||
stat.txchutemax = -decivario;
|
stat.txchutemax = -decivario;
|
||||||
if (decivario > stat.txchutemin)
|
if (decivario > stat.txchutemin)
|
||||||
@@ -971,7 +981,11 @@ void loop()
|
|||||||
//every second
|
//every second
|
||||||
if (millis() >= (get_time1 + 1000))
|
if (millis() >= (get_time1 + 1000))
|
||||||
{
|
{
|
||||||
get_time1 = millis();
|
resetTimer(get_time1);
|
||||||
|
|
||||||
|
if (menu.getCurrent().getShortkey() == MENU_STAT) {
|
||||||
|
menu.use();
|
||||||
|
}
|
||||||
|
|
||||||
// proceedings of the dynamic display of vario
|
// proceedings of the dynamic display of vario
|
||||||
renderVario();
|
renderVario();
|
||||||
@@ -998,7 +1012,7 @@ void loop()
|
|||||||
display.setTextColor(BLACK);
|
display.setTextColor(BLACK);
|
||||||
display.setCursor(0, 41);
|
display.setCursor(0, 41);
|
||||||
display.fillRect(0, 41, 84, 7, WHITE);
|
display.fillRect(0, 41, 84, 7, WHITE);
|
||||||
get_time1 = millis(); //stop the refresh rendering vario
|
resetTimer(get_time1); //stop the refresh rendering vario
|
||||||
display.print(F("R.A.Z. stat M"));
|
display.print(F("R.A.Z. stat M"));
|
||||||
display.print(conf.stat_index + 1);
|
display.print(conf.stat_index + 1);
|
||||||
display.display();
|
display.display();
|
||||||
@@ -1022,7 +1036,7 @@ void loop()
|
|||||||
}
|
}
|
||||||
if (stat.chrono_start != 0 && stat.chrono == 0) {
|
if (stat.chrono_start != 0 && stat.chrono == 0) {
|
||||||
// if altitude left in the same "zone" (2 meters) during 15 seconds, the timer is stopped
|
// if altitude left in the same "zone" (2 meters) during 15 seconds, the timer is stopped
|
||||||
if (altitude_temp - 1 < Altitude && altitude_temp + 1 > Altitude) {
|
if (altitude_temp - 1 <= Altitude && altitude_temp + 1 >= Altitude) {
|
||||||
chrono_cpt++;
|
chrono_cpt++;
|
||||||
if (chrono_cpt >= 15) {
|
if (chrono_cpt >= 15) {
|
||||||
DateTime now = rtc.now();
|
DateTime now = rtc.now();
|
||||||
@@ -1053,8 +1067,8 @@ void readButtons()
|
|||||||
if (newKnobPosition > knobPosition) { //Right
|
if (newKnobPosition > knobPosition) { //Right
|
||||||
if (!menuUsed && varioState == false) {
|
if (!menuUsed && varioState == false) {
|
||||||
if (menu.getCurrent().getShortkey() == MENU_STAT && stat_displayed < NB_STATS) {
|
if (menu.getCurrent().getShortkey() == MENU_STAT && stat_displayed < NB_STATS) {
|
||||||
get_time1 += 1000;
|
resetTimer(get_time1);
|
||||||
//stat_blink_status = true;
|
stat_blink_status = true;
|
||||||
stat_displayed++;
|
stat_displayed++;
|
||||||
renderMenu();
|
renderMenu();
|
||||||
}
|
}
|
||||||
@@ -1069,8 +1083,8 @@ void readButtons()
|
|||||||
else { //Left
|
else { //Left
|
||||||
if (!menuUsed && varioState == false) {
|
if (!menuUsed && varioState == false) {
|
||||||
if (menu.getCurrent().getShortkey() == MENU_STAT && stat_displayed > 1) {
|
if (menu.getCurrent().getShortkey() == MENU_STAT && stat_displayed > 1) {
|
||||||
get_time1 += 1000;
|
resetTimer(get_time1);
|
||||||
//stat_blink_status = true;
|
stat_blink_status = true;
|
||||||
stat_displayed--;
|
stat_displayed--;
|
||||||
renderMenu();
|
renderMenu();
|
||||||
}
|
}
|
||||||
@@ -1097,7 +1111,7 @@ void readButtons()
|
|||||||
}
|
}
|
||||||
// in vario, button enter init timer
|
// in vario, button enter init timer
|
||||||
else {
|
else {
|
||||||
get_time1 = millis();
|
resetTimer(get_time1);
|
||||||
is_vario_button_push = true;
|
is_vario_button_push = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user