Skip to content

Commit f80e48d

Browse files
committed
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.
1 parent b8e6f84 commit f80e48d

File tree

11 files changed

+103
-26
lines changed

11 files changed

+103
-26
lines changed

inc/dataflash.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ typedef struct
8383
/* 04000000 */ unsigned int chkmodeoff:1;
8484
/* 08000000 */ unsigned int dfmt2:1;
8585
/* 10000000 */ unsigned int pcurve:1;
86+
/* 20000000 */ unsigned int pwrbar:1;
8687

8788
// Do not exceed 32 bits;
8889
// if you may do so, create another bitfield.

inc/miscs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ extern void qix_diddle(int16_t *ptr );
3636

3737
extern void Snow( int );
3838

39+
extern void AnimPwrBar( int );
40+
3941
extern uint8_t LEDRed;
4042
extern uint8_t LEDGreen;
4143
extern uint8_t LEDBlue;

inc/myevic.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ typedef struct
150150
/* 00200000 */ int fading:1;
151151
/* 00400000 */ int led_on:1;
152152
/* 00800000 */ int splash:1;
153+
154+
/* 01000000 */ int animpwrbar:1;
153155
}
154156

155157
gFlags_t;

inc/screens.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ extern const uint8_t String_4[];
228228
extern const uint8_t String_OnOff[];
229229
extern const uint8_t String_ModePlus[];
230230
extern const uint8_t String_PPwr[];
231+
extern const uint8_t String_PwrBar[];
231232
extern const uint8_t String_Clicks[];
232233
extern const uint8_t String_BAT[];
233234
extern const uint8_t String_GEN[];

src/eh.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,7 @@ __myevic__ void EventHandler()
723723
if ( !gFlags.firing || LastInputs != 1 )
724724
StopFire();
725725
gFlags.refresh_display = 1;
726+
gFlags.animpwrbar = 0; // Screen 2 may decide to set this.
726727
Screen = 2;
727728
ScreenDuration = 1;
728729
return;

src/main.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,11 @@ __myevic__ void Main()
924924
anim3d( 0 );
925925
}
926926

