From f80e48d35689ca8f770c0d38a67d3e1c49223fa8 Mon Sep 17 00:00:00 2001 From: uniquealt Date: Sat, 21 Apr 2018 17:26:18 -0700 Subject: [PATCH] Analog power bar & more responsive UI. I've already sent these patches to the tubomyevic fork, but upstream may find them useful. When the Interface > PwBar option is enabled, this replaces the "PWR" label with an analog power gauge, animated at 50Hz. Always call DrawScreen() at 10Hz, reducing the maximum fire button lag from 500ms to 100ms. TC modes still refresh the screen at 2Hz, but this occurs at FireDuration=(1, 6, 11, ...) instead of following the global 2Hz clock. --- inc/dataflash.h | 1 + inc/miscs.h | 2 ++ inc/myevic.h | 2 ++ inc/screens.h | 1 + src/eh.c | 1 + src/main.c | 19 +++++++----------- src/mainview.c | 17 ++++++++++++---- src/menus.c | 16 ++++++++++++++- src/miscs.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ src/screens.c | 16 +++++++-------- src/strings.c | 1 + 11 files changed, 103 insertions(+), 26 deletions(-) diff --git a/inc/dataflash.h b/inc/dataflash.h index aeb650a7..c21980c8 100644 --- a/inc/dataflash.h +++ b/inc/dataflash.h @@ -83,6 +83,7 @@ typedef struct /* 04000000 */ unsigned int chkmodeoff:1; /* 08000000 */ unsigned int dfmt2:1; /* 10000000 */ unsigned int pcurve:1; +/* 20000000 */ unsigned int pwrbar:1; // Do not exceed 32 bits; // if you may do so, create another bitfield. diff --git a/inc/miscs.h b/inc/miscs.h index 5e75b1d7..c89f9644 100644 --- a/inc/miscs.h +++ b/inc/miscs.h @@ -36,6 +36,8 @@ extern void qix_diddle(int16_t *ptr ); extern void Snow( int ); +extern void AnimPwrBar( int ); + extern uint8_t LEDRed; extern uint8_t LEDGreen; extern uint8_t LEDBlue; diff --git a/inc/myevic.h b/inc/myevic.h index 1f370087..fb997f25 100644 --- a/inc/myevic.h +++ b/inc/myevic.h @@ -150,6 +150,8 @@ typedef struct /* 00200000 */ int fading:1; /* 00400000 */ int led_on:1; /* 00800000 */ int splash:1; + +/* 01000000 */ int animpwrbar:1; } gFlags_t; diff --git a/inc/screens.h b/inc/screens.h index 7d168d54..3fd115c1 100644 --- a/inc/screens.h +++ b/inc/screens.h @@ -228,6 +228,7 @@ extern const uint8_t String_4[]; extern const uint8_t String_OnOff[]; extern const uint8_t String_ModePlus[]; extern const uint8_t String_PPwr[]; +extern const uint8_t String_PwrBar[]; extern const uint8_t String_Clicks[]; extern const uint8_t String_BAT[]; extern const uint8_t String_GEN[]; diff --git a/src/eh.c b/src/eh.c index 3c1d89af..f9e9b80c 100644 --- a/src/eh.c +++ b/src/eh.c @@ -723,6 +723,7 @@ __myevic__ void EventHandler() if ( !gFlags.firing || LastInputs != 1 ) StopFire(); gFlags.refresh_display = 1; + gFlags.animpwrbar = 0; // Screen 2 may decide to set this. Screen = 2; ScreenDuration = 1; return; diff --git a/src/main.c b/src/main.c index f0ca9161..7ffc07c2 100644 --- a/src/main.c +++ b/src/main.c @@ -924,6 +924,11 @@ __myevic__ void Main() anim3d( 0 ); } + if ( Screen == 2 && gFlags.animpwrbar ) + { + AnimPwrBar( 0 ); + } + if ( Screen == 60 ) { AnimateScreenSaver(); @@ -994,10 +999,7 @@ __myevic__ void Main() if ( ShowProfNum ) --ShowProfNum; - if ( !( gFlags.firing && ISMODETC(dfMode) ) ) - { - DrawScreen(); - } + DrawScreen(); if ( KeyTicks < 5 ) { @@ -1056,14 +1058,7 @@ __myevic__ void Main() gFlags.osc_1hz ^= 1; - if ( gFlags.firing ) - { - if ( ISMODETC(dfMode) ) - { - DrawScreen(); - } - } - else + if ( !gFlags.firing ) { if ( !dfStatus.off diff --git a/src/mainview.c b/src/mainview.c index d69d831e..6217a8dc 100644 --- a/src/mainview.c +++ b/src/mainview.c @@ -107,12 +107,21 @@ __myevic__ void DrawMode() //============================================================================= -__myevic__ void DrawPwrLine( int pwr, int line ) +__myevic__ void DrawPwrLine( int pwr, int drawbar, int line ) { if ( BLINKITEM(2) && PD2 && PD3 ) return; - DrawString( String_PWR_s, 0, line+2 ); + if ( drawbar ) + { + // Note: this always draws on line 52. + AnimPwrBar( 1 ); + gFlags.animpwrbar = 1; + } + else + { + DrawString( String_PWR_s, 0, line+2 ); + } if ( pwr < 1000 ) { @@ -393,7 +402,7 @@ __myevic__ void DrawInfoLines() } else { - DrawPwrLine( AtoPower( AtoVolts ), 52 ); + DrawPwrLine( AtoPower( AtoVolts ), dfStatus.pwrbar, 52 ); } break; case 4: @@ -420,7 +429,7 @@ __myevic__ void DrawInfoLines() } else { - DrawPwrLine( dfTCPower, 52 ); + DrawPwrLine( dfTCPower, 0, 52 ); } break; case 4: diff --git a/src/menus.c b/src/menus.c index e3eac027..135a7f71 100644 --- a/src/menus.c +++ b/src/menus.c @@ -492,6 +492,15 @@ __myevic__ void IFMenuIDraw( int it, int line, int sel ) DrawString( dfStatus.priopwr ? String_On : String_Off, 44, line+2 ); break; + case 6: // PwrBar + if ( dfStatus.priopwr ) { + // PwrBar doesn't work in PPwr mode; draw a lock icon. + DrawImage( 44, line+2, 0xC3 ); + } else { + DrawString( dfStatus.pwrbar ? String_On : String_Off, 44, line+2 ); + } + break; + default: break; } @@ -555,6 +564,10 @@ __myevic__ void IFMenuOnClick() dfStatus.priopwr ^= 1; break; + case 6: // PwrBar + if ( !dfStatus.priopwr ) dfStatus.pwrbar ^= 1; + break; + default: // Exit UpdateDataFlash(); return; @@ -2085,7 +2098,7 @@ const menu_t IFMenu = 0, IFMenuOnClick+1, 0, - 8, + 9, { { String_1Watt, 0, 0, 0 }, { String_1C5F, 0, 0, 0 }, @@ -2093,6 +2106,7 @@ const menu_t IFMenu = { String_Font, 0, 0, 0 }, { String_Temp, 0, 0, 0 }, { String_PPwr, 0, 0, 0 }, + { String_PwrBar, 0, 0, 0 }, { String_Clicks, &ClicksMenu, 0, MACTION_SUBMENU }, { String_Back, 0, EVENT_PARENT_MENU, 0 } } diff --git a/src/miscs.c b/src/miscs.c index baa0b734..4e071e36 100644 --- a/src/miscs.c +++ b/src/miscs.c @@ -789,6 +789,59 @@ __myevic__ void Snow( int redraw ) } } +//========================================================================= +// Analog Power Bar +// +// When PwBar is enabled, the firing screen calls this (with first=1) +// instead of drawing the "PWR" label. It will also set animpwrbar=1, +// to request updates (with first=0) at 100 Hz. +// +// It's important to clear animpwrbar before switching to Screen 2, +// so that updates only occur under the expected constraints. +//------------------------------------------------------------------------- + +__myevic__ void AnimPwrBar( int first ) +{ + static const int LINE = 52; + static const int WIDTH = 24; + if ( first ) { + // Draw the tick marks. + for ( int x = 0; x <= WIDTH; x += 3 ) { + int h; + if ( x == 0 ) { + h = 2; + } else if ( x % 12 == 0 ) { + h = 1; + } else { + h = 0; + } + DrawVLine( x, LINE, LINE+h, 1 ); + DrawVLine( x, LINE+9, LINE+9-h, 1 ); + } + } else { + // Animate subsequent frames at 50 Hz. + static uint8_t tscaler = 0; + if ( ++tscaler < 2 ) return; + tscaler = 0; + } + + // Zero the bar when not firing, because Screen 2 remains visible + // for ~1 second after firing stops. + const int pwr = gFlags.firing ? AtoPower( AtoVolts ) : 0; + const int pwrmax = dfTCPower; + + int bar = ( pwr * WIDTH / pwrmax ); + if ( bar < 0 ) bar = 0; + if ( bar > WIDTH ) bar = WIDTH; + + DrawFillRect( 0, LINE+3, WIDTH, LINE+6, 0 ); + DrawFillRect( 0, LINE+3, bar, LINE+6, 1 ); + + if ( !first ) { + DisplayRefresh(); + } +} + //========================================================================= // LED Stuff diff --git a/src/screens.c b/src/screens.c index 5cc74f90..2b2a08e1 100644 --- a/src/screens.c +++ b/src/screens.c @@ -38,8 +38,7 @@ void SetScreen( int screen, int duration ) //========================================================================= -// Called at a frequency of 10Hz except when firing in TC modes. -// Called at a frequency of 2Hz when firing in TC modes. +// Called at a frequency of 10Hz __myevic__ void DrawScreen() { @@ -51,7 +50,11 @@ __myevic__ void DrawScreen() CurrentFD = FireDuration; ScreenDuration = ISMODETC(dfMode) ? 1 : 3; TenthOfSecs = 0; - gFlags.refresh_display = 1; + // Refresh at 2Hz in TC mode, or 10Hz otherwise. + if ( !ISMODETC(dfMode) || FireDuration % 5 == 1 ) + { + gFlags.refresh_display = 1; + } } else if ( ScreenRefreshTimer && !--ScreenRefreshTimer ) { @@ -221,12 +224,7 @@ __myevic__ void DrawScreen() gFlags.fading = 0; } - if (( gFlags.firing ) && ISMODETC(dfMode)) - TenthOfSecs += 5; - else - TenthOfSecs += 1; - - if ( TenthOfSecs < 10 ) + if ( ++TenthOfSecs < 10 ) return; TenthOfSecs = 0; diff --git a/src/strings.c b/src/strings.c index 471735f5..b9aaafc8 100644 --- a/src/strings.c +++ b/src/strings.c @@ -116,6 +116,7 @@ __string__ String_OnOff [] = { 0xAA, 0x8F, 0xD6, 0xBD, 0xAA, 0x87, 0x87, 0 }; __string__ String_ModePlus [] = { 0xA8, 0x90, 0x85, 0x86, 0xBD, 0xD4, 0xD4, 0 }; __string__ String_Clicks [] = { 0x9E, 0x8D, 0x8A, 0x84, 0x8C, 0x94, 0 }; __string__ String_PPwr [] = { 0xAB, 0xAB, 0x98, 0x93, 0 }; +__string__ String_PwrBar [] = { 0xAB, 0x98, 0x9D, 0x82, 0x93, 0 }; // "PwBar" __string__ String_BAT [] = { 0x9D, 0x9C, 0xAF, 0 }; __string__ String_GEN [] = { 0xA2, 0xA0, 0xA9, 0 }; __string__ String_25R [] = { 0x0D, 0x10, 0xAD, 0 };