Skip to content

Commit

Permalink
Merge pull request #31 from simonttp78/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
simonttp78 authored Dec 29, 2021
2 parents 100dc78 + a89fe54 commit 3fcf76c
Show file tree
Hide file tree
Showing 12 changed files with 267 additions and 236 deletions.
14 changes: 9 additions & 5 deletions Firmware/include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.If not, see <http://www.gnu.org/licenses/>
// along with this program. If not, see <http://www.gnu.org/licenses/>

#ifdef ESP32
#define GET_MICROS esp_timer_get_time()
Expand All @@ -22,11 +22,15 @@
#ifndef GLOBALVAR_H
#define GLOBALVAR_H

#define FW_VER "0.9.01" // Flyball ETS firmware version

#define Simulate false // Set to true to enable race simulation (see Simulator.h/.cpp)
#define Accuracy2digits true // Change accuracy of displayed results from 0.001s to 0.01s except first dog if entry time in range from -0.095s to +0.095s
#define NumSimulatedRaces 25 // number of prepeared simulated races. Sererial interface command to change interface: e.g. "race 1"
//#define WiFiOFF // If defined all WiFi features are off: OTA, Web server. Please be carefull. Keep remote board/antenna away from ESP32 to avoid interferences.
#define WebUIonSDcard // When defined webserver data will be loaded from SC card (MMC 1 bit mode) and not taken compiled into fimrware package
#define Accuracy2digits true // Change accuracy of displayed results from 0.001s to 0.01s except first dog if entry time in range from -0.095s to +0.095s

#define WiFiON // If defined all WiFi features are on: OTA, Web server. Please be carefull. Keep remote receiver board (antenna) away from ESP32 to avoid interferences.
#define SDcardForcedDetect false// Forcing SD Card initialization even SDdetectPin state isn't LOW
//#define WebUIonSDcard // When defined webserver data will be loaded from SC card (MMC 1 bit mode) and not taken compiled into fimrware package. Precondition: SDcard defined too.
#define BatteryCalibration false// after setting to true LCD will display analog read value from battery pin (range 0-4095). This is handfull for battery volate curve definition (dPinVoltage)

#define LaserOutputTimer 60 // Laser output timer in seconds
Expand All @@ -38,7 +42,7 @@
#define SPI_FLASH_SEC_SIZE 4096 // Flash Sector Size declaration for ESP32 as it seems to become removed from embedded libraries

#define WS_TICKET_BUFFER_SIZE 5 // Number of websocket tickets kept in memory
#define WS_TIMEOUT 1800000 // Timeout for secured websocket
#define WS_TIMEOUT 180000 // Timeout for secured websocket in miliseconds

#define APP_VER "5.0.0"

