Skip to content

Commit 37b1e22

Browse files
committed
Adding Pixel CLI visualization
- Uses ANSI Truecolor support (only supported in some modern terminal emulators) - Added color test to animation.py unit test - Adds CLI command and Python API command to invoke
1 parent ddf3318 commit 37b1e22

5 files changed

Lines changed: 132 additions & 22 deletions

File tree

Debug/cli/cli.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,24 @@
3333
// ----- Variables -----
3434

3535
// Basic command dictionary
36-
CLIDict_Entry( clear, "Clear the screen.");
37-
CLIDict_Entry( cliDebug, "Enables/Disables hex output of the most recent cli input." );
36+
CLIDict_Entry( clear, "Clear the screen.");
37+
CLIDict_Entry( cliDebug, "Enables/Disables hex output of the most recent cli input." );
38+
CLIDict_Entry( colorTest, "Displays a True Color ANSI test sequence to test terminal. If it displays in color, you're good." );
3839
#if defined(_host_)
39-
CLIDict_Entry( exit, "Host KLL Only - Exits cli." );
40+
CLIDict_Entry( exit, "Host KLL Only - Exits cli." );
4041
#endif
41-
CLIDict_Entry( help, "You're looking at it :P" );
42-
CLIDict_Entry( led, "Enables/Disables indicator LED. Try a couple times just in case the LED is in an odd state.\r\n\t\t\033[33mWarning\033[0m: May adversely affect some modules..." );
43-
CLIDict_Entry( reload, "Signals microcontroller to reflash/reload." );
44-
CLIDict_Entry( reset, "Resets the terminal back to initial settings." );
45-
CLIDict_Entry( restart, "Sends a software restart, should be similar to powering on the device." );
46-
CLIDict_Entry( tick, "Displays the fundamental tick size, and current ticks since last systick." );
47-
CLIDict_Entry( version, "Version information about this firmware." );
42+
CLIDict_Entry( help, "You're looking at it :P" );
43+
CLIDict_Entry( led, "Enables/Disables indicator LED. Try a couple times just in case the LED is in an odd state.\r\n\t\t\033[33mWarning\033[0m: May adversely affect some modules..." );
44+
CLIDict_Entry( reload, "Signals microcontroller to reflash/reload." );
45+
CLIDict_Entry( reset, "Resets the terminal back to initial settings." );
46+
CLIDict_Entry( restart, "Sends a software restart, should be similar to powering on the device." );
47+
CLIDict_Entry( tick, "Displays the fundamental tick size, and current ticks since last systick." );
48+
CLIDict_Entry( version, "Version information about this firmware." );
4849

4950
CLIDict_Def( basicCLIDict, "General Commands" ) = {
5051
CLIDict_Item( clear ),
5152
CLIDict_Item( cliDebug ),
53+
CLIDict_Item( colorTest ),
5254
#if defined(_host_)
5355
CLIDict_Item( exit ),
5456
#endif
@@ -510,6 +512,12 @@ void cliFunc_cliDebug( char* args )
510512
}
511513
}
512514

