diff --git a/open-led-race/olr-controller.c b/open-led-race/olr-controller.c index bb0dc4b..2cb4d2a 100644 --- a/open-led-race/olr-controller.c +++ b/open-led-race/olr-controller.c @@ -17,7 +17,7 @@ void controller_setup( void ) { digitalWrite(PIN_VCC_ADC2, HIGH); } ***/ - + DIGITAL_CTRL[CTRL_1]= DIG_CTRL_1_PIN; DIGITAL_CTRL[CTRL_2]= DIG_CTRL_2_PIN; DIGITAL_CTRL[CTRL_3]= DIG_CTRL_3_PIN; diff --git a/open-led-race/open-led-race.h b/open-led-race/open-led-race.h index 3f6e550..65b6a3a 100644 --- a/open-led-race/open-led-race.h +++ b/open-led-race/open-led-race.h @@ -45,9 +45,9 @@ enum phases { // Types for ack.type enum resp{ // - NOK = -1, + NOK = -1, NOTHING = 0, - OK = 1 + OLR_OK = 1 // Changed from OK to OLR_OK to avoid conflicts with ESP32 libs }; // Answer sent after processing a command received from Host diff --git a/open-led-race/open-led-race.ino b/open-led-race/open-led-race.ino index 7c3431d..80ec6e2 100644 --- a/open-led-race/open-led-race.ino +++ b/open-led-race/open-led-race.ino @@ -122,12 +122,13 @@ void setup() { // Check if DEMO mode is configured race.demo_mode = param_option_is_active(&tck.cfg, DEMO_MODE_OPTION); - enum ctr_type current_mode = (race.demo_mode == true) ? DEMO_MODE : DIGITAL_MODE; +// enum ctr_type current_mode = (race.demo_mode == true) ? DEMO_MODE : DIGITAL_MODE; // !!! Eliminare var current_mode ...mettere if contratto direttamente in f() call // Initialize Controllers for very player - set_controllers_mode(race.numcars, current_mode ) ; + //set_controllers_mode(race.numcars, current_mode ) ; + set_controllers_mode(race.numcars, (race.demo_mode == true) ? DEMO_MODE : DIGITAL_MODE ) ; // Initialize car for every player init_cars(race.numcars); @@ -371,8 +372,9 @@ void loop() { /** * */ -void set_controllers_mode(uint8_t numctrl, uint8_t mode ) { +void set_controllers_mode(uint8_t numctrl, enum ctr_type mode ) { for( uint8_t i = 0; i < numctrl; ++i) { + //enum ctr_type mode; controller_init( &switchs[i], mode, DIGITAL_CTRL[i] ); } } @@ -780,7 +782,7 @@ ack_t manageSerialCommand() { race.phase = CONFIG; enter_configuration_mode(); } - ack.rp = OK; + ack.rp = OLR_OK; } break; @@ -790,7 +792,7 @@ ack_t manageSerialCommand() { if(race.phase == CONFIG) { // Ignore command if Board is not in "Configure Mode" race.newcfg = true; } - ack.rp = OK; + ack.rp = OLR_OK; } break; @@ -803,12 +805,12 @@ ack_t manageSerialCommand() { // Does not accept anymore R=1 as Enter Configuration / Use command @ instead if( 0 > phase || RACE_PHASES <= phase || phase == CONFIG) return ack; race.phase = (enum phases) phase; - ack.rp = OK; + ack.rp = OLR_OK; **/ // Codice vecchio con R1=Enter Configuration if( 0 > phase || RACE_PHASES <= phase) return ack; race.phase = (enum phases) phase; - ack.rp = OK; + ack.rp = OLR_OK; if ( race.phase == CONFIG ) { // accept R1 as a EnterConfigurationMode command - DEPRECATED enter_configuration_mode(); } @@ -825,7 +827,7 @@ ack_t manageSerialCommand() { if( 0 >= ncar || race.numcars < ncar) return ack; cars[ncar-1].st = CAR_ENTER; cars[ncar-1].speed = (float) speed / 10; - ack.rp = OK; + ack.rp = OLR_OK; ack.rp = NOTHING; if( false ) { sprintf( txbuff, "%s %d, %s %d, %s %d", "CAR: ", ncar, "STATUS: ", cars[ncar-1].st, "SPEED: ", (int)(cars[ncar-1].speed * 10) ); @@ -840,7 +842,7 @@ ack_t manageSerialCommand() { byte const ncar = atoi( cmd + 1); if( 0 >= ncar || race.numcars < ncar) return ack; cars[ncar-1].st = CAR_COMING; - ack.rp = OK; + ack.rp = OLR_OK; if ( false ) { sprintf( txbuff, "%s %d, %s %d", "CAR: ", ncar, "STATUS: ", cars[ncar-1].st); printdebug( txbuff, LOG ); @@ -894,7 +896,7 @@ ack_t manageSerialCommand() { race.cfg.nrepeat = tck.cfg.race.nrepeat; race.cfg.finishline = tck.cfg.race.finishline; - ack.rp = OK; + ack.rp = OLR_OK; } break; @@ -912,7 +914,7 @@ ack_t manageSerialCommand() { track_configure( &tck, 0); if( err ) return ack; - ack.rp = OK; + ack.rp = OLR_OK; } break; @@ -934,7 +936,7 @@ ack_t manageSerialCommand() { int err = boxlen_configure( &tck, boxlen, boxperm ); if( err ) return ack; - ack.rp = OK; + ack.rp = OLR_OK; // Force Pitlane ON, so "show_cfgpars_onstrip()" // will show the new values, even if AlwaysON=false @@ -972,7 +974,7 @@ ack_t manageSerialCommand() { uint8_t err = ramp_configure( &tck, init, center, end, high, slopeperm ); if( err ) return ack; - ack.rp = OK; + ack.rp =OLR_OK; // Force Ramp ON, so "show_cfgpars_onstrip()" // will show the new values, even if AlwaysON=false @@ -1007,7 +1009,7 @@ ack_t manageSerialCommand() { uint8_t err = battery_configure( &tck, delta, min, boost, active ); if( err ) return ack; - ack.rp = OK; + ack.rp = OLR_OK; } break; @@ -1023,7 +1025,7 @@ ack_t manageSerialCommand() { uint8_t err = autostart_configure( &tck, autostart); if( err ) return ack; - ack.rp = OK; + ack.rp = OLR_OK; } break; @@ -1038,7 +1040,7 @@ ack_t manageSerialCommand() { uint8_t err = demo_configure( &tck, demo); if( err ) return ack; - ack.rp = OK; + ack.rp = OLR_OK; if(demo == 0) { race.demo_mode_off_received = true; @@ -1060,7 +1062,7 @@ ack_t manageSerialCommand() { uint8_t err = players_n_configure( &tck, players_n); if( err ) return ack; - ack.rp = OK; + ack.rp = OLR_OK; } break; @@ -1085,7 +1087,7 @@ ack_t manageSerialCommand() { int err = physic_configure( &tck, kgp, kfp ); if( err ) return ack; - ack.rp = OK; + ack.rp = OLR_OK; } break; @@ -1095,7 +1097,7 @@ ack_t manageSerialCommand() { uint8_t const dtunnel = atoi( cmd + 1); if( 0 >= dtunnel || 254 < dtunnel) return ack; race.circ.outtunnel = dtunnel; - ack.rp = OK; + ack.rp = OLR_OK; if ( false ) { //VERBOSE sprintf( txbuff, "%s %d", "TUNNEL: ", race.circ.outtunnel ); printdebug( txbuff, LOG ); @@ -1110,7 +1112,7 @@ ack_t manageSerialCommand() { param_setdefault( &tck.cfg ); EEPROM.put( eeadrInfo, tck.cfg ); // Save immediately - ack.rp = OK; + ack.rp = OLR_OK; // Update box/slope active in current Track Struct with values // just loaded (for show_cfgpars_onstrip()) @@ -1128,8 +1130,14 @@ ack_t manageSerialCommand() { ack.type = cmd[0]; if( strlen(cmd + 1) > LEN_UID ) return ack; strcpy( info->uid, cmd + 1 ); + + sprintf( txbuff, "%s%s%c", "$", cmd + 1, EOL ); + serialCommand.sendCommand(txbuff); + sprintf( txbuff, "%s%s%c", "$", info->uid, EOL ); + serialCommand.sendCommand(txbuff); + EEPROM.put( eeadrInfo, tck.cfg ); // Save immediately - ack.rp = OK; + ack.rp = OLR_OK; } break; @@ -1163,7 +1171,7 @@ ack_t manageSerialCommand() { race.network_race = true; race.phase = COMPLETE; // Immediatly ends the current race (if any) race.winner=0; // Set a fake winner (used in Status=Complete by draw_winner()) - ack.rp = OK; + ack.rp = OLR_OK; } break; @@ -1223,7 +1231,7 @@ ack_t manageSerialCommand() { { ack.type = cmd[0]; EEPROM.put( eeadrInfo, tck.cfg ); - ack.rp = OK; + ack.rp = OLR_OK; } break; @@ -1238,9 +1246,9 @@ ack_t manageSerialCommand() { */ void sendResponse( ack_t *ack) { if(ack->type=='\0'){ - sprintf(txbuff, "%s%c", ack->rp==OK? "OK":"NOK" , EOL ); + sprintf(txbuff, "%s%c", ack->rp==OLR_OK? "OK":"NOK" , EOL ); } else { - sprintf(txbuff, "%c%s%c", ack->type, ack->rp==OK? "OK":"NOK" , EOL ); + sprintf(txbuff, "%c%s%c", ack->type, ack->rp==OLR_OK? "OK":"NOK" , EOL ); } serialCommand.sendCommand(txbuff); }