Expand Down
7 changes: 4 additions & 3 deletions Firmware/lib/LCDController/LCDController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ void LCDControllerClass::init(LiquidCrystal *Clcd1, LiquidCrystal *Clcd2)
//Put initial text on screen
// 1 2 3
//LCD layout: 0123456789012345678901234567890123456789
_UpdateLCD(2, 0, String(" Flyball Electronic Training System "), 40);
_UpdateLCD(3, 0, String(" ver. 1.0.0 "), 40);
delay(3000);
_UpdateLCD(2, 0, String(" Flyball Electronic Training System "), 40);
_UpdateLCD(3, 0, String(" ver. rev.S "), 40);
_UpdateLCD(3, 17, String(FW_VER), 6);
delay(1500);
_UpdateLCD(1, 0, String("1: 0.000 + 0.000 | WELCOME "), 40);
_UpdateLCD(2, 0, String("2: 0.000 + 0.000 | Team: 0.000"), 40);
_UpdateLCD(3, 0, String("3: 0.000 + 0.000 | Net: 0.000"), 40);
Expand Down
94 changes: 36 additions & 58 deletions Firmware/lib/LightsController/LightsController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ void LightsControllerClass::init(NeoPixelBus<NeoRgbFeature, WS_METHOD> *LightsSt
/// </summary>
void LightsControllerClass::Main()
{
if (byOverallState == STARTING)
{
HandleStartSequence();
}

//Check if we have to toggle any lights
for (int i = 0; i < 6; i++)
{
Expand All @@ -78,71 +73,37 @@ void LightsControllerClass::Main()
{
//ESP_LOGD(__FILE__, " %llu: New light states: %i", GET_MICROS / 1000, _byNewLightsState);
_byCurrentLightsState = _byNewLightsState;
#ifndef WiFiOFF
#ifdef WiFiON
//Send data to websocket clients
WebHandler.SendLightsData(GetLightsState());
#endif
}
}

/// <summary>
/// Handles the start sequence, will be called by main function when oceral race state is
/// STARTING.
/// Initiate start sequence, should be called if starting lights sequence should be initiated.
/// </summary>
void LightsControllerClass::HandleStartSequence()
void LightsControllerClass::InitiateStartSequence()
{
//This function takes care of the starting lights sequence
//Check if the lights have been programmed yet
if (!_bStartSequenceStarted)
{
//Start sequence is not yet started, we need to schedule the lights on/off times

//Set schedule for RED light
_lLightsOnSchedule[1] = GET_MICROS / 1000; //Turn on NOW
_lLightsOutSchedule[1] = GET_MICROS / 1000 + 1000; //keep on for 1 second
//Set start sequence, we need to schedule the lights on/off times. Offset of 10ms instoruced to avoid RED light ON delay

//Set schedule for YELLOW1 light
_lLightsOnSchedule[2] = GET_MICROS / 1000 + 1000; //Turn on after 1 second
_lLightsOutSchedule[2] = GET_MICROS / 1000 + 2000; //Turn off after 2 seconds
//Set schedule for RED light
_lLightsOnSchedule[1] = (GET_MICROS + 10000) / 1000; //Turn on NOW
_lLightsOutSchedule[1] = (GET_MICROS + 10000) / 1000 + 1000; //keep on for 1 second

//Set schedule for YELLOW2 light
_lLightsOnSchedule[4] = GET_MICROS / 1000 + 2000; //Turn on after 2 seconds
_lLightsOutSchedule[4] = GET_MICROS / 1000 + 3000; //Turn off after 3 seconds
//Set schedule for YELLOW1 light
_lLightsOnSchedule[2] = (GET_MICROS + 10000) / 1000 + 1000; //Turn on after 1 second
_lLightsOutSchedule[2] = (GET_MICROS + 10000) / 1000 + 2000; //Turn off after 2 seconds

//Set schedule for GREEN light
_lLightsOnSchedule[5] = GET_MICROS / 1000 + 3000; //Turn on after 3 seconds
_lLightsOutSchedule[5] = GET_MICROS / 1000 + 4000; //Turn off after 4 seconds
//Set schedule for YELLOW2 light
_lLightsOnSchedule[4] = (GET_MICROS + 10000) / 1000 + 2000; //Turn on after 2 seconds
_lLightsOutSchedule[4] = (GET_MICROS + 10000) / 1000 + 3000; //Turn off after 3 seconds

_bStartSequenceStarted = true;
}
//Check if the start sequence is busy
bool bStartSequenceBusy = false;
for (int i = 0; i < 6; i++)
{
if (_lLightsOnSchedule[i] > 0 || _lLightsOutSchedule[i] > 0)
{
bStartSequenceBusy = true;
}
}
//Check if we should start the timer (GREEN light on)
if (CheckLightState(GREEN) == ON && RaceHandler.RaceState == RaceHandler.STARTING)
{
RaceHandler.StartTimers();
ESP_LOGD(__FILE__, "%llu: GREEN light is ON!", GET_MICROS / 1000);
}
if (!bStartSequenceBusy)
{
_bStartSequenceStarted = false;
byOverallState = STARTED;
}
}
//Set schedule for GREEN light
_lLightsOnSchedule[5] = (GET_MICROS + 10000) / 1000 + 3000; //Turn on after 3 seconds
_lLightsOutSchedule[5] = (GET_MICROS + 10000) / 1000 + 4000; //Turn off after 4 seconds

/// <summary>
/// Initiate start sequence, should be called if starting lights sequence should be initiated.
/// </summary>
void LightsControllerClass::InitiateStartSequence()
{
byOverallState = STARTING;
byOverallState = INITIATED;
}

/// <summary>
Expand Down Expand Up @@ -172,6 +133,9 @@ void LightsControllerClass::DeleteSchedules()
_lLightsOnSchedule[i] = 0; //Delete schedule
_lLightsOutSchedule[i] = 0; //Delete schedule
}
//Blink WHITE light to indicate manual STOP or RESET execution
_lLightsOnSchedule[0] = GET_MICROS / 1000; //Turn on NOW
_lLightsOutSchedule[0] = GET_MICROS / 1000 + 100; //keep on for 100ms
}

/// <summary>
Expand Down Expand Up @@ -201,16 +165,30 @@ void LightsControllerClass::ToggleLightState(Lights byLight, LightStates byLight
if (byLightState == OFF)
{
LightConfig.iColor = RgbColor(0);
ESP_LOGD(__FILE__, "%llu: Light %d is OFF", GET_MICROS / 1000, LightConfig.iPixelNumber);
//ESP_LOGD(__FILE__, "%llu: Light %d is OFF", GET_MICROS / 1000, LightConfig.iPixelNumber);
}
else
{
ESP_LOGD(__FILE__, "%llu: Light %d is ON", GET_MICROS / 1000, LightConfig.iPixelNumber);
//ESP_LOGD(__FILE__, "%llu: Light %d is ON", GET_MICROS / 1000, LightConfig.iPixelNumber);
// If start sequence is initiated and we're going to turn on RED light we need to start race timer
if (byOverallState == INITIATED && LightConfig.iPixelNumber == 1)
{
RaceHandler.StartRaceTimer();
byOverallState = STARTING;
}

// If start sequence is in progress and we're going to trun on GREEN light we need to change race state to RUNNING
if (byOverallState == STARTING && LightConfig.iPixelNumber == 4)
{
RaceHandler.ChangeRaceStateToRunning();
byOverallState = STARTED;
}
}

for (int lightschain = 0; lightschain < LIGHTSCHAINS; lightschain++)
{
_LightsStrip->SetPixelColor(LightConfig.iPixelNumber + 5 * lightschain, LightConfig.iColor);
ESP_LOGD(__FILE__, "%llu: Light %d is now %d", GET_MICROS / 1000, LightConfig.iPixelNumber, byLightState);
}

if (byCurrentLightState != byLightState)
Expand Down
1 change: 1 addition & 0 deletions Firmware/lib/LightsController/LightsController.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class LightsControllerClass
//Overal state of this class
enum OverallStates
{
INITIATED,
RESET,
STARTING,
STARTED
Expand Down
Loading

0 comments on commit 3fcf76c

Please sign in to comment.