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