/* || || @file mlaser.pde || @version 1.0 || @author Alexander Brevig || @contact alexanderbrevig@gmail.com || || @description || | Implement an example using the library Toolkit || | Improvised from this thread: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1240828046 || # || || @contribution || | [url=http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?action=viewprofile;username=mlaser]mlaser[/url] || | [url=http://arduino.cc/playground/Profiles/AlphaBeta]AlphaBeta[/url] || # */ @@#include //http://hosting.alexanderbrevig.com/arduino/libraries/Toolkit.zip //constants const unsigned int TIMEOUT = 1000; const byte MAX_COMMAND_LENGTH = 12; //command syntax const char REQUEST = '+'; const char REPLACE = '-'; const char END_OF_COMMAND = '$'; //initialize some tools @@Tool spanner8 = Tool("spanner8"); @@Tool spanner10 = Tool("spanner10"); @@Tool spanner12 = Tool("spanner12"); @@Tool spanner14 = Tool("spanner14"); //prepare the toolkit @@Toolkit toolkit; //initialize a user @@ToolUser mlaser = ToolUser("mlaser",toolkit); //user name is mlaser, and this user can use tools from the Toolkit named toolkit //program variables unsigned long time = 0; //store the time when the serial becomes available. Is used to implement a TIMEOUT boolean toolRequest = false; //do user want to add or remove a tool? boolean readCommand = false; //are we ready to recieve a command? char command[MAX_COMMAND_LENGTH+1] = {'\0'}; //store the command byte currentCommandIndex = 0; //current index in the command array /* || @description || | Setup toolkit and mlaser:ToolUser || | Print information and a description to the serial console || # */ void setup() { Serial.begin(9600); //description to serial monitor Serial.println("You can add or remove tools by usnig these commands:"); Serial.println("\t+SpannerXX$"); Serial.println("\t-SpannerXX$"); Serial.println("\tWhere:"); Serial.println("\t\t+ and - indicates the wanted operation (add / remove)"); Serial.println("\t\tXX could be either 8,10,12 or 14"); Serial.println("\t\t$ indicates command end"); Serial.println("Write '+Spanner10$' in order to add spanner10"); Serial.println("Write '-Spanner10$' in order to remove spanner10"); //setup toolkit @@ toolkit.addTool(spanner8); @@ toolkit.addTool(spanner10); @@ toolkit.addTool(spanner12); @@ toolkit.addTool(spanner14); @@ toolkit.printTools(); //make the user aware of what tools is available //setup user programmatically @@ mlaser.request(spanner8); @@ mlaser.request(spanner12); @@ mlaser.request(spanner14); @@ mlaser.printTools(); //make user aware of what tools it already has }//end setup void loop(){ /* This is just an example, and not programmatically good. Contact me for useful additions to the Toolkit and ToolUser API */ if (Serial.available()){ //there are something available in the buffer readCommand = false; //reset readCommand. We will need a REQUEST or REPLACE command to set this true currentCommandIndex = 0; time = millis(); while (millis()