Optimizations

improve stats rendering and cumulative altitude
This commit is contained in:
sinseman 2015-03-16 15:35:00 +01:00
parent 3ac4306346
commit 299e6c9f6d

View File

@ -45,7 +45,7 @@ bool menuUsed = false;
bool menuUsed_last = false;
bool varioState = false;
uint8_t stat_displayed = 1;
//bool stat_blink_status = false;
bool stat_blink_status = false;
#define MENU_RIGHT 0
#define MENU_LEFT 1
@ -218,6 +218,10 @@ void playConfirmMelody()
}
}
void resetTimer(unsigned long &timer)
{
timer = millis();
}
void renderChrono(Stat value = stat)
{
@ -240,6 +244,7 @@ void renderVario()
{
if (true == varioState) {
DateTime now = rtc.now();
display.clearDisplay();
//ALtitude
@ -250,7 +255,6 @@ void renderVario()
display.print(F("m"));
//Time
DateTime now = rtc.now();
display.setCursor(55, 0);
renderZero(now.hour());
display.print(now.hour());
@ -327,7 +331,7 @@ void renderVolume(bool volume)
conf.volume = volume;
push_write_eeprom = 0;
get_time1 = millis(); //stop the refresh rendering vario
resetTimer(get_time1); //stop the refresh rendering vario
display.println(F("Sons:"));
(false == conf.volume) ? display.print(F("Off")) : display.print(F("On"));
@ -656,20 +660,23 @@ void renderMenu(MenuItem newMenuItem = menu.getCurrent(), uint8_t dir = 2)
}
else {
//if (stat_blink_status) {
if (!stat_blink_status) {
display.setTextColor(BLACK);
renderDateTime(DateTime(stat_to_display.chrono_start));
}
else {
display.print(F("M"));
display.print(stat_displayed);
display.setTextColor(BLACK);
}
stat_blink_status = !stat_blink_status;
display.println();
//}
//else {
display.print(F("Chrono:"));
renderChrono(stat_to_display);
display.println();
//}
//stat_blink_status = !stat_blink_status;
display.print(F("Alt max:"));
renderStatItem(stat_to_display.alti_max, F("m"), true);
display.println();
@ -853,11 +860,11 @@ void resetAltitudeSensor()
*/
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) {
@ -867,7 +874,7 @@ void makeBeeps()
//beep even if vario has negative value but vario is climbing
float variation = (vario < varioClimbRateStart && vario_diff >= varioClimbRateStart && varioClimbRateStart != 0) ? vario_diff : vario;
if (timeNoPauseBeep <= 30){
if (timeNoPauseBeep <= 40) {
timeNoPauseBeep++;
beepLatency = 150;
}
@ -929,17 +936,20 @@ void setup()
void loop()
{
float tempo = micros();
readButtons();
updateAltitude();
float tempo = micros();
/* TEST BLOC */
//Altitude = alt + 0.05;
// 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 */
/*
vario = vario + 0.01;
vario = vario + 0.005;
if (vario > 4)
vario = 0;
*/
@ -948,7 +958,7 @@ void loop()
if (stat.chrono_start != 0) {
if (vario > 0)
stat.cumul_alt += vario * (1000 /(tempo - tim));
stat.cumul_alt += Altitude - alt;
if (Altitude > stat.alti_max)
stat.alti_max = Altitude;
@ -971,7 +981,11 @@ void loop()
//every second
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
renderVario();
@ -998,7 +1012,7 @@ void loop()
display.setTextColor(BLACK);
display.setCursor(0, 41);
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(conf.stat_index + 1);
display.display();
@ -1022,7 +1036,7 @@ void loop()
}
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_temp - 1 < Altitude && altitude_temp + 1 > Altitude) {
if (altitude_temp - 1 <= Altitude && altitude_temp + 1 >= Altitude) {
chrono_cpt++;
if (chrono_cpt >= 15) {
DateTime now = rtc.now();
@ -1053,8 +1067,8 @@ void readButtons()
if (newKnobPosition > knobPosition) { //Right
if (!menuUsed && varioState == false) {
if (menu.getCurrent().getShortkey() == MENU_STAT && stat_displayed < NB_STATS) {
get_time1 += 1000;
//stat_blink_status = true;
resetTimer(get_time1);
stat_blink_status = true;
stat_displayed++;
renderMenu();
}
@ -1069,8 +1083,8 @@ void readButtons()
else { //Left
if (!menuUsed && varioState == false) {
if (menu.getCurrent().getShortkey() == MENU_STAT && stat_displayed > 1) {
get_time1 += 1000;
//stat_blink_status = true;
resetTimer(get_time1);
stat_blink_status = true;
stat_displayed--;
renderMenu();
}
@ -1097,7 +1111,7 @@ void readButtons()
}
// in vario, button enter init timer
else {
get_time1 = millis();
resetTimer(get_time1);
is_vario_button_push = true;
}
}