From f01d606ff11a6352007445737086af5cfdb9c9c5 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 11 Jan 2022 10:46:04 +0100 Subject: [PATCH 1/4] Rework 'Check_inputs', removing superfluous code and including safeguards against memory access violations. --- examples/Check_inputs/Check_inputs.ino | 42 +++++++++++++++----------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/examples/Check_inputs/Check_inputs.ino b/examples/Check_inputs/Check_inputs.ino index 5ea9361..9321c32 100644 --- a/examples/Check_inputs/Check_inputs.ino +++ b/examples/Check_inputs/Check_inputs.ino @@ -1,30 +1,36 @@ -#include "Braccio++.h" +#include -String message = ""; +String toMessage(int const input) +{ + static String const message[] = + { "", + "LEFT (Joystick)", + "RIGHT (Joystick)", + "SELECT (Joystick)", + "UP (Joystick)", + "DOWN (Joystick)", + "ENTER (Button)" + }; -String checkInputs(int input){ - String check[] = { "", - "Joystick left was moved!", - "Joystick right was moved!", - "Joystick select button was pressed!", - "Joystick up was moved!", - "Joystick down was moved!", - "Enter button was pressed!"}; - return check[input]; + if (input < 7) + return message[input]; + else + return String("Error, invalid input value"); } -void setup() { +void setup() +{ Serial.begin(115200); while(!Serial){} + Braccio.begin(); Serial.println("Press any button or move the joystick."); } -void loop() { - message = checkInputs(Braccio.getKey()); - if(message != ""){ +void loop() +{ + String const message = toMessage(Braccio.getKey()); + if(message != "") Serial.println(message); - message = ""; - } - delay(500); + delay(100); } From b329991e09ad6022705a584863cc7a0b6d501d2b Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 11 Jan 2022 10:47:53 +0100 Subject: [PATCH 2/4] Adding comment describing the purpose of Check_inputs. --- examples/Check_inputs/Check_inputs.ino | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/Check_inputs/Check_inputs.ino b/examples/Check_inputs/Check_inputs.ino index 9321c32..27b42d8 100644 --- a/examples/Check_inputs/Check_inputs.ino +++ b/examples/Check_inputs/Check_inputs.ino @@ -1,3 +1,9 @@ +/* This example allows the user to read the + * inputs of the Braccio++ shield UI devices: + * - joystick (up,down,left,right,select) + * - button (enter) + */ + #include String toMessage(int const input) From 8df88e911e22c2e02266b54094807e472e94e485 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 11 Jan 2022 10:49:10 +0100 Subject: [PATCH 3/4] Renaming 'Check_inputs' to 'Check_Inputs' Staying consistent with examples naming API. --- .../Check_inputs.ino => Check_Inputs/Check_Inputs.ino} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/{Check_inputs/Check_inputs.ino => Check_Inputs/Check_Inputs.ino} (100%) diff --git a/examples/Check_inputs/Check_inputs.ino b/examples/Check_Inputs/Check_Inputs.ino similarity index 100% rename from examples/Check_inputs/Check_inputs.ino rename to examples/Check_Inputs/Check_Inputs.ino From 7e24530caec2e5383f6cce3c5ed2fa9b85ef0429 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 11 Jan 2022 10:50:07 +0100 Subject: [PATCH 4/4] Moving 'Check_Inputs' into 'Tools' subdirectory. --- examples/{ => Tools}/Check_Inputs/Check_Inputs.ino | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/{ => Tools}/Check_Inputs/Check_Inputs.ino (100%) diff --git a/examples/Check_Inputs/Check_Inputs.ino b/examples/Tools/Check_Inputs/Check_Inputs.ino similarity index 100% rename from examples/Check_Inputs/Check_Inputs.ino rename to examples/Tools/Check_Inputs/Check_Inputs.ino