927+
if ( Screen == 2 && gFlags.animpwrbar )
928+
{
929+
AnimPwrBar( 0 );
930+
}
931+
927932
if ( Screen == 60 )
928933
{
929934
AnimateScreenSaver();
@@ -994,10 +999,7 @@ __myevic__ void Main()
994999
if ( ShowProfNum )
9951000
--ShowProfNum;
9961001

997-
if ( !( gFlags.firing && ISMODETC(dfMode) ) )
998-
{
999-
DrawScreen();
1000-
}
1002+
DrawScreen();
10011003

10021004
if ( KeyTicks < 5 )
10031005
{
@@ -1056,14 +1058,7 @@ __myevic__ void Main()
10561058

10571059
gFlags.osc_1hz ^= 1;
10581060

1059-
if ( gFlags.firing )
1060-
{
1061-
if ( ISMODETC(dfMode) )
1062-
{
1063-
DrawScreen();
1064-
}
1065-
}
1066-
else
1061+
if ( !gFlags.firing )
10671062
{
10681063
if
10691064
( !dfStatus.off

src/mainview.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,21 @@ __myevic__ void DrawMode()
107107

108108
//=============================================================================
109109

110-
__myevic__ void DrawPwrLine( int pwr, int line )
110+
__myevic__ void DrawPwrLine( int pwr, int drawbar, int line )
111111
{
112112
if ( BLINKITEM(2) && PD2 && PD3 )
113113
return;
114114

115-
DrawString( String_PWR_s, 0, line+2 );
115+
if ( drawbar )
116+
{
117+
// Note: this always draws on line 52.
118+
AnimPwrBar( 1 );
119+
gFlags.animpwrbar = 1;
120+
}
121+
else
122+
{
123+
DrawString( String_PWR_s, 0, line+2 );
124+
}
116125

117126
if ( pwr < 1000 )
118127
{
@@ -393,7 +402,7 @@ __myevic__ void DrawInfoLines()
393402
}
394403
else
395404
{
396-
DrawPwrLine( AtoPower( AtoVolts ), 52 );
405+
DrawPwrLine( AtoPower( AtoVolts ), dfStatus.pwrbar, 52 );
397406
}
398407
break;
399408
case 4:
@@ -420,7 +429,7 @@ __myevic__ void DrawInfoLines()
420429
}
421430
else
422431
{
423-
DrawPwrLine( dfTCPower, 52 );
432+
DrawPwrLine( dfTCPower, 0, 52 );
424433
}
425434
break;
426435
case 4:

src/menus.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,15 @@ __myevic__ void IFMenuIDraw( int it, int line, int sel )
492492
DrawString( dfStatus.priopwr ? String_On : String_Off, 44, line+2 );
493493
break;
494494

495+
case 6: // PwrBar
496+
if ( dfStatus.priopwr ) {
497+
// PwrBar doesn't work in PPwr mode; draw a lock icon.
498+
DrawImage( 44, line+2, 0xC3 );
499+
} else {
500+
DrawString( dfStatus.pwrbar ? String_On : String_Off, 44, line+2 );
501+
}
502+
break;
503+
495504
default:
496505
break;
497506
}
@@ -555,6 +564,10 @@ __myevic__ void IFMenuOnClick()
555564
dfStatus.priopwr ^= 1;
556565
break;
557566

567+
case 6: // PwrBar
568+
if ( !dfStatus.priopwr ) dfStatus.pwrbar ^= 1;
569+
break;
570+
558571
default: // Exit
559572
UpdateDataFlash();
560573
return;
@@ -2085,14 +2098,15 @@ const menu_t IFMenu =
20852098
0,
20862099
IFMenuOnClick+1,
20872100
0,
2088-
8,
2101+
9,
20892102
{
20902103
{ String_1Watt, 0, 0, 0 },
20912104
{ String_1C5F, 0, 0, 0 },
20922105
{ String_WakeMP, 0, 0, 0 },
20932106
{ String_Font, 0, 0, 0 },
20942107
{ String_Temp, 0, 0, 0 },
20952108
{ String_PPwr, 0, 0, 0 },
2109+
{ String_PwrBar, 0, 0, 0 },
20962110
{ String_Clicks, &ClicksMenu, 0, MACTION_SUBMENU },
20972111
{ String_Back, 0, EVENT_PARENT_MENU, 0 }
20982112
}

src/miscs.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,59 @@ __myevic__ void Snow( int redraw )
789789
}
790790
}
791791

792+
//=========================================================================
793+
// Analog Power Bar
794+
//
795+
// When PwBar is enabled, the firing screen calls this (with first=1)
796+
// instead of drawing the "PWR" label. It will also set animpwrbar=1,
797+
// to request updates (with first=0) at 100 Hz.
798+
//
799+
// It's important to clear animpwrbar before switching to Screen 2,
800+
// so that updates only occur under the expected constraints.
801+
//-------------------------------------------------------------------------
802+
803+
__myevic__ void AnimPwrBar( int first )
804+
{
805+
static const int LINE = 52;
806+
static const int WIDTH = 24;
807+
if ( first ) {
808+
// Draw the tick marks.
809+
for ( int x = 0; x <= WIDTH; x += 3 ) {
810+
int h;
811+
if ( x == 0 ) {
812+
h = 2;
813+
} else if ( x % 12 == 0 ) {
814+
h = 1;
815+
} else {
816+
h = 0;
817+
}
818+
DrawVLine( x, LINE, LINE+h, 1 );
819+
DrawVLine( x, LINE+9, LINE+9-h, 1 );
820+
}
821+
} else {
822+
// Animate subsequent frames at 50 Hz.
823+
static uint8_t tscaler = 0;
824+
if ( ++tscaler < 2 ) return;
825+
tscaler = 0;
826+
}
827+
828+
// Zero the bar when not firing, because Screen 2 remains visible
829+
// for ~1 second after firing stops.
830+
const int pwr = gFlags.firing ? AtoPower( AtoVolts ) : 0;
831+
const int pwrmax = dfTCPower;
832+
833+
int bar = ( pwr * WIDTH / pwrmax );
834+
if ( bar < 0 ) bar = 0;
835+
if ( bar > WIDTH ) bar = WIDTH;
836+
837+
DrawFillRect( 0, LINE+3, WIDTH, LINE+6, 0 );
838+
DrawFillRect( 0, LINE+3, bar, LINE+6, 1 );
839+
840+
if ( !first ) {
841+
DisplayRefresh();
842+
}
843+
}
844+
792845

793846
//=========================================================================
794847
// LED Stuff

src/screens.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ void SetScreen( int screen, int duration )
3838

3939

4040
//=========================================================================
41-
// Called at a frequency of 10Hz except when firing in TC modes.
42-
// Called at a frequency of 2Hz when firing in TC modes.
41+
// Called at a frequency of 10Hz
4342

4443
__myevic__ void DrawScreen()
4544
{
@@ -51,7 +50,11 @@ __myevic__ void DrawScreen()
5150
CurrentFD = FireDuration;
5251
ScreenDuration = ISMODETC(dfMode) ? 1 : 3;
5352
TenthOfSecs = 0;
54-
gFlags.refresh_display = 1;
53+
// Refresh at 2Hz in TC mode, or 10Hz otherwise.
54+
if ( !ISMODETC(dfMode) || FireDuration % 5 == 1 )
55+
{
56+
gFlags.refresh_display = 1;
57+
}
5558
}
5659
else if ( ScreenRefreshTimer && !--ScreenRefreshTimer )
5760
{
@@ -221,12 +224,7 @@ __myevic__ void DrawScreen()
221224
gFlags.fading = 0;
222225
}
223226

224-
if (( gFlags.firing ) && ISMODETC(dfMode))
225-
TenthOfSecs += 5;
226-
else
227-
TenthOfSecs += 1;
228-
229-
if ( TenthOfSecs < 10 )
227+
if ( ++TenthOfSecs < 10 )
230228
return;
231229

232230
TenthOfSecs = 0;

0 commit comments

Comments
 (0)