Skip to content

Commit

Permalink
Merge branch 'release/v1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
vyruz1986 committed Aug 22, 2017
2 parents e4d3d0a + b7504d6 commit 5aa3a9f
Show file tree
Hide file tree
Showing 15 changed files with 276 additions and 131 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,5 @@ ModelManifest.xml
FlyballETS-Software.vcxproj.filters

#VisualMicro files
Visual Micro/
Visual Micro/
__vm/
2 changes: 1 addition & 1 deletion BatterySensor.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// file: BatterySensor.cpp
//
// summary: Implements the battery sensor class
// Copyright (C) 2015 Alex Goris
// Copyright (C) 2017 Alex Goris
// This file is part of FlyballETS-Software
// FlyballETS-Software is free software : you can redistribute it and / or modify
// it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion BatterySensor.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// BatterySensor.h
// Copyright (C) 2015 Alex Goris
// Copyright (C) 2017 Alex Goris
// This file is part of FlyballETS-Software
// FlyballETS-Software is free software : you can redistribute it and / or modify
// it under the terms of the GNU General Public License as published by
Expand Down
130 changes: 84 additions & 46 deletions FlyballETS-Software.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// Pro Mini which controls all components in the Flyball ETS These sources are originally
// distributed from: https://github.com/vyruz1986/FlyballETS-Software.
//
// Copyright (C) 2015 Alex Goris
// Copyright (C) 2017 Alex Goris
// This file is part of FlyballETS-Software
// FlyballETS-Software is free software : you can redistribute it and / or modify it under the terms of
// the GNU General Public License as published by the Free Software Foundation, either version 3 of
Expand All @@ -21,6 +21,7 @@
//
// You should have received a copy of the GNU General Public License along with this program.If not,
// see <http://www.gnu.org/licenses/>
#include "config.h"
#include "StreamPrint.h"
#include "LCDController.h"
#include "RaceHandler.h"
Expand All @@ -39,12 +40,12 @@
- D5: LCD Data6
- D6: LCD Data5
- D7: LCD Data4
- D8: Lights 74HC595 clock pin
- D9: Lights 74HC595 data pin
- D8: WS2811B lights data pin / Lights 74HC595 clock pin
- D9: <free> / Lights 74HC595 data pin
- D10: LCD2 (line 3&4) enable pin
- D11: LCD1 (line 1&2) enable pin
- D12: LCD RS Pin
- D13: Lights 74HC595 latch pin
- D13: <free> / Lights 74HC595 latch pin
- A0: remote D5
- A1: remote D2
- A2: remote D1
Expand All @@ -61,6 +62,10 @@
#include "Simulator.h"
#endif

#ifdef WS281x
#include <Adafruit_NeoPixel.h>
#endif // WS281x

uint8_t iS1Pin = 2;
uint8_t iS2Pin = 3;
uint8_t iCurrentDog;
Expand All @@ -76,6 +81,18 @@ int iBatterySensorPin = A6;
uint16_t iBatteryVoltage = 0;

//Initialise Lights stuff
#ifdef WS281x
uint8_t iLightsDataPin = 8;
Adafruit_NeoPixel LightsStrip = Adafruit_NeoPixel(5, iLightsDataPin, NEO_RGB);
#else
uint8_t iLightsClockPin = 8;
uint8_t iLightsDataPin = 9;
uint8_t iLightsLatchPin = 13;
#endif // WS281x



//Set last serial output variable
long lLastSerialOutput = 0;

//remote control pins
Expand Down Expand Up @@ -111,7 +128,11 @@ void setup()
BatterySensor.init(iBatterySensorPin);

//Initialize LightsController class with shift register pins
LightsController.init(13,8,9);
#ifdef WS281x
LightsController.init(&LightsStrip);
#else
LightsController.init(iLightsLatchPin, iLightsClockPin, iLightsDataPin);
#endif

//Initialize RaceHandler class with S1 and S2 pins
RaceHandler.init(iS1Pin, iS2Pin);
Expand Down Expand Up @@ -159,84 +180,60 @@ void loop()
//Race start/stop button (remote D0 output) or serial command
if ((digitalRead(iRC0Pin) == HIGH
&& (millis() - lLastRCPress[0] > 2000))
|| strSerialData == "START"
|| strSerialData == "STOP")
|| (bSerialStringComplete
&& (strSerialData == "START"
|| strSerialData == "STOP")))
{
lLastRCPress[0] = millis();
if (RaceHandler.RaceState == RaceHandler.STOPPED //If race is stopped
&& RaceHandler.GetRaceTime() == 0) //and timers are zero
{
//Then start the race
if (bDEBUG) Serialprint("%lu: START!\r\n", millis());
LightsController.InitiateStartSequence();
RaceHandler.StartRace();
}
else //If race state is running or starting, we should stop it
{
RaceHandler.StopRace(micros());
LightsController.DeleteSchedules();
}
StartStopRace();
}

//Race reset button (remote D1 output)
if ((digitalRead(iRC1Pin) == HIGH
&& RaceHandler.RaceState == RaceHandler.STOPPED //Only allow reset when race is stopped first
if (digitalRead(iRC1Pin) == HIGH
&& (millis() - lLastRCPress[1] > 2000))
|| strSerialData == "RESET")
|| (bSerialStringComplete && strSerialData == "RESET"))
{
lLastRCPress[1] = millis();
LightsController.ResetLights();
RaceHandler.ResetRace();
ResetRace();
}

//Dog0 fault RC button
if ((digitalRead(iRC2Pin) == HIGH
&& RaceHandler.RaceState == RaceHandler.RUNNING //Only allow reset when race is stopped first
if (digitalRead(iRC2Pin) == HIGH
&& (millis() - lLastRCPress[2] > 2000))
|| strSerialData == "D0F")
|| (bSerialStringComplete && strSerialData == "D0F"))
{
lLastRCPress[2] = millis();
//Toggle fault for dog
RaceHandler.SetDogFault(0);
}

//Dog1 fault RC button
if ((digitalRead(iRC3Pin) == HIGH
&& RaceHandler.RaceState == RaceHandler.RUNNING //Only allow reset when race is stopped first
if (digitalRead(iRC3Pin) == HIGH
&& (millis() - lLastRCPress[3] > 2000))
|| strSerialData == "D1F")
|| (bSerialStringComplete && strSerialData == "D1F"))
{
lLastRCPress[3] = millis();
//Toggle fault for dog
RaceHandler.SetDogFault(1);
}
//Dog2 fault RC button
if ((digitalRead(iRC4Pin) == HIGH
&& RaceHandler.RaceState == RaceHandler.RUNNING //Only allow reset when race is stopped first
if (digitalRead(iRC4Pin) == HIGH
&& (millis() - lLastRCPress[4] > 2000))
|| strSerialData == "D2F")
|| (bSerialStringComplete && strSerialData == "D2F"))
{
lLastRCPress[4] = millis();
//Toggle fault for dog
RaceHandler.SetDogFault(2);
}

//Dog3 fault RC button
if ((digitalRead(iRC5Pin) == HIGH
&& RaceHandler.RaceState == RaceHandler.RUNNING //Only allow reset when race is stopped first
if (digitalRead(iRC5Pin) == HIGH
&& (millis() - lLastRCPress[5] > 2000))
|| strSerialData == "D3F")
|| (bSerialStringComplete && strSerialData == "D3F"))
{
lLastRCPress[5] = millis();
//Toggle fault for dog
RaceHandler.SetDogFault(3);
}

if (strSerialData == "DEBUG")
{
bDEBUG = !bDEBUG;
}

/*Update LCD Display fields*/
//Update team time to display
dtostrf(RaceHandler.GetRaceTime(), 7, 3, cElapsedRaceTime);
Expand Down Expand Up @@ -282,7 +279,7 @@ void loop()
//Race is finished, put final data on screen
dtostrf(RaceHandler.GetDogTime(RaceHandler.iCurrentDog, -2), 7, 3, cDogTime);
Serialprint("D%i: %s|CR: %s\r\n", RaceHandler.iCurrentDog, cDogTime, RaceHandler.GetCrossingTime(RaceHandler.iCurrentDog, -2).c_str());
Serialprint("RT: %s\r\n", cElapsedRaceTime);
Serialprint("RT:%s\r\n", cElapsedRaceTime);
}
Serialprint("RS: %i\r\n", RaceHandler.RaceState);
}
Expand All @@ -292,7 +289,7 @@ void loop()
dtostrf(RaceHandler.GetDogTime(RaceHandler.iPreviousDog, -2), 7, 3, cDogTime);
Serialprint("D%i: %s|CR: %s\r\n", RaceHandler.iPreviousDog, cDogTime, RaceHandler.GetCrossingTime(RaceHandler.iPreviousDog, -2).c_str());
Serialprint("D: %i\r\n", RaceHandler.iCurrentDog);
Serialprint("RT: %s\r\n", cElapsedRaceTime);
Serialprint("RT:%s\r\n", cElapsedRaceTime);
}

//Enable (uncomment) the following if you want periodic status updates on the serial port
Expand All @@ -319,6 +316,12 @@ void loop()
&& bSerialStringComplete)
{
if (bDEBUG) Serialprint("cSer: '%s'\r\n", strSerialData.c_str());

if (strSerialData == "DEBUG")
{
bDEBUG = !bDEBUG;
}

strSerialData = "";
bSerialStringComplete = false;
}
Expand Down Expand Up @@ -358,3 +361,38 @@ void Sensor1Wrapper()
{
RaceHandler.TriggerSensor1();
}

/// <summary>
/// Starts (if stopped) or stops (if started) a race. Start is only allowed if race is stopped and reset.
/// </summary>
void StartStopRace()
{
lLastRCPress[0] = millis();
if (RaceHandler.RaceState == RaceHandler.STOPPED //If race is stopped
&& RaceHandler.GetRaceTime() == 0) //and timers are zero
{
//Then start the race
if (bDEBUG) Serialprint("%lu: START!\r\n", millis());
LightsController.InitiateStartSequence();
RaceHandler.StartRace();
}
else //If race state is running or starting, we should stop it
{
RaceHandler.StopRace(micros());
LightsController.DeleteSchedules();
}
}

/// <summary>
/// Reset race so new one can be started, reset is only allowed when race is stopped
/// </summary>
void ResetRace()
{
if (RaceHandler.RaceState != RaceHandler.STOPPED) //Only allow reset when race is stopped first
{
return;
}
lLastRCPress[1] = millis();
LightsController.ResetLights();
RaceHandler.ResetRace();
}
Loading

0 comments on commit 5aa3a9f

Please sign in to comment.