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.

168 lines
4.6 KiB

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