Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 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
- */
- import processing.serial.*;
- //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;
- //Hopefully, the port you're looking for is the same one
- //as the chronos is assigned to. If not, change the
- //"0" in Serial.list() to the appropriate value.
- chronos = new Serial(this, Serial.list()[0], 115200);
- //Start the access point..
- chronos.write(startAccessPoint);
- //Until the port is still availible...
- //Send data request to chronos.
- chronos.write(accDataRequest);
- //Processing doesn't like infinite loops...but we're going to do one anyway.
- while (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[3] == 1) {
- //println("Datatype: " + str(buf[3]));
- println ("x: " + str(buf[4]) + " y: " + str(buf[5]) + " z: " + str(buf[6]));
- }
- chronos.write(accDataRequest);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement