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.

143 lines
4.0 KiB

5 years ago
  1. /*
  2. * LaunchPad_Temp_GUI.pde
  3. *
  4. * LaunchPad Temperature GUI
  5. *
  6. * Copyright (C) {YEAR} Texas Instruments Incorporated - http://www.ti.com/
  7. *
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. *
  13. * Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. *
  16. * Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the
  19. * distribution.
  20. *
  21. * Neither the name of Texas Instruments Incorporated nor the names of
  22. * its contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  26. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  27. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  28. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  29. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  30. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  31. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  32. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  33. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  34. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  35. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. */
  38. /**
  39. * LaunchPad GUI
  40. *
  41. * Select COM port that LaunchPad is connected to
  42. * receive serial communication from LaunchPad for
  43. * instantaneous temperature readings.
  44. *
  45. **/
  46. PFont fontA;
  47. char instruct;
  48. color backColor;
  49. int dataRead;
  50. boolean portChosen = false;
  51. int COMPort;
  52. int [] keyIn = new int[3];
  53. int i, keyIndex=0;
  54. // The serial port:
  55. Serial myPort;
  56. void setup()
  57. {
  58. //setup window
  59. size(1000, 500);
  60. smooth();
  61. //load font
  62. // Set the font, its size (in units of pixels), and alignment
  63. textAlign(CENTER);
  64. //Set background color
  65. color baseColor = color(70);
  66. backColor = baseColor;
  67. //import serial library
  68. import processing.serial.*;
  69. // List all the available serial ports, then give prompt
  70. println(Serial.list());
  71. println("Please type in the serial COM port that your LaunchPad is connected to.");
  72. background(backColor);
  73. stroke(255);
  74. textSize(13);
  75. text("Please, select the COM port that your LaunchPad is connected to.", 265, 20);
  76. textAlign(LEFT);
  77. for(i=0; i<Serial.list().length; i++){
  78. text("[" + i + "] " + Serial.list()[i], 215, 38+13*i);
  79. }
  80. textSize(30);
  81. text("# =",20, 350);
  82. //wait for keypress --> Refer to void keyPressed()
  83. }
  84. void draw()
  85. {
  86. if(portChosen == true){
  87. dataRead= myPort.read();
  88. if(dataRead != -1){
  89. //clear previous temperature reading from screen
  90. background(backColor);
  91. stroke(255);
  92. //Update console
  93. print("Temp: ");
  94. print(dataRead);
  95. println("°");
  96. //Update on screen GUI
  97. text("Current Temperature: ", 420, 60);
  98. text(dataRead, 835, 60);
  99. text("°", 900, 60);
  100. }
  101. }
  102. }
  103. //wait for key press. Once key is entered, initialize serial com port
  104. void keyPressed() {
  105. if(portChosen == false){
  106. if (key != 10) //Enter
  107. {
  108. keyIn[keyIndex++] = key-48;
  109. textSize(30);
  110. text(keyIn[keyIndex-1],100 + (keyIndex*20), 350);
  111. }
  112. else
  113. {
  114. COMPort = 0;
  115. for (i = 0; i < keyIndex; i++)
  116. COMPort = COMPort * 10 + keyIn[i];
  117. println(COMPort);
  118. myPort = new Serial(this, Serial.list()[COMPort], 2400);
  119. portChosen = true;
  120. textSize( 60); // change font size & alignment for temp readings
  121. textAlign(CENTER);
  122. }
  123. }
  124. }