Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.93 KB | None | 0 0
  1. import hypermedia.net.*;
  2.  
  3.  
  4. UDP udp;
  5. int lf = 10; // ASCII linefeed
  6. boolean firstItt;
  7.  
  8.  
  9.  
  10. int rectX;
  11. int rectY;
  12. int rectH;
  13. int rectL;
  14. int rectColor;
  15. int saveRectColor;
  16. int saveTextColor;
  17. int titleSize = 32;
  18. int subTitleSize = 18;
  19. int valueSize = 12;
  20. boolean rectOver = false;
  21. boolean recordingQ = false;
  22. boolean fileClose = false;
  23.  
  24.  
  25. String currentLine [];
  26. String incomingLine [];
  27. String [] recordingBuffer;
  28.  
  29.  
  30.  
  31.  
  32. void setup() {
  33. size(1000,500);
  34.  
  35. udp = new UDP(this, 5555, "192.168.1.78");
  36. udp.listen(true);
  37.  
  38. firstItt = true;
  39.  
  40. // File Saving Stuff
  41. rectX = rectY = 10;
  42. rectL = 100;
  43. rectH = 20;
  44. rectColor = color(100);
  45. saveRectColor = color(#1FFC79);
  46. saveTextColor = color(#FC1F26);
  47. recordingBuffer = new String[0];
  48. currentLine = new String[28];
  49. }
  50.  
  51. void draw() {
  52. background(#3D86BC);
  53.  
  54. // If its the first iteration, delay until a serial string is available
  55. if(firstItt){
  56. delay(1000);
  57. firstItt = !firstItt;
  58. }
  59.  
  60.  
  61. update(mouseX, mouseY);
  62.  
  63. fill(255);
  64. // Title
  65. textSize(titleSize);
  66. text("Joule Serial Monitor", 250,30);
  67.  
  68. textSize(10);
  69. //text(inString, 10, 40);
  70.  
  71. // Informational Display
  72. textSize(subTitleSize);
  73. text("Battery Status", 10,50);
  74.  
  75. textSize(valueSize);
  76. int vertSpacing = 13;
  77. int vert = 75;
  78. text("Battery mV: " + currentLine[16], 10, vert);
  79. text("Battery mA: " + currentLine[21], 10, vert + vertSpacing);
  80. text("Cell 0 mV: " + currentLine[12], 10, vert + 2*vertSpacing);
  81. text("Cell 1 mV: " + currentLine[13], 10, vert + 3*vertSpacing);
  82. text("Cell 2 mV: " + currentLine[14], 10, vert + 4*vertSpacing);
  83. text("Cell 3 mV: " + currentLine[15], 10, vert + 5*vertSpacing);
  84.  
  85.  
  86. textSize(subTitleSize);
  87. text("Charging Status", 10, 170);
  88.  
  89. textSize(valueSize);
  90. int vert2 = 195;
  91. text("Charging mV: " + currentLine[24], 10, vert2);
  92. text("Charging mA: " + currentLine[25], 10, vert2 + vertSpacing);
  93. text("Tether mV: " + currentLine[22], 10, vert2 + 3*vertSpacing);
  94. text("Tether mA: " + currentLine[23], 10, vert2 + 2*vertSpacing);
  95. text("Tether mV: " + currentLine[22], 10, vert2 + 3*vertSpacing);
  96.  
  97.  
  98. textSize(subTitleSize);
  99. text("Temperatures", 10, 259);
  100.  
  101. textSize(valueSize);
  102. int vert3 = 284;
  103. text("Proc Temp: " + currentLine[17], 10, vert3);
  104. text("BMS Temp: " + currentLine[18], 10, vert3 + vertSpacing);
  105. text("Cell Therm Count: " + currentLine[19], 10, vert3 + 2*vertSpacing);
  106. text("FET Therm Count: " + currentLine[20], 10, vert3 + 3*vertSpacing);
  107.  
  108.  
  109. textSize(subTitleSize);
  110. text("Miscellaneous", 10, 348);
  111.  
  112. textSize(valueSize);
  113. int vert4 = 373;
  114. text("mS since Start: " + currentLine[1], 10, vert4);
  115. text("PWM Count: " + currentLine[2], 10, vert4 + vertSpacing);
  116. text("BMS Error Status: " + currentLine[3], 10, vert4 + 2*vertSpacing);
  117. text("Proc IO Status: " + currentLine[4], 10, vert4 + 3*vertSpacing);
  118. text("BMS 1 Status: " + currentLine[5], 10, vert4 + 4*vertSpacing);
  119. text("BMS 2 Status: " + currentLine[6], 10, vert4 + 5*vertSpacing);
  120. text("BMS 3 Status: " + currentLine[7], 10, vert4 + 6*vertSpacing);
  121. text("BMS 4 Status:" + currentLine[8], 10, vert4 + 7*vertSpacing);
  122. text("BMS CB Status: " + currentLine[9], 10, vert4 + 8*vertSpacing);
  123. text("BMS FET Status: " + currentLine[10], 10, vert4 + 9*vertSpacing);
  124.  
  125.  
  126. // Saving Data to File
  127. stroke(255);
  128. if(recordingQ){
  129. fill(saveRectColor);
  130. }
  131. else{
  132. fill(100);
  133. }
  134. rect(rectX,rectY,rectL,rectH, 5);
  135.  
  136. fill(saveTextColor);
  137. textSize(13);
  138. text("Recording", 25, 24);
  139.  
  140. }
  141.  
  142. void update(int x, int y) {
  143. if ( overRect(rectX, rectY, rectL, rectH) ) {
  144. rectOver = true;
  145. } else {
  146. rectOver = false;
  147. }
  148. }
  149.  
  150. boolean overRect(int x, int y, int w, int h) {
  151. if (mouseX >= x && mouseX <= x+w &&
  152. mouseY >= y && mouseY <= y+h) {
  153. return true;
  154. } else {
  155. return false;
  156. }
  157. }
  158.  
  159. void mousePressed() {
  160. if (rectOver && recordingQ) {
  161. recordingQ = !recordingQ;
  162.  
  163. saveToFile();
  164. println("saving");
  165. println(recordingQ);
  166. }
  167. else if (rectOver) {
  168. recordingQ = !recordingQ;
  169. println(recordingQ);
  170. }
  171. }
  172.  
  173.  
  174. void record(String newString){
  175. recordingBuffer = append(recordingBuffer, newString);
  176. }
  177.  
  178. void saveToFile(){
  179. String fileName = str(year()) + "_" + str(month()) + "_" + str(day()) + "_" + str(hour()) + "_" + str(minute()) + "_" + str(second()) + ".txt";
  180. println(fileName);
  181. saveStrings(fileName, recordingBuffer);
  182. recordingBuffer = new String[0];
  183. }
  184.  
  185.  
  186. void receive( byte[] data ) {
  187.  
  188. String inString = new String( data );
  189.  
  190. incomingLine = split(inString, ',');
  191.  
  192. // If the incomingLine has fields missing then don't use it and repeat the previous
  193. // Improvement would be to flag the repeated line
  194. if(incomingLine.length == 28) {
  195. record(inString);
  196. currentLine = incomingLine;
  197. }
  198.  
  199. // print the result
  200. println(incomingLine.length);
  201.  
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement