You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

755 lines
25 KiB

5 years ago
  1. import processing.core.*;
  2. import processing.xml.*;
  3. import pitaru.sonia_v2_9.*;
  4. import processing.serial.*;
  5. import java.io.BufferedReader;
  6. import java.io.IOException;
  7. import java.io.InputStreamReader;
  8. import java.applet.*;
  9. import java.awt.Dimension;
  10. import java.awt.Frame;
  11. import java.awt.event.MouseEvent;
  12. import java.awt.event.KeyEvent;
  13. import java.awt.event.FocusEvent;
  14. import java.awt.Image;
  15. import java.io.*;
  16. import java.net.*;
  17. import java.text.*;
  18. import java.util.*;
  19. import java.util.zip.*;
  20. import java.util.regex.*;
  21. public class CapTouch_BoosterPack_UserExperience_GUI extends PApplet {
  22. /*******************************************************************************
  23. *
  24. * CapTouch_BoosterPack_UserExperience_GUI.pde
  25. * - PC demo application for establishing a serial connection
  26. * with the LaunchPad CapTouch BoosterPack.
  27. *
  28. * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
  29. *
  30. * Redistribution and use in source and binary forms, with or without
  31. * modification, are permitted provided that the following conditions
  32. * are met:
  33. *
  34. * Redistributions of source code must retain the above copyright
  35. * notice, this list of conditions and the following disclaimer.
  36. *
  37. * Redistributions in binary form must reproduce the above copyright
  38. * notice, this list of conditions and the following disclaimer in the
  39. * documentation and/or other materials provided with the
  40. * distribution.
  41. *
  42. * Neither the name of Texas Instruments Incorporated nor the names of
  43. * its contributors may be used to endorse or promote products derived
  44. * from this software without specific prior written permission.
  45. *
  46. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  47. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  48. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  49. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  50. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  51. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  52. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  53. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  54. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  55. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  56. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  57. *
  58. *
  59. ******************************************************************************/
  60. /******************************************************************************
  61. * MSP430G2-LaunchPad CapTouch BoosterPack User Experience GUI
  62. * Desc:
  63. * This PC GUI application communicates with the LaunchPad specifically to
  64. * receive capacitive touch data from the LaunchPad CapTouch BoosterPack and
  65. * provides the visualization of said information in the GUI.
  66. *
  67. * The GUI uses a small .NET utility (FindAppUART.exe) to automatically detect
  68. * a proper LaunchPad/430Emulator device connected to the PC USB port. Upon
  69. * correct USB COM port discovery, the application initiates a 9600baud UART
  70. * connection and starts receiving data.
  71. *
  72. * Upon each LaunchPad event, data is transmitted [always] via a simple '2-byte'
  73. * protocol as described below.
  74. * [LaunchPad] Wake up : 0xBE 0xEF
  75. * [LaunchPad] Sleep : 0xDE 0xAD
  76. * [CapTouch] Center Button : 0x80 0x80
  77. * [CapTouch] Wheel Tap : WT WT = pos. on wheel [0-0x0F] + 0x30
  78. * [CapTouch] Gesture Start : 0xFC POS = pos. on wheel [0-0x0F] + 0x20
  79. * [CapTouch] Gesture Stop : 0xFB POS = pos. on wheel [0-0x0F] + 0x20
  80. * [CapTouch] Gesture Update: GES POS
  81. * Gesture = [0-0x0F] --> Clockwise gesture
  82. * = 0x10+ [0-0x0F] --> Counter-clockwise gesture
  83. *
  84. * The GUI grays out during sleep mode and returns to active mode upon wake up.
  85. * The 'Center Button' press data toggles the center circle color, mimicking the
  86. * behavior of the center LED on the BoosterPack.
  87. * The 'Wheel Tap' is represented by lighting up a single slice on the wheel.
  88. * The gesture tracking [Start, Stop, Update] is visualized on the wheel with
  89. * the coloration of the wheel slices. Gesture can be tracked for several
  90. * revolutions of the wheel, in both clockwise and counter-clockwise directions.
  91. *
  92. * A hidden code/lock is embedded in the wheel. Correct sequence [similar to a
  93. * rotational combination lock] reveals a secret address.
  94. *
  95. * D. Dang
  96. * Texas Instruments, Inc.
  97. * Ver 0.90 Feb 2011
  98. ******************************************************************************/
  99. final int TIME_OUT = 140;
  100. /*--------Dimensions & coordinates------------*/
  101. final int CANVAS_SIZE_X = 900;
  102. final int CANVAS_SIZE_Y = 580;
  103. final int OUT_CIRCLE_RADIUS = 248;
  104. final int IN_CIRCLE_RADIUS = 101;
  105. final int CENTER_CIRCLE_RADIUS = 37;
  106. final int CIRCLE_CENTER_X = 450;
  107. final int CIRCLE_CENTER_Y = 285;
  108. final int SOUND_ICON_X = 820;
  109. final int SOUND_ICON_Y = 20;
  110. /*--------Drawing definitions------------*/
  111. final int NUMBER_OF_SLICES = 16;
  112. final int BACKGROUND_COLOR = 170;
  113. final int TAP_SLICE_COLOR = -100;
  114. final int SLICE_TRANSPARENCY = 30;
  115. final int SLICE_TRANSPARENCY_OFFSET = 80;
  116. /*--------UART protocol definitions------------*/
  117. final int WAKE_UP_UART_CODE = 0xBE;
  118. final int WAKE_UP_UART_CODE2 = 0xEF;
  119. final int SLEEP_MODE_UART_CODE = 0xDE;
  120. final int SLEEP_MODE_UART_CODE2 = 0xAD;
  121. final int CENTER_BUTTON_CODE = 0x80;
  122. final int INVALID_WHEEL_POSITION = 0xFE;
  123. final int INVALID_GESTURE = 0xFD;
  124. final int GESTURE_START = 0xFC;
  125. final int GESTURE_STOP = 0xFB;
  126. final int GESTURE_POSITION_OFFSET = 0x20;
  127. final int WHEEL_POSITION_OFFSET = 0x30;
  128. final int NUMBER_OF_WHEEL_POSITIONS = 16;
  129. //final int INVALID_WHEEL_POSITION = -100;
  130. final int INVALID_GESTURE_DIRECTION = -100;
  131. final int GESTURE_CLOCKWISE = 1;
  132. final int GESTURE_COUNTERCLOCKWISE = -1;
  133. /*----------CapTouch-related variables----------------*/
  134. int gestureStartingPosition = INVALID_WHEEL_POSITION, gestureStoppingPosition = INVALID_WHEEL_POSITION;
  135. int[] gestureCoverPositions = new int[16];
  136. int gestureDirection = INVALID_GESTURE_DIRECTION;
  137. int gestureImmediateDirection = INVALID_GESTURE_DIRECTION;
  138. int allLit = 0;
  139. int inactivityCounter=0, sleeping=0, tapping=0, centerButton=0;
  140. int CenterButtonToggle=0;
  141. /*------Serial communication----------------*/
  142. int LaunchPadComPortFound = 0, numberOfLookingDots=0;
  143. Serial LaunchPad;
  144. /*--------- Visual & audio elements-----------*/
  145. PImage backgroundImage, innerCircleImage,innerCircleSelectedImage, innerCircleUnlockedImage ;
  146. int drawNumberEnabled = 0;
  147. Sample click,clickFound, clickOpen;
  148. int soundEnabled = 0;
  149. public void drawSlice(int sliceIndex, int sliceLevel)
  150. {
  151. int sliceAfter, sliceLabel;
  152. sliceLabel = sliceIndex;
  153. if (sliceIndex < 3)
  154. sliceIndex = sliceIndex + 16 - 4;
  155. else
  156. sliceIndex = sliceIndex - 4;
  157. sliceAfter = sliceIndex + 1;
  158. if (sliceAfter == NUMBER_OF_SLICES)
  159. sliceAfter = 0;
  160. noStroke();
  161. stroke(255);
  162. strokeWeight(4);
  163. if (sliceLevel == TAP_SLICE_COLOR)
  164. fill(160,160,160, 225);
  165. else
  166. fill(252,236,54, sliceLevel * SLICE_TRANSPARENCY + SLICE_TRANSPARENCY_OFFSET);
  167. arc(CIRCLE_CENTER_X, CIRCLE_CENTER_Y, OUT_CIRCLE_RADIUS*2, OUT_CIRCLE_RADIUS*2, (((float)sliceIndex)-0.5f) * 2 * PI /16, (((float)sliceIndex)+0.5f) * 2 * PI /16);
  168. line( CIRCLE_CENTER_X + cos( (((float)sliceIndex)-0.5f) * 2 * PI /16 ) * OUT_CIRCLE_RADIUS, CIRCLE_CENTER_Y + sin((((float)sliceIndex)-0.5f) * 2 * PI /16 ) * OUT_CIRCLE_RADIUS,
  169. CIRCLE_CENTER_X + cos( (((float)sliceIndex)-0.5f) * 2 * PI /16 ) * IN_CIRCLE_RADIUS, CIRCLE_CENTER_Y + sin((((float)sliceIndex)-0.5f) * 2 * PI /16 ) * IN_CIRCLE_RADIUS);
  170. line( CIRCLE_CENTER_X + cos( (((float)sliceIndex)+0.5f) * 2 * PI /16 ) * OUT_CIRCLE_RADIUS, CIRCLE_CENTER_Y + sin((((float)sliceIndex)+0.5f) * 2 * PI /16 ) * OUT_CIRCLE_RADIUS,
  171. CIRCLE_CENTER_X + cos( (((float)sliceIndex)+0.5f) * 2 * PI /16 ) * IN_CIRCLE_RADIUS, CIRCLE_CENTER_Y + sin((((float)sliceIndex)+0.5f) * 2 * PI /16 ) * IN_CIRCLE_RADIUS);
  172. if (drawNumberEnabled == 1)
  173. {
  174. fill(0);
  175. text( sliceLabel,
  176. CIRCLE_CENTER_X + cos( (((float)sliceIndex)) * 2 * PI /16 ) * (OUT_CIRCLE_RADIUS-40)-7,
  177. CIRCLE_CENTER_Y + sin( (((float)sliceIndex)) * 2 * PI /16 ) * (OUT_CIRCLE_RADIUS-40));
  178. }
  179. }
  180. public void drawCanvas()
  181. {
  182. int i;
  183. background(BACKGROUND_COLOR);
  184. image(backgroundImage, 0 ,0);
  185. fill(0,0,0,255);
  186. if (unlocked == 1)
  187. {
  188. fill(0);
  189. text("BoosterPack Unlocked",300,30);
  190. for (i=0;i<4;i++)
  191. drawSlice(code[i],4);
  192. fill(255);
  193. ellipse(CIRCLE_CENTER_X, CIRCLE_CENTER_Y, IN_CIRCLE_RADIUS*2 , IN_CIRCLE_RADIUS*2);
  194. image(innerCircleUnlockedImage, 0, 0);
  195. }
  196. }
  197. public void goToSleep()
  198. {
  199. tint(120,120,120,180);
  200. drawCanvas();
  201. tint(120,120,120,180);
  202. fill(255);
  203. textSize(20);
  204. text(".",20,30);
  205. text(".",28,30);
  206. text(".",35,30);
  207. textSize(25);
  208. text("z",47,30);
  209. textSize(30);
  210. text("z",65,30);
  211. textSize(35);
  212. text("z",85,30);
  213. textSize(40);
  214. text("z",108,30);
  215. textSize(30);
  216. noTint();
  217. sleeping = 1;
  218. inactivityCounter = TIME_OUT;
  219. }
  220. public void findLaunchPad()
  221. {
  222. String ComPortName ="";
  223. try
  224. {
  225. Process proc = Runtime.getRuntime().exec("FindAppUART.exe");
  226. proc.waitFor();
  227. int exitVal = proc.exitValue();
  228. // Get the first line from the process' STDOUT
  229. BufferedReader buf = new BufferedReader(new InputStreamReader(proc.getInputStream()));
  230. ComPortName = buf.readLine();
  231. if (ComPortName.substring(0,3).equals("COM") != true)
  232. ComPortName = "";
  233. else
  234. {
  235. LaunchPadComPortFound = 1;
  236. LaunchPad = new Serial(this, ComPortName, 9600);
  237. }
  238. }
  239. catch(Exception e)
  240. {
  241. println(e);
  242. }
  243. }
  244. public void promptLookingForLaunchPad()
  245. {
  246. fill(255,0,0);
  247. noStroke();
  248. rect(100,CANVAS_SIZE_Y/2-100,CANVAS_SIZE_X-120,200);
  249. fill(255);
  250. textSize(50);
  251. numberOfLookingDots++;
  252. if (numberOfLookingDots==5)
  253. numberOfLookingDots = 1;
  254. switch(numberOfLookingDots)
  255. {
  256. case 1: text("Looking for LaunchPad ", 175,CANVAS_SIZE_Y/2 ); break;
  257. case 2: text("Looking for LaunchPad . ", 175,CANVAS_SIZE_Y/2 ); break;
  258. case 3: text("Looking for LaunchPad .. ", 175,CANVAS_SIZE_Y/2 ); break;
  259. case 4: text("Looking for LaunchPad ...", 175,CANVAS_SIZE_Y/2 ); break;
  260. }
  261. }
  262. public void setup()
  263. {
  264. size(CANVAS_SIZE_X, CANVAS_SIZE_Y);
  265. background(255,0,0);
  266. Sonia.start(this);
  267. click = new Sample("click1.aiff");
  268. clickOpen = new Sample("open.aiff");
  269. clickFound = new Sample("unlock.aiff");
  270. click.setVolume(3);
  271. clickFound.setVolume(3);
  272. frameRate(3);
  273. backgroundImage = loadImage("background.png");
  274. innerCircleImage = loadImage("innerCircle.png");
  275. innerCircleSelectedImage = loadImage("innerCircleSelected.png");
  276. innerCircleUnlockedImage = loadImage("innerCircleUnlocked.png");
  277. findLaunchPad();
  278. if (LaunchPadComPortFound == 0)
  279. {
  280. fill(255);
  281. textSize(40);
  282. text("LaunchPad Capacitive Touch BoosterPack", 70,50);
  283. textSize(55);
  284. fill(0);
  285. text("User Experience Demo", 150,100);
  286. fill(0);
  287. textSize(25);
  288. text("1. Plug your Capacitive Touch BoosterPack into the LaunchPad", 150,CANVAS_SIZE_Y - 70);
  289. text("2. Connect your LaunchPad to the PC via USB", 150,CANVAS_SIZE_Y - 45);
  290. promptLookingForLaunchPad();
  291. }
  292. else
  293. {
  294. frameRate(30);
  295. goToSleep();
  296. }
  297. }
  298. public void draw()
  299. {
  300. int i;
  301. if (LaunchPadComPortFound==0)
  302. {
  303. findLaunchPad();
  304. if (LaunchPadComPortFound==1)
  305. {
  306. goToSleep();
  307. frameRate(30);
  308. }
  309. else
  310. promptLookingForLaunchPad();
  311. }
  312. else
  313. if(LaunchPad.available() >= 0)
  314. {
  315. int buf, buf1;
  316. buf = LaunchPad.read();
  317. buf1 = -1;
  318. if (buf>=0)
  319. {
  320. drawCanvas();
  321. textSize(30);
  322. sleeping = 0;
  323. inactivityCounter=0;
  324. tapping = 0 ;
  325. centerButton = 0;
  326. switch(buf)
  327. {
  328. case WAKE_UP_UART_CODE:
  329. while (buf1 <0)
  330. buf1 = LaunchPad.read();
  331. if (buf1==WAKE_UP_UART_CODE2)
  332. text("Proximity Sensor Wake Up",20,30);
  333. else
  334. {
  335. print("Error: invalid UART Wake up == ");
  336. println(buf1);
  337. }
  338. break;
  339. case SLEEP_MODE_UART_CODE:
  340. while (buf1 <0)
  341. buf1 = LaunchPad.read();
  342. if (buf1==SLEEP_MODE_UART_CODE2)
  343. {
  344. //tint(120,0,0,180);
  345. CenterButtonToggle = 0;
  346. backgroundImage = loadImage("background.png");
  347. innerCircleImage = loadImage("innerCircle.png");
  348. tint(120,120,120,180);
  349. drawCanvas();
  350. text("Good night!",20,30);
  351. sleeping = 1;
  352. noTint();
  353. }
  354. else
  355. {
  356. print("Error: invalid UART Sleep == ");
  357. println(buf1);
  358. }
  359. break;
  360. case CENTER_BUTTON_CODE:
  361. while (buf1 <0)
  362. buf1 = LaunchPad.read();
  363. if (buf==buf1)
  364. {
  365. if (unlocked==1)
  366. {
  367. unlocked = 0;
  368. link(secretURL);
  369. }
  370. CenterButtonToggle = 1 - CenterButtonToggle;
  371. if (CenterButtonToggle == 1)
  372. {
  373. innerCircleImage= loadImage("innerCircleSelected.png");
  374. backgroundImage = loadImage("backgroundSelected.png");
  375. }
  376. else
  377. {
  378. innerCircleImage= loadImage("innerCircle.png");
  379. backgroundImage = loadImage("background.png");
  380. }
  381. drawCanvas();
  382. centerButton = 1;
  383. }
  384. else
  385. {
  386. print("Error: invalid CENTER BUTTON code == ");
  387. println(buf1);
  388. }
  389. break;
  390. case GESTURE_STOP:
  391. while (buf1 <0)
  392. buf1 = LaunchPad.read();
  393. if (buf==buf1)
  394. {
  395. text("Gesture Released",20,30);
  396. gestureStartingPosition = INVALID_WHEEL_POSITION;
  397. gestureStoppingPosition = INVALID_WHEEL_POSITION;
  398. gestureDirection = INVALID_GESTURE_DIRECTION;
  399. allLit = 0;
  400. codeCheck = 0;
  401. codeLevel = 0;
  402. //unlocked = 0;
  403. }
  404. else
  405. {
  406. print("Error: invalid GESTURE_STOP code == ");
  407. println(buf1);
  408. }
  409. break;
  410. case GESTURE_START:
  411. while (buf1 <0)
  412. buf1 = LaunchPad.read();
  413. if ( (buf1 < GESTURE_POSITION_OFFSET ) || (buf1 > GESTURE_POSITION_OFFSET + NUMBER_OF_WHEEL_POSITIONS))
  414. {
  415. print("Error: invalid gesture start position == ");
  416. println(buf1);
  417. }
  418. else
  419. {
  420. text("Gesture Detected",20,30);
  421. buf1 = buf1 - GESTURE_POSITION_OFFSET;
  422. if (buf1<0)
  423. println(buf);
  424. gestureStartingPosition = buf1;
  425. gestureStoppingPosition = buf1;
  426. if (buf1 == code[0])
  427. codeCheck = 1;
  428. else
  429. codeCheck = -1;
  430. codeLevel = 0;
  431. changeDirection = 0;
  432. drawSlice(buf1, 1);
  433. fill(255);
  434. ellipse(CIRCLE_CENTER_X, CIRCLE_CENTER_Y, IN_CIRCLE_RADIUS*2 , IN_CIRCLE_RADIUS*2);
  435. image(innerCircleImage,0,0);
  436. }
  437. break;
  438. default: // data from LaunchPad is not code, but value
  439. if (buf > WHEEL_POSITION_OFFSET + NUMBER_OF_WHEEL_POSITIONS ) // Invalid Code
  440. {
  441. print("Error: invalid UART code == ");
  442. println(buf);
  443. }
  444. else
  445. /*---------------------WHEEL POSITION-----------------------*/
  446. if ((buf <= WHEEL_POSITION_OFFSET + NUMBER_OF_WHEEL_POSITIONS) && (buf >= WHEEL_POSITION_OFFSET )) // Tapping
  447. {
  448. while (buf1 <0)
  449. buf1 = LaunchPad.read();
  450. if (buf==buf1)
  451. {
  452. buf = buf - WHEEL_POSITION_OFFSET;
  453. text("Press @ ",10,30);
  454. text(buf,125,30);
  455. tapping = 1;
  456. drawSlice(buf, TAP_SLICE_COLOR);
  457. fill(255);
  458. ellipse(CIRCLE_CENTER_X, CIRCLE_CENTER_Y, IN_CIRCLE_RADIUS*2 , IN_CIRCLE_RADIUS*2);
  459. image(innerCircleImage, 0,0);
  460. }
  461. else
  462. {
  463. print("Error: invalid WHEEL POSITION code == ");
  464. println(buf);
  465. }
  466. }
  467. else
  468. /*---------------------GESTURE DATA-----------------------*/
  469. if (buf < GESTURE_POSITION_OFFSET ) // Gesturing
  470. if (gestureStartingPosition != INVALID_WHEEL_POSITION)
  471. {
  472. if (buf>=NUMBER_OF_WHEEL_POSITIONS) // Determine orientation: binary value 00000xxx = CW, 00001xxx = CC
  473. {
  474. buf -= NUMBER_OF_WHEEL_POSITIONS;
  475. text(buf, 20,30);
  476. text("Counter-Clockwise",55,30);
  477. gestureImmediateDirection = GESTURE_COUNTERCLOCKWISE;
  478. }
  479. else
  480. {
  481. text(buf, 20,30);
  482. text("Clockwise",55,30);
  483. gestureImmediateDirection = GESTURE_CLOCKWISE;
  484. }
  485. while (buf1 <0)
  486. buf1 = LaunchPad.read();
  487. if ( (buf1 >= GESTURE_POSITION_OFFSET ) && (buf1 < GESTURE_POSITION_OFFSET + NUMBER_OF_WHEEL_POSITIONS))
  488. {
  489. buf1 = buf1 - GESTURE_POSITION_OFFSET;
  490. if (gestureDirection == INVALID_GESTURE_DIRECTION)
  491. gestureDirection = gestureImmediateDirection;
  492. // if (gestureImmediateDirection != gestureDirection)
  493. // gestureCoverPositions[gestureStoppingPosition] = 0;
  494. //
  495. while (buf-->0)
  496. {
  497. if (gestureStoppingPosition == gestureStartingPosition) //If moving from the starting position
  498. if (gestureDirection != gestureImmediateDirection) //If moving against the current direction
  499. {
  500. if (allLit == 0) //Starting at zero? Change direction
  501. gestureDirection = gestureImmediateDirection;
  502. else //Back to a previous revolution?
  503. allLit--;
  504. }
  505. gestureStoppingPosition += gestureImmediateDirection;
  506. if (gestureStoppingPosition == NUMBER_OF_WHEEL_POSITIONS)
  507. gestureStoppingPosition = 0;
  508. if (gestureStoppingPosition < 0)
  509. gestureStoppingPosition = NUMBER_OF_WHEEL_POSITIONS-1;
  510. if (gestureStoppingPosition == gestureStartingPosition) //If moving to the starting position
  511. {
  512. if (gestureImmediateDirection == gestureDirection) //complete a revolution?
  513. allLit += 1;
  514. else
  515. if (allLit == 0) //Back to zero
  516. gestureDirection = INVALID_GESTURE_DIRECTION;
  517. //Undo
  518. }
  519. }
  520. for ( i = 0; i < NUMBER_OF_WHEEL_POSITIONS; i++)
  521. gestureCoverPositions[i] = allLit;
  522. i = gestureStartingPosition;
  523. while (i != gestureStoppingPosition)
  524. {
  525. gestureCoverPositions[i]= allLit + 1;
  526. i += gestureDirection;
  527. if (i<0)
  528. i = NUMBER_OF_WHEEL_POSITIONS-1;
  529. if (i == NUMBER_OF_WHEEL_POSITIONS)
  530. i = 0;
  531. }
  532. gestureCoverPositions[i]= allLit + 1;
  533. for ( i = 0; i < NUMBER_OF_WHEEL_POSITIONS; i++)
  534. if (gestureCoverPositions[i] > 0)
  535. drawSlice(i, gestureCoverPositions[i]);
  536. fill(255);
  537. ellipse(CIRCLE_CENTER_X, CIRCLE_CENTER_Y, IN_CIRCLE_RADIUS*2 , IN_CIRCLE_RADIUS*2);
  538. image(innerCircleImage,0,0);
  539. if (changeDirection !=0)
  540. {
  541. if (gestureImmediateDirection != changeDirection)
  542. codeCheck = -1;
  543. changeDirection = 0;
  544. }
  545. if (soundEnabled == 1)
  546. click.play();
  547. if (codeModeEnabled == 1)
  548. {
  549. if (codeCheck==1)
  550. {
  551. codeValid = 1;
  552. for ( i = 0; i < NUMBER_OF_WHEEL_POSITIONS; i++)
  553. if (gestureCoverPositions[i] != codeValues[codeLevel][i])
  554. codeValid = 0;
  555. if (codeRotate[codeLevel] != gestureImmediateDirection)
  556. codeValid = 0;
  557. if (codeValid == 1)
  558. {
  559. if (codeLevel++ < 2)
  560. {
  561. changeDirection = -gestureImmediateDirection;
  562. if (soundEnabled == 1)
  563. clickFound.play();
  564. }
  565. else
  566. {
  567. fill(0);
  568. text("Unlocked!!",400,30);
  569. text("Press Center",500,90);
  570. unlocked = 1;
  571. codeLevel = 0;
  572. codeCheck = -1;
  573. if (soundEnabled == 1)
  574. clickOpen.play();
  575. }
  576. }
  577. }
  578. }
  579. }
  580. // invalid gesture data
  581. else
  582. {
  583. print("Error: invalid gesture position data == ");
  584. println(buf1);
  585. }
  586. }
  587. else
  588. { // Should not happen
  589. buf = buf - GESTURE_POSITION_OFFSET;
  590. println("Invalid UART Data, not expecting such data");
  591. }
  592. break;
  593. }
  594. }
  595. else
  596. {
  597. if (++inactivityCounter==TIME_OUT)
  598. {
  599. if (sleeping==1)
  600. {
  601. goToSleep();
  602. }
  603. else
  604. drawCanvas();
  605. }
  606. }
  607. }
  608. }
  609. public void mouseReleased()
  610. {
  611. if ( (mouseX-CANVAS_SIZE_X/2)*(mouseX-CANVAS_SIZE_X/2) + (mouseY-CANVAS_SIZE_Y/2)*(mouseY-CANVAS_SIZE_Y/2) < IN_CIRCLE_RADIUS * IN_CIRCLE_RADIUS )
  612. if (LaunchPadComPortFound ==1)
  613. {
  614. soundEnabled = 1 - soundEnabled;
  615. codeModeEnabled = 1 - codeModeEnabled;
  616. drawNumberEnabled = 1 - drawNumberEnabled;
  617. }
  618. }
  619. /*---------Embedded code validation------------------*/
  620. // Ideally nobody should ever bother scrolling down here
  621. // But good job, you've found it the easy way!
  622. // Anyways, don't spoil the fun for others would ya?
  623. int[] code = { 0, 4, 3, 0};
  624. int[] codeRotate = {1, -1, 1};
  625. int[][] codeValues = { {1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  626. {1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  627. {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
  628. String secretURL = "http://ti.com/msp430rr";
  629. int codeCheck, codeLevel, codeValid, changeDirection, unlocked=0, codeModeEnabled = 0;
  630. static public void main(String args[]) {
  631. PApplet.main(new String[] { "--bgcolor=#E2E2E2", "CapTouch_BoosterPack_UserExperience_GUI" });
  632. }
  633. }