/* Get acceleration data from Chronos watch. Taken from info posted at: http://e2e.ti.com/support/microcontrollers/msp43016-bit_ultra-low_power_mcus/f/166/t/32714.aspx Based off of the latest Python code on the Chronos wiki that I wrote. Copyright (c) 2010 Sean Brewer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. If you want you may contact me at seabre986@gmail.com or on reddit: seabre Modications made by Oliver Smith to print out buttons http://chemicaloliver.net */ import processing.serial.*; //Horizontal coordinate for graphics int xPos = 1; //Take what we know about the packets for starting the access point //and put it in its integer representation int startAccessPointNum[] = {255, 7, 3}; //Take what we know about the packets for aquiring data from the chronos //and put it in its integer representation int accDataRequestNum[] = {255, 8, 7, 0, 0, 0, 0}; //Convert it all to bytes so that watch will understand //what we're talking about.. byte startAccessPoint[] = byte(startAccessPointNum); byte accDataRequest[] = byte(accDataRequestNum); // We want to talk to the chronos... Serial chronos; void setup() { //Draw window //In linux /dev/ttyACM0 is not correctly detected by java so //setting this property solves that //You'll need to change this if you are using osx/windows or //another serial port System.setProperty("gnu.io.rxtx.SerialPorts", "/dev/ttyACM0"); chronos = new Serial(this, "/dev/ttyACM0", 115200); //Start the access point.. chronos.write(startAccessPoint); //Until the port is still availible... //Send data request to chronos. chronos.write(accDataRequest); background(0); } void draw() { if(chronos.available() >= 0) { //Accelerometer data is 7 bytes long. This looks really lame, but it works. int[] buf = new int[7]; for (int i = 0; i < 7; i++) buf[i] = chronos.read(); //Fourth byte indicates if there are coordinates. If the byte is 0xFF (255) //Then there is no data. If it is 1, then data is valid. //Sometimes the datatype comes back as other values...not sure if that //means anything or not. //Also, the Python version of this code ALWAYS returns 0xFF (255).. //Don't know why that is. if(buf[4] == 0) { /*for (int i = 0; i < 7; i++) { print (i+" = "+buf[i]+" "); } println("\n");*/ //on my chronos (the 868MHz version) the following values are correct however other watches may use //values one less than the current value if(buf[3]==18) { println("Top Left"); } if(buf[3]==50) { println("Top Right"); } if(buf[3]==34) { println("Bottom Left"); } } } chronos.write(accDataRequest); }