515+
void cliFunc_colorTest( char* args )
516+
{
517+
print( NL );
518+
print("\x1b[38;2;255;100;0mTRUECOLOR\x1b[0m");
519+
}
520+
513521
#if defined(_host_)
514522
void cliFunc_exit( char* args )
515523
{

Debug/cli/cli.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,15 @@ void CLI_saveHistory( char *buff );
118118
void CLI_retreiveHistory( int index );
119119

120120
// CLI Command Functions
121-
void cliFunc_clear ( char* args );
122-
void cliFunc_cliDebug( char* args );
123-
void cliFunc_exit ( char* args );
124-
void cliFunc_help ( char* args );
125-
void cliFunc_led ( char* args );
126-
void cliFunc_reload ( char* args );
127-
void cliFunc_reset ( char* args );
128-
void cliFunc_restart ( char* args );
129-
void cliFunc_tick ( char* args );
130-
void cliFunc_version ( char* args );
121+
void cliFunc_clear ( char* args );
122+
void cliFunc_cliDebug ( char* args );
123+
void cliFunc_colorTest( char* args );
124+
void cliFunc_exit ( char* args );
125+
void cliFunc_help ( char* args );
126+
void cliFunc_led ( char* args );
127+
void cliFunc_reload ( char* args );
128+
void cliFunc_reset ( char* args );
129+
void cliFunc_restart ( char* args );
130+
void cliFunc_tick ( char* args );
131+
void cliFunc_version ( char* args );
131132

Macro/PixelMap/pixel.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ void cliFunc_aniDel ( char* args );
3737
void cliFunc_chanTest ( char* args );
3838
void cliFunc_pixelList ( char* args );
3939
void cliFunc_pixelTest ( char* args );
40+
void cliFunc_rectDisp ( char* args );
4041

4142

4243

@@ -60,13 +61,15 @@ CLIDict_Entry( aniDel, "Remove the given stack index animation" );
6061
CLIDict_Entry( chanTest, "Channel test. No arg - next pixel. # - pixel, r - roll-through. a - all, s - stop" );
6162
CLIDict_Entry( pixelList, "Prints out pixel:channel mappings." );
6263
CLIDict_Entry( pixelTest, "Pixel test. No arg - next pixel. # - pixel, r - roll-through. a - all, s - stop" );
64+
CLIDict_Entry( rectDisp, "Show the current output of the MCU pixel buffer." );
6365

6466
CLIDict_Def( pixelCLIDict, "Pixel Module Commands" ) = {
6567
CLIDict_Item( aniAdd ),
6668
CLIDict_Item( aniDel ),
6769
CLIDict_Item( chanTest ),
6870
CLIDict_Item( pixelList ),
6971
CLIDict_Item( pixelTest ),
72+
CLIDict_Item( rectDisp ),
7073
{ 0, 0, 0 } // Null entry for dictionary end
7174
};
7275

@@ -1041,3 +1044,60 @@ void cliFunc_aniDel( char* args )
10411044
Pixel_AnimationStack.size--;
10421045
}
10431046

1047+
void Pixel_dispBuffer()
1048+
{
1049+
uint8_t row = 0;
1050+
uint8_t col = 0;
1051+
for ( uint16_t px = 0; px < Pixel_DisplayMapping_Cols * Pixel_DisplayMapping_Rows; px++ )
1052+
{
1053+
// Display a + if it's a blank pixel
1054+
if ( Pixel_DisplayMapping[px] == 0 )
1055+
{
1056+
print("+");
1057+
}
1058+
// Lookup pixel
1059+
else
1060+
{
1061+
// Determine number of channels
1062+
// TODO Adjust output if single channel
1063+
1064+
PixelElement *elem = (PixelElement*)&Pixel_Mapping[ Pixel_DisplayMapping[px] - 1 ];
1065+
1066+
// Lookup channel data
1067+
// TODO account for different channel size mappings
1068+
print("\033[48;2");
1069+
for ( uint8_t ch = 0; ch < elem->channels; ch++ )
1070+
{
1071+
print(";");
1072+
uint16_t ch_pos = elem->indices[ch];
1073+
PixelBuf *pixbuf = Pixel_bufferMap( ch_pos );
1074+
printInt8( PixelBuf16( pixbuf, ch_pos ) );
1075+
}
1076+
print("m");
1077+
print(" ");
1078+
print("\033[0m");
1079+
}
1080+
1081+
// Determine what to increment next
1082+
if ( col >= Pixel_DisplayMapping_Cols - 1 )
1083+
{
1084+
col = 0;
1085+
row++;
1086+
print(" ");
1087+
print(NL);
1088+
}
1089+
else
1090+
{
1091+
col++;
1092+
}
1093+
}
1094+
}
1095+
1096+
void cliFunc_rectDisp( char* args )
1097+
{
1098+
print( NL ); // No \r\n by default after the command is entered
1099+
1100+
// TODO move to own function, use this func to control startup/args
1101+
Pixel_dispBuffer();
1102+
}
1103+

Scan/TestIn/Tests/animation.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434
# Drop to cli, type exit in the displayed terminal to continue
3535
#i.control.cli()
3636

37+
print("-Pixel Test-")
38+
3739
# Read status of animation display buffers
38-
print( i.control.cmd('animationDisplayBuffers')() )
40+
#print( i.control.cmd('animationDisplayBuffers')() )
3941

4042
# Add Animation, index 0, to Stack
4143
i.control.cmd('addAnimation')()
@@ -51,6 +53,7 @@
5153
expecting = ((0, 33, 49), (30, 70, 120))
5254
print( "Expecting:", expecting, "Got:", i.control.cmd('readPixel')(0) )
5355
check( i.control.cmd('readPixel')(0) == expecting )
56+
i.control.cmd('rectDisp')()
5457

5558
# Update FrameState and Loop again
5659
i.control.cmd('setFrameState')(2)
@@ -60,6 +63,7 @@
6063
expecting = ((0, 33, 49), (0, 0, 0))
6164
print( "Expecting:", expecting, "Got:", i.control.cmd('readPixel')(0) )
6265
check( i.control.cmd('readPixel')(0) == expecting )
66+
i.control.cmd('rectDisp')()
6367

6468
# Update FrameState and Loop again
6569
i.control.cmd('setFrameState')(2)
@@ -69,17 +73,48 @@
6973
expecting = ((0, 33, 49), (60, 90, 140))
7074
print( "Expecting:", expecting, "Got:", i.control.cmd('readPixel')(0) )
7175
check( i.control.cmd('readPixel')(0) == expecting )
76+
i.control.cmd('rectDisp')()
7277

7378
# Update FrameState and Loop again to clear the stack
7479
i.control.cmd('setFrameState')(2)
7580
i.control.loop(1)
7681

7782
# Read status of animation display buffers
78-
print( i.control.cmd('animationDisplayBuffers')() )
83+
#print( i.control.cmd('animationDisplayBuffers')() )
7984

8085
# Read animation stack info
8186
print( "Expecting Stack Size: 0 Got:", i.control.cmd('animationStackInfo')().size )
8287
check( i.control.cmd('animationStackInfo')().size == 0 )
8388

89+
90+
##### Next Test #####
91+
92+
93+
print("-Rainbow Test-")
94+
# Add Animation, index 0, to Stack
95+
i.control.cmd('addAnimation')(index=1, pfunc=0)
96+
97+
# Read animation stack info
98+
print( "Expecting Stack Size: 1 Got:", i.control.cmd('animationStackInfo')().size )
99+
check( i.control.cmd('animationStackInfo')().size == 1 )
100+
101+
# Loop once
102+
i.control.cmd('setFrameState')(2)
103+
i.control.loop(1)
104+
105+
# Show output
106+
i.control.cmd('rectDisp')()
107+
108+
# Update FrameState and Loop again to clear the stack
109+
i.control.cmd('setFrameState')(2)
110+
i.control.loop(1)
111+
112+
# Read animation stack info
113+
print( "Expecting Stack Size: 0 Got:", i.control.cmd('animationStackInfo')().size )
114+
check( i.control.cmd('animationStackInfo')().size == 0 )
115+
116+
117+
##### Tests Complete #####
118+
84119
result()
85120

Scan/TestIn/host.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ class PixelElement( Structure ): pass
228228

229229
return tuple( output_ch ), tuple( read_value )
230230

231+
def rectDisp( self ):
232+
'''
233+
Show current MCU pixel buffer
234+
'''
235+
control.kiibohd.Pixel_dispBuffer()
236+
231237

232238
class Callbacks:
233239
'''

0 commit comments

Comments
 (0)