2727
2828
2929// === voidapp ===============================================================
30- // The void app , doing nothing, allowing unhindered USB commands
31- // It is always registered (in init), but not part of switchnext()
30+ // The voidapp , doing nothing, allowing unhindered USB commands
31+ // It is always registered (in init), but hidden, ie not part of switchnext()
3232
3333
3434static aoresult_t aoapps_mngr_voidapp_start () {
@@ -48,7 +48,7 @@ static void aoapps_mngr_voidapp_stop () {
4848
4949void aoapps_mngr_voidapp_register () {
5050 aoapps_mngr_register (" voidapp" , " USB command" , " --" , " --" ,
51- 0 , /* no dither, no repair */
51+ AOAPPS_MNGR_FLAGS_HIDDEN,
5252 aoapps_mngr_voidapp_start, aoapps_mngr_voidapp_step, aoapps_mngr_voidapp_stop,
5353 0 , 0 /* no config command */ );
5454}
@@ -362,8 +362,8 @@ void aoapps_mngr_stop() {
362362 0 <= appix < aoapps_mngr_app_count()
363363 @note It is an error when the current app is "stop" (must be "run").
364364 @note See `aoapps_mngr_start()` for start/stop/current/appix terminology.
365- @note aoapps_mngr_switch(0) will select the voidapp; the function
366- aoapps_mngr_switchnext() skips the voidapp .
365+ @note ` aoapps_mngr_switch(0)` will select the voidapp like any other hidden
366+ app; the function ` aoapps_mngr_switchnext()` skips them .
367367 @note See `aoapps_mngr_switchnext()`.
368368*/
369369void aoapps_mngr_switch (int appix) {
@@ -374,13 +374,18 @@ void aoapps_mngr_switch(int appix) {
374374
375375/* !
376376 @brief Stops the current app and starts the next one.
377- @note The next one in the sense of appix (registration order).
378- @note Wraps around to appix 1 (so skips voidapp).
377+ @note The "next one" is in the sense of registration order.
378+ @note Wraps around, and skips apps that have their hidden flag set.
379+ @note If all apps are hidden does nothing (stays at app).
379380 @note It is an error when the current app is "stop" (must be "run").
380381 @note See `aoapps_mngr_start()` for start/stop/current/appix terminology.
381382*/
382383void aoapps_mngr_switchnext () {
383- aoapps_mngr_switch ( aoapps_mngr_appix % (aoapps_mngr_count-1 ) + 1 );
384+ int appix= aoapps_mngr_appix;
385+ do {
386+ appix= (appix+1 ) % aoapps_mngr_count;
387+ } while ( (aoapps_mngr_apps[appix].flags & AOAPPS_MNGR_FLAGS_HIDDEN) && (appix!=aoapps_mngr_appix) );
388+ if ( appix!=aoapps_mngr_appix ) aoapps_mngr_switch (appix);
384389}
385390
386391
@@ -476,7 +481,7 @@ static aoresult_t aoapps_mngr_stepwithtopo() {
476481 if ( aoapps_mngr_error!=aoresult_ok ) aoapps_mngr_state= AOAPPS_MNGR_STATE_ERROR;
477482 return aoresult_ok; // loop topo build
478483 }
479- Serial.printf (" %s: starting on %d RGBs\n " , aoapps_mngr_apps[aoapps_mngr_appix].name , aomw_topo_numtriplets () );
484+ // Serial.printf("%s: starting on %d RGBs\n", aoapps_mngr_apps[aoapps_mngr_appix].name, aomw_topo_numtriplets() );
480485 aoapps_mngr_error= aoapps_mngr_apps[aoapps_mngr_appix].start (); // call start of app
481486 if ( aoapps_mngr_error!=aoresult_ok ) aoapps_mngr_state= AOAPPS_MNGR_STATE_ERROR;
482487 aoapps_mngr_state= AOAPPS_MNGR_STATE_APPANIM;
@@ -555,12 +560,13 @@ static void aoapps_mngr_cmd_listone(int appix) {
555560 if ( appix!=cur ) mode= " stop" ;
556561 else if ( run ) mode= " run" ;
557562 else mode= " idle" ;
558- char flags[4 ]=" tre" ;
559- if ( aoapps_mngr_apps[appix].flags & AOAPPS_MNGR_FLAGS_WITHTOPO ) flags[0 ]=' T' ;
560- if ( aoapps_mngr_apps[appix].flags & AOAPPS_MNGR_FLAGS_WITHREPAIR ) flags[1 ]=' R' ;
561- if ( aoapps_mngr_apps[appix].flags & AOAPPS_MNGR_FLAGS_NEXTONERR ) flags[2 ]=' E' ;
563+ char flags[]=" htre" ;
564+ if ( aoapps_mngr_apps[appix].flags & AOAPPS_MNGR_FLAGS_HIDDEN ) flags[0 ]=' H' ;
565+ if ( aoapps_mngr_apps[appix].flags & AOAPPS_MNGR_FLAGS_WITHTOPO ) flags[1 ]=' T' ;
566+ if ( aoapps_mngr_apps[appix].flags & AOAPPS_MNGR_FLAGS_WITHREPAIR ) flags[2 ]=' R' ;
567+ if ( aoapps_mngr_apps[appix].flags & AOAPPS_MNGR_FLAGS_NEXTONERR ) flags[3 ]=' E' ;
562568 const char * oled= aoapps_mngr_app_oled (appix);
563- Serial.printf (" %d %-10s %-4s %-5s %s\n " ,appix,name,mode,flags,oled);
569+ Serial.printf (" %1d %-10s %-4s %-5s %s\n " ,appix,name,mode,flags,oled);
564570}
565571
566572
@@ -569,7 +575,7 @@ static void aoapps_mngr_cmd_listall(int verbose) {
569575 if ( verbose ) Serial.printf (" # %-10s %-4s %5s %s\n " ," name" ," mode" ," flags" ," display name" );
570576 for ( int appix=0 ; appix<aoapps_mngr_app_count (); appix++ )
571577 aoapps_mngr_cmd_listone (appix);
572- if ( verbose ) Serial.printf (" \n flags: T=withtopo R=withrepair, E=nextonerr\n " );
578+ if ( verbose ) Serial.printf (" \n flags: H=hidden T=withtopo R=withrepair, E=nextonerr\n " );
573579}
574580
575581
@@ -582,7 +588,7 @@ static void aoapps_mngr_cmd( int argc, char * argv[] ) {
582588 if ( argc!=2 ) { Serial.printf (" ERROR: too many args\n " ); return ; }
583589 aoapps_mngr_cmd_listall (argv[0 ][0 ]!=' @' );
584590 return ;
585- } else if ( aocmd_cint_isprefix (" switch" ,argv[1 ]) ) {
591+ } else if ( aocmd_cint_isprefix (" switch" ,argv[1 ]) || aocmd_cint_isprefix ( " hide " ,argv[ 1 ]) ) {
586592 if ( argc!=3 ) { Serial.printf (" ERROR: <app> missing\n " ); return ; }
587593 // <app> is number?
588594 int appix;
@@ -601,8 +607,15 @@ static void aoapps_mngr_cmd( int argc, char * argv[] ) {
601607 }
602608 }
603609 if ( appix==-1 ) { Serial.printf (" ERROR: no app with name starting with '%s'\n " ,argv[2 ] ); return ; }
604- aoapps_mngr_switch (appix);
605- if ( argv[0 ][0 ]!=' @' ) aoapps_mngr_cmd_listone (appix);
610+ if ( aocmd_cint_isprefix (" switch" ,argv[1 ]) ) {
611+ aoapps_mngr_switch (appix);
612+ if ( argv[0 ][0 ]!=' @' ) aoapps_mngr_cmd_listone (appix);
613+ } else if ( aocmd_cint_isprefix (" hide" ,argv[1 ]) ) {
614+ aoapps_mngr_apps[appix].flags ^= AOAPPS_MNGR_FLAGS_HIDDEN; // toggle hidden flag
615+ if ( argv[0 ][0 ]!=' @' ) aoapps_mngr_cmd_listone (appix);
616+ } else {
617+ AORESULT_ASSERT (false ); // can not happen
618+ }
606619 return ;
607620 } else if ( aocmd_cint_isprefix (" config" ,argv[1 ]) ) {
608621 aoapps_mngr_cmd_config (argc,argv);
@@ -621,6 +634,8 @@ static const char aoapps_mngr_cmd_longhelp[] =
621634 " - stops current app and starts <app>\n "
622635 " - <app> is either a name or an id (see list)\n "
623636 " - <app> 0 is the 'voidapp' (doing nothing): no interference with commands\n "
637+ " SYNTAX: apps hide <app>\n "
638+ " - toggles hide-flag of <app>; a hidden app is skipped in 'switchnext' list\n "
624639 " SYNTAX: apps config [...]\n "
625640 " - without arguments, shows which apps offer configuration\n "
626641 " - with app name shows help for configuration of that app\n "
@@ -630,6 +645,8 @@ static const char aoapps_mngr_cmd_longhelp[] =
630645;
631646
632647
648+
649+
633650/* !
634651 @brief Registers the "apps" command with the command interpreter.
635652 @return Number of remaining registration slots (or -1 if registration failed).
0 commit comments