Advertisement
Guest User

Sean Brewer

a guest
Feb 4th, 2010
4,633
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. /*
  2. Get acceleration data from Chronos watch.
  3. Taken from info posted at: http://e2e.ti.com/support/microcontrollers/msp43016-bit_ultra-low_power_mcus/f/166/t/32714.aspx
  4.  
  5. Based off of the latest Python code on the Chronos wiki that I wrote.
  6.  
  7.  
  8. Copyright (c) 2010 Sean Brewer
  9. Permission is hereby granted, free of charge, to any person
  10. obtaining a copy of this software and associated documentation
  11. files (the "Software"), to deal in the Software without
  12. restriction, including without limitation the rights to use,
  13.  
  14. copies of the Software, and to permit persons to whom the
  15. Software is furnished to do so, subject to the following
  16. conditions:
  17.  
  18. The above copyright notice and this permission notice shall be
  19. included in all copies or substantial portions of the Software.
  20.  
  21. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  23. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  25. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  26. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  27. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  28. OTHER DEALINGS IN THE SOFTWARE.
  29.  
  30.  
  31.  
  32. If you want you may contact me at seabre986@gmail.com
  33. or on reddit: seabre
  34. */
  35.  
  36. import processing.serial.*;
  37.  
  38. //Take what we know about the packets for starting the access point
  39. //and put it in its integer representation
  40. int startAccessPointNum[] = {255, 7, 3};
  41. //Take what we know about the packets for aquiring data from the chronos
  42. //and put it in its integer representation
  43. int accDataRequestNum[] = {255, 8, 7, 0, 0, 0, 0};
  44.  
  45. //Convert it all to bytes so that watch will understand
  46. //what we're talking about..
  47. byte startAccessPoint[] = byte(startAccessPointNum);
  48. byte accDataRequest[] = byte(accDataRequestNum);
  49.  
  50.  
  51. // We want to talk to the chronos...
  52. Serial chronos;
  53.  
  54. //Hopefully, the port you're looking for is the same one
  55. //as the chronos is assigned to. If not, change the
  56. //"0" in Serial.list() to the appropriate value.
  57. chronos = new Serial(this, Serial.list()[0], 115200);
  58.  
  59. //Start the access point..
  60. chronos.write(startAccessPoint);
  61.  
  62.  
  63. //Until the port is still availible...
  64. //Send data request to chronos.
  65. chronos.write(accDataRequest);
  66.  
  67. //Processing doesn't like infinite loops...but we're going to do one anyway.
  68. while (chronos.available() >= 0) {
  69.  
  70. //Accelerometer data is 7 bytes long. This looks really lame, but it works.
  71. int[] buf = new int[7];
  72.  
  73. for (int i = 0; i < 7; i++)
  74. buf[i] = chronos.read();
  75.  
  76. //Fourth byte indicates if there are coordinates. If the byte is 0xFF (255)
  77. //Then there is no data. If it is 1, then data is valid.
  78. //Sometimes the datatype comes back as other values...not sure if that
  79. //means anything or not.
  80. //Also, the Python version of this code ALWAYS returns 0xFF (255)..
  81. //Don't know why that is.
  82. if (buf[3] == 1) {
  83. //println("Datatype: " + str(buf[3]));
  84. println ("x: " + str(buf[4]) + " y: " + str(buf[5]) + " z: " + str(buf[6]));
  85.  
  86. }
  87.  
  88. chronos.write(accDataRequest);
  89. }
  90.  
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement