updating kicker v1

This commit is contained in:
Ghassan Yusuf 2020-05-22 09:33:27 +03:00
parent 1302316362
commit 417b22e36e
3 changed files with 30 additions and 28 deletions

View File

@ -2,17 +2,17 @@
// TERMINAL WINDOW - NATIVE USB
//======================================================
void terminal(String msg)
void terminal(String msg)
{
msg += "\n";
Terminal.print(msg);
}
//======================================================
// BLUETOOTH WINDOW - NATIVE/VERTUAL USB
//======================================================
void bluetooth(String msg)
void bluetooth(String msg)
{
msg += "\n";
Bluetooth.print(msg);
@ -22,7 +22,7 @@
// BLUETOOTH WINDOW - NATIVE/VERTUAL USB
//======================================================
void dualcomm(String msg)
void dualcomm(String msg)
{
terminal(msg);
bluetooth(msg);

View File

@ -3,7 +3,7 @@
//======================================================
/* game selector is the main function that tell the game groutine
* which game to be JSONed and at what parameters
* which game to be JSONed and at what parameters
*/
void game_selector(String game, String settings)
@ -18,7 +18,7 @@
// Time Attack Game
else if(game == "ta") {
terminal(GM_TATTACK);
game_reaction_bluetooth(settings);
time_attack_bluetooth(settings);
return;
}

View File

@ -2,17 +2,17 @@
// TIME ATTACK GAME MAIN ROUTINE
//======================================================
/* This Game Can Be Called From
/* This Game Can Be Called From
* Stand Alone Mode / Bluetooth Connection
* The primary mode is the standalone but
* if the bluetooth is connected it has the priority
* so it will take over the control of the device
*
*
* If you want to control the game via bluetooth
* you need to call : time_attack_bluetooth(JSON String)
* If you want to use the stand alone mode
* you need to call : time_attack_standalone()
*
*
* the game returns a float point number which is
* in seconds. so the athlete know how long he takes to react
*/
@ -24,11 +24,11 @@
void time_attack_standalone()
{
// Variables
uint16_t time = 0;
uint16_t timer = 0;
uint16_t limit = 0;
uint16_t time = 0;
uint16_t timer = 0;
uint16_t limit = 0;
bool limitEnable = 0;
// Display Screen Menu And Button Actions
// If The Menu Number 1 -> We Set The Value Of Min Delay
// If The Menu Number 2 -> We Set The Value Of Max Delay
@ -44,7 +44,7 @@
/* TIME ATTACK GAME SETTINGS PARAMETERS NOTE:
* ------------------------------------------
*
*
* FORMAT :
* --------
* {"tm": 10, "le": false, "lm": 10}
@ -52,22 +52,22 @@
* tm : count down timer starting value
* le : stands for limit enable, if is TRUE the game end if target value is meet
* lm : targeted amount of kicks
*
*
* THINGS THAT ENDS THE GAME :
* ---------------------------
* 1. BY COUNT DOWN "tm" REACH TO ZERO
* 2. BY A COMMAND "FROM APP VIA BLUETOOTH"
* 3. BY LIMITS MEET "WHEN NUMBER OF YOUR KICKS REACH TO lm VALUE"
*
*
* CALCULATING RESULTS :
* ---------------------
* Rapid Kick Speed = Number Of Kickes Made / Elasped Time In Sec
* Delay Between Kicks = Time Of Current Kick - Time Of Last Kick
*
*
* RETURNNING JSON FORMAT :
* ------------------------
* {"tm" : 82, "ct" : 10, "dl" : 1234, "st" : 585}
*
*
* tm : timer count in Sec
* ct : strike counter (number of kicks)
* dl : delay between strikes
@ -75,7 +75,7 @@
*/
void time_attack_bluetooth(String settings)
{
{
// Deserialize the JSON document
DeserializationError error = deserializeJson(JSON, settings); // the main JSON body container
@ -102,7 +102,7 @@
// Play Time Atack Game
//======================================================
void game_timeAttack(uint16_t time, uint16_t timer, uint16_t limit, bool limitEnable)
void game_timeAttack(uint16_t time, uint16_t timer, uint16_t limit, bool limitEnable)
{
// Building Timers 1000mSec -> 1Sec
TimeTrigger sec_tick(1000);
@ -122,7 +122,7 @@
// staring Of time stamp
unsigned long startStamp = millis();
// store the time of the previous kick
unsigned long lastStamp = 0;
@ -141,7 +141,7 @@
String msg = Bluetooth.readStringUntil('\n');
flushBluetooth;
msg.trim();
if(msg == CM_STOP)
if(msg == CM_STOP)
{
dualcomm(GAME_OVER);
// Grean Light In
@ -161,8 +161,9 @@
LED_SIGNAL_RESET();
}
}
// Every Kick ---------------------------->>>
if(readImpact() > VTH)
{
counter++;
@ -172,12 +173,13 @@
}
// Every Second ---------------------------->>>
if(sec_tick.Trigger())
{
timer--;
dualcomm(timeAttack_JSON_json(timer, counter, 0, 0));
}
// If Limits Are Enabled And Meet
if(limitEnable == true && counter == limit)
{
@ -205,25 +207,25 @@
//======================================================
String timeAttack_JSON_json(unsigned int RunningTime, unsigned int KickCount, unsigned int LastStamp, unsigned int TimeStamp)
{
{
// Building The Buffer
JSON["tm"] = RunningTime;
JSON["ct"] = KickCount;
// Calculations
if(TimeStamp > 0)
if(TimeStamp > 0)
{
// Calculate Time Stamp In Seconds
float st = TimeStamp;
st /= 1000;
JSON["st"] = String(st, 3).toFloat();
// Calculate Strike Delay In Seconds
float dl = TimeStamp - LastStamp;
dl /= 1000;
JSON["dl"] = String(dl, 3).toFloat();
}
String output;
serializeJson(JSON, output);
JSON.clear();