Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed a few bugs #2

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d7f17bd
renaming SerialControl.ino to first caps
Nov 18, 2014
0e99b69
renamed SerialControl.ino to first caps
Nov 18, 2014
2f3aaf6
fixed bug in isNumeric() function - char 75[K] should be 57[9]
Nov 18, 2014
06362b0
added LINE_ENDING define and improved detecting of these chars in get…
Nov 18, 2014
14c543e
merged Func.ino files into Commands.ino
Nov 19, 2014
058eaac
updated some comments
Nov 19, 2014
3662689
added BAUD_RATE and MAX_LENGTH defines
Nov 19, 2014
ce8f544
changed ANSWER to a define
Nov 19, 2014
49ecaaa
renamed OFFSET_ defines and added SIZE_ARG
Nov 19, 2014
84d6466
wrote new getArgument() and getIntArgument() functions
Nov 19, 2014
7e926d5
renamed ownID and recID to OWN_ID and CALL_ID
Nov 19, 2014
3bea3a7
some final cleanup
Nov 19, 2014
5ab4c1b
removed spaces from command response strings
Nov 19, 2014
f13ed3c
fixed minor bug on startup
Nov 19, 2014
eabb455
added clearBuffer() function to simplify nested if's in processComman…
Nov 19, 2014
374f202
added early detection of empty command buffer
Nov 19, 2014
ecd95b9
added padInt() function to ensure returned commands have the proper f…
Nov 19, 2014
f73b9a9
added command to set device id and save to eeprom
Nov 19, 2014
1a12cbf
added INHI mode for input pulled high
Nov 19, 2014
ad4d55f
some final cleanup
Nov 19, 2014
f37df6a
added scan command to detect multiple devices on a comm port
Nov 20, 2014
6e3c8c6
added SCAN_DELAY define
Nov 22, 2014
723abd2
changed all commands from pins 0-14 to 2-14
Nov 22, 2014
25dce96
added PIN_FROM and PIN_TO defines
Nov 24, 2014
cdab2e8
fixed formatting of user changable defines
Nov 24, 2014
98ed1f4
added SIZE_ID define
Nov 24, 2014
72defb8
added support for both Arduino Uno and Due
Nov 24, 2014
a4f8123
added scanFunc() and moved code from main file to Commands.ino
Nov 24, 2014
01c9749
ensure OWN_ID is 0-99 (flash defaults to 255 before set)
Nov 24, 2014
f2d8a54
changed processCommand() to validate id using SIZE_ID
Nov 24, 2014
af31525
changed ERROR response to use id and error codes
Nov 24, 2014
4d4e699
added #ifdef ANSWER where missing
Nov 24, 2014
4f4d85c
changed allFunc() to store argument in String arg
Nov 24, 2014
2119073
changed pinModeFunc() to store argument in String mode and reordered …
Nov 24, 2014
e1a44f5
changed digitalWriteFunc() to store argument in char arg
Nov 24, 2014
d9b4ebf
added missing lines to save id to due flash
Nov 24, 2014
f775ed6
fixed error command in setIdFunc()
Nov 24, 2014
c424e40
changed/added a few comments
Nov 24, 2014
46995f0
minor change to formatting of SIZE defines to be more clearly readable
lorenzop Dec 8, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 180 additions & 0 deletions Commands.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
/*******************************************************************************

This file is part of SerialControl.

SerialControl 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 2 of the License, or
(at your option) any later version.

SerialControl is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with SerialControl. If not, see <http://www.gnu.org/licenses/>.

*******************************************************************************/


// scan for device id's
void scanFunc() {
delay( SCAN_DELAY * (OWN_ID + 2) );
#ifdef ANSWER
Serial << padInt(OWN_ID, SIZE_ID) << "id" << VERSION << LINE_ENDING;
#endif
}


// all pins
void allFunc() {
String arg = getArgument(OFFSET_AR1, SIZE_ARG);
arg.toUpperCase();
if (getArgument(OFFSET_AR1, SIZE_ARG - 1).equals("LOW"))
arg = "LOW_";
// set all to output mode off/low
if (arg.equals("OUTP") || arg.equals("LOW_")) {
for (int i = PIN_FROM; i < PIN_TO; i++) {
pinMode (i, OUTPUT);
digitalWrite(i, LOW);
}
} else
// set all to output mode on/high
if (arg.equals("HIGH")) {
for (int i = PIN_FROM; i < PIN_TO; i++) {
pinMode (i, OUTPUT);
digitalWrite(i, HIGH);
}
} else
// set all to input mode
if (arg.equals("INPU")) {
for (int i = PIN_FROM; i < PIN_TO; i++)
pinMode(i, INPUT);
} else
// set all to input pulled high mode
if (arg.equals("INHI")) {
for (int i = PIN_FROM; i < PIN_TO; i++)
pinMode(i, INPUT_PULLUP);
} else {
// error
#ifdef ANSWER
Serial << padInt(OWN_ID, SIZE_ID) << "ERROR" << LINE_ENDING;
#endif
return;
}
#ifdef ANSWER
Serial << padInt(OWN_ID, SIZE_ID) << "al" << arg << LINE_ENDING;
#endif
}


