-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
72fef48
commit 4e3e4e8
Showing
2 changed files
with
212 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,155 +1,159 @@ | ||
/********************************************************************************************** | ||
* Arduino LED RGB Library - Version 1.0 | ||
* by William Bailes <williambailes@gmail.com> http://tinkersprojects.com/ | ||
* | ||
* This Library is licensed under a GPLv3 License | ||
**********************************************************************************************/ | ||
#define version 1.0 | ||
|
||
#if ARDUINO >= 100 | ||
#include "Arduino.h" | ||
#else | ||
#include "WProgram.h" | ||
#endif | ||
|
||
#include "gcode.h" | ||
|
||
/******************* SETUP *******************/ | ||
|
||
gcode::gcode() | ||
{ | ||
} | ||
|
||
gcode::gcode(commandscallback *commandscallbacks_temp) | ||
{ | ||
commandscallbacks = commandscallbacks_temp; | ||
} | ||
|
||
gcode::gcode(void (*CallBack)()) | ||
{ | ||
runCallback = CallBack; | ||
} | ||
|
||
void gcode::begin() | ||
{ | ||
Serial.begin(9600); | ||
Serial.println("v" +String(version)+" Simple G code"); | ||
} | ||
|
||
void gcode::begin(int bitrate) | ||
{ | ||
Serial.begin(bitrate); | ||
Serial.println("v" +String(version)+" Simple G code"); | ||
} | ||
|
||
|
||
/******************* receive *******************/ | ||
|
||
void gcode::clearBuffer() | ||
{ | ||
commandLetter = 0; | ||
commandBuffer = ""; | ||
commandValue = 0; | ||
} | ||
|
||
bool gcode::available() | ||
{ | ||
while (Serial.available()) | ||
{ | ||
char inChar = (char)Serial.read(); | ||
|
||
if(inChar == ' ' || inChar == '\n') | ||
{ | ||
if(commandBuffer != "") | ||
{ | ||
if(commandLetter == 0) | ||
{ | ||
commandsList[0] = commandBuffer.toDouble(); | ||
} | ||
else if(commandLetter >= 'A' && commandLetter <= 'Z') | ||
{ | ||
commandsList[commandLetter - 'A' + 1] = commandBuffer.toDouble(); | ||
} | ||
|
||
// run if command matches | ||
|
||
for(int i = 0; i < 2 /*sizeof(commandscallbacks)*/; i++) | ||
{ | ||
commandscallback commandscallbackstest = commandscallbacks[i]; | ||
|
||
if(commandscallbackstest.includesValue == 0 && (commandscallbackstest.letter == commandLetter || commandscallbackstest.letter-('a'-'A') == commandLetter)) | ||
{ | ||
commandscallbackstest.Callback(); | ||
} | ||
if(commandscallbackstest.includesValue == 1 && (commandscallbackstest.letter == commandLetter || commandscallbackstest.letter-('a'-'A') == commandLetter) && commandscallbackstest.value == commandBuffer.toDouble()) | ||
{ | ||
commandscallbackstest.Callback(); | ||
} | ||
} | ||
} | ||
gcode::clearBuffer(); | ||
} | ||
|
||
if(inChar == '\n') | ||
{ | ||
// run | ||
restIsComment = false; | ||
if(runCallback != NULL) | ||
runCallback(); | ||
return true; | ||
} | ||
|
||
if(inChar == ';' || restIsComment) | ||
{ | ||
restIsComment = true; | ||
return false; | ||
} | ||
|
||
if(inChar >= 'a' && inChar <= 'z') | ||
{ | ||
inChar = inChar - ('a'-'A'); | ||
} | ||
|
||
if(inChar >= 'A' && inChar <= 'Z') | ||
{ | ||
gcode::clearBuffer(); | ||
commandLetter = inChar; | ||
return false; | ||
} | ||
|
||
if((inChar >= '0' && inChar <= '9') || inChar == '.' || inChar == '-') | ||
{ | ||
commandBuffer = commandBuffer + String(inChar); | ||
return false; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
void gcode::comment(String comment) | ||
{ | ||
Serial.println(";" +String(comment)); | ||
} | ||
|
||
void gcode::command(char number, double values) | ||
{ | ||
Serial.println(String(number)+String(values)); | ||
} | ||
|
||
double gcode::GetValue(char Letter) | ||
{ | ||
if(Letter >= 'a' && Letter <= 'z') | ||
{ | ||
Letter = Letter - ('a'-'A'); | ||
} | ||
|
||
if(Letter == ' ') | ||
{ | ||
return commandsList[0]; | ||
} | ||
else if(Letter >= 'A' && Letter <= 'Z') | ||
{ | ||
return commandsList[Letter - 'A' + 1]; | ||
} | ||
return 0; | ||
/********************************************************************************************** | ||
* Arduino LED RGB Library - Version 1.0 | ||
* by William Bailes <williambailes@gmail.com> http://tinkersprojects.com/ | ||
* | ||
* This Library is licensed under a GPLv3 License | ||
**********************************************************************************************/ | ||
#define version 1.0 | ||
|
||
#if ARDUINO >= 100 | ||
#include "Arduino.h" | ||
#else | ||
#include "WProgram.h" | ||
#endif | ||
|
||
#include "gcode.h" | ||
|
||
/******************* SETUP *******************/ | ||
|
||
gcode::gcode() | ||
{ | ||
} | ||
|
||
gcode::gcode(commandscallback *commandscallbacks_temp) | ||
{ | ||
commandscallbacks = commandscallbacks_temp; | ||
} | ||
|
||
gcode::gcode(void (*CallBack)()) | ||
{ | ||
runCallback = CallBack; | ||
} | ||
|
||
void gcode::begin() | ||
{ | ||
Serial.begin(9600); | ||
Serial.println("v" +String(version)+" Simple G code"); | ||
} | ||
|
||
void gcode::begin(int bitrate) | ||
{ | ||
Serial.begin(bitrate); | ||
Serial.println("v" +String(version)+" Simple G code"); | ||
} | ||
|
||
|
||
/******************* receive *******************/ | ||
|
||
void gcode::clearBuffer() | ||
{ | ||
commandLetter = 0; | ||
commandBuffer = ""; | ||
commandValue = 0; | ||
} | ||
|
||
bool gcode::available() | ||
{ | ||
while (Serial.available()) | ||
{ | ||
char inChar = (char)Serial.read(); | ||
if(gcode::available(inChar)) | ||
{ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
bool gcode::available(char inChar) | ||
{ | ||
if(inChar == ' ' || inChar == '\n') | ||
{ | ||
if(commandBuffer != "") | ||
{ | ||
if(commandLetter == 0) | ||
{ | ||
commandsList[0] = commandBuffer.toDouble(); | ||
} | ||
else if(commandLetter >= 'A' && commandLetter <= 'Z') | ||
{ | ||
commandsList[commandLetter - 'A' + 1] = commandBuffer.toDouble(); | ||
} | ||
|
||
// run if command matches | ||
|
||
for(int i = 0; i < 2 /*sizeof(commandscallbacks)*/; i++) | ||
{ | ||
commandscallback commandscallbackstest = commandscallbacks[i]; | ||
|
||
if(commandscallbackstest.value == String(commandLetter)+String(commandBuffer) || commandscallbackstest.value == String(commandLetter-('a'-'A'))+String(commandBuffer)) | ||
{ | ||
commandscallbackstest.Callback(); | ||
} | ||
} | ||
} | ||
gcode::clearBuffer(); | ||
} | ||
|
||
if(inChar == '\n') | ||
{ | ||
// run | ||
restIsComment = false; | ||
if(runCallback != NULL) | ||
runCallback(); | ||
return true; | ||
} | ||
|
||
if(inChar == ';' || restIsComment) | ||
{ | ||
restIsComment = true; | ||
return false; | ||
} | ||
|
||
if(inChar >= 'a' && inChar <= 'z') | ||
{ | ||
inChar = inChar - ('a'-'A'); | ||
} | ||
|
||
if(inChar >= 'A' && inChar <= 'Z') | ||
{ | ||
gcode::clearBuffer(); | ||
commandLetter = inChar; | ||
return false; | ||
} | ||
|
||
if((inChar >= '0' && inChar <= '9') || inChar == '.' || inChar == '-') | ||
{ | ||
commandBuffer = commandBuffer + String(inChar); | ||
return false; | ||
} | ||
return false; | ||
} | ||
|
||
void gcode::comment(String comment) | ||
{ | ||
Serial.println(";" +String(comment)); | ||
} | ||
|
||
void gcode::command(char number, double values) | ||
{ | ||
Serial.println(String(number)+String(values)); | ||
} | ||
|
||
double gcode::GetValue(char Letter) | ||
{ | ||
if(Letter >= 'a' && Letter <= 'z') | ||
{ | ||
Letter = Letter - ('a'-'A'); | ||
} | ||
|
||
if(Letter == ' ') | ||
{ | ||
return commandsList[0]; | ||
} | ||
else if(Letter >= 'A' && Letter <= 'Z') | ||
{ | ||
return commandsList[Letter - 'A' + 1]; | ||
} | ||
return 0; | ||
} |
Oops, something went wrong.