// set pin mode
void pinModeFunc() {
int pin = getIntArgument(OFFSET_AR1, SIZE_ARG);
String mode = getArgument (OFFSET_AR2, SIZE_ARG);
mode.toUpperCase();
// set output mode
if (mode.equals("OUTP")) {
pinMode (pin, OUTPUT);
digitalWrite(pin, LOW);
} else
// set input floating mode
if (mode.equals("INPU")) {
pinMode (pin, INPUT);
digitalWrite(pin, LOW);
} else
// set input pulled high
if (mode.equals("INHI")) {
pinMode (pin, INPUT_PULLUP);
//digitalWrite(pin, HIGH);
} else {
// error
#ifdef ANSWER
Serial << padInt(OWN_ID, SIZE_ID) << "ERRORpm" << LINE_ENDING;
#endif
return;
}
#ifdef ANSWER
Serial << padInt(OWN_ID, SIZE_ID) << "pm" << padInt(pin, SIZE_ARG) << mode << LINE_ENDING;
#endif
}


// digital write
void digitalWriteFunc() {
int pin = getIntArgument(OFFSET_AR1, SIZE_ARG);
char arg = command.charAt(OFFSET_AR2);
// set pin high
if (arg == '1' || arg == 'H' || arg == 'h') {
digitalWrite(pin, HIGH);
#ifdef ANSWER
Serial << padInt(OWN_ID, SIZE_ID) << "dw" << padInt(pin, SIZE_ARG) << "HIGH" << LINE_ENDING;
#endif
} else
// set pin low
if (arg == '0' || arg == 'L' || arg == 'l') {
digitalWrite(pin, LOW);
#ifdef ANSWER
Serial << padInt(OWN_ID, SIZE_ID) << "dw" << padInt(pin, SIZE_ARG) << "LOW_" << LINE_ENDING;
#endif
} else {
// error
#ifdef ANSWER
Serial << padInt(OWN_ID, SIZE_ID) << "ERRORdw" << LINE_ENDING;
#endif
}
}


// pwm
void analogWriteFunc() {
int pin = getIntArgument(OFFSET_AR1, SIZE_ARG);
int val = getIntArgument(OFFSET_AR2, SIZE_ARG);
analogWrite(pin, val);
#ifdef ANSWER
Serial << padInt(OWN_ID, SIZE_ID) << "aw" << padInt(pin, SIZE_ARG) << padInt(val, SIZE_ARG) << LINE_ENDING;
#endif
}


// digital read
void digitalReadFunc() {
int pin = getIntArgument(OFFSET_AR1, SIZE_ARG);
int val = digitalRead(pin);
#ifdef ANSWER
Serial << padInt(OWN_ID, SIZE_ID) << "dr" << padInt(pin, SIZE_ARG) << padInt(val, SIZE_ARG) << LINE_ENDING;
#endif
}


// analog read
void analogReadFunc() {
int pin = getIntArgument(OFFSET_AR1, SIZE_ARG);
// read analog
int val = analogRead(pin);
#ifdef ANSWER
Serial << padInt(OWN_ID, SIZE_ID) << "ar" << padInt(pin, SIZE_ARG) << padInt(val, SIZE_ARG) << LINE_ENDING;
#endif
}


void setIdFunc() {
int id = getIntArgument(OFFSET_AR1, SIZE_ARG);
if (id < 0 || id > 99) {
#ifdef ANSWER
Serial << padInt(OWN_ID, SIZE_ID) << "ERRORid" << LINE_ENDING;
#endif
return;
}
// save to flash
#if defined ( is_AVR )
EEPROM.write(MEMADDR_ID, id);
#elif defined ( is_SAM )
DueFlashStorage().write(MEMADDR_ID, (byte) id);
#endif
OWN_ID = id;
#ifdef ANSWER
Serial << padInt(OWN_ID, SIZE_ID) << "id" << LINE_ENDING;
#endif
}
Loading