Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import hypermedia.net.*;
- UDP udp;
- int lf = 10; // ASCII linefeed
- boolean firstItt;
- int rectX;
- int rectY;
- int rectH;
- int rectL;
- int rectColor;
- int saveRectColor;
- int saveTextColor;
- int titleSize = 32;
- int subTitleSize = 18;
- int valueSize = 12;
- boolean rectOver = false;
- boolean recordingQ = false;
- boolean fileClose = false;
- String currentLine [];
- String incomingLine [];
- String [] recordingBuffer;
- void setup() {
- size(1000,500);
- udp = new UDP(this, 5555, "192.168.1.78");
- udp.listen(true);
- firstItt = true;
- // File Saving Stuff
- rectX = rectY = 10;
- rectL = 100;
- rectH = 20;
- rectColor = color(100);
- saveRectColor = color(#1FFC79);
- saveTextColor = color(#FC1F26);
- recordingBuffer = new String[0];
- currentLine = new String[28];
- }
- void draw() {
- background(#3D86BC);
- // If its the first iteration, delay until a serial string is available
- if(firstItt){
- delay(1000);
- firstItt = !firstItt;
- }
- update(mouseX, mouseY);
- fill(255);
- // Title
- textSize(titleSize);
- text("Joule Serial Monitor", 250,30);
- textSize(10);
- //text(inString, 10, 40);
- // Informational Display
- textSize(subTitleSize);
- text("Battery Status", 10,50);
- textSize(valueSize);
- int vertSpacing = 13;
- int vert = 75;
- text("Battery mV: " + currentLine[16], 10, vert);
- text("Battery mA: " + currentLine[21], 10, vert + vertSpacing);
- text("Cell 0 mV: " + currentLine[12], 10, vert + 2*vertSpacing);
- text("Cell 1 mV: " + currentLine[13], 10, vert + 3*vertSpacing);
- text("Cell 2 mV: " + currentLine[14], 10, vert + 4*vertSpacing);
- text("Cell 3 mV: " + currentLine[15], 10, vert + 5*vertSpacing);
- textSize(subTitleSize);
- text("Charging Status", 10, 170);
- textSize(valueSize);
- int vert2 = 195;
- text("Charging mV: " + currentLine[24], 10, vert2);
- text("Charging mA: " + currentLine[25], 10, vert2 + vertSpacing);
- text("Tether mV: " + currentLine[22], 10, vert2 + 3*vertSpacing);
- text("Tether mA: " + currentLine[23], 10, vert2 + 2*vertSpacing);
- text("Tether mV: " + currentLine[22], 10, vert2 + 3*vertSpacing);
- textSize(subTitleSize);
- text("Temperatures", 10, 259);
- textSize(valueSize);
- int vert3 = 284;
- text("Proc Temp: " + currentLine[17], 10, vert3);
- text("BMS Temp: " + currentLine[18], 10, vert3 + vertSpacing);
- text("Cell Therm Count: " + currentLine[19], 10, vert3 + 2*vertSpacing);
- text("FET Therm Count: " + currentLine[20], 10, vert3 + 3*vertSpacing);
- textSize(subTitleSize);
- text("Miscellaneous", 10, 348);
- textSize(valueSize);
- int vert4 = 373;
- text("mS since Start: " + currentLine[1], 10, vert4);
- text("PWM Count: " + currentLine[2], 10, vert4 + vertSpacing);
- text("BMS Error Status: " + currentLine[3], 10, vert4 + 2*vertSpacing);
- text("Proc IO Status: " + currentLine[4], 10, vert4 + 3*vertSpacing);
- text("BMS 1 Status: " + currentLine[5], 10, vert4 + 4*vertSpacing);
- text("BMS 2 Status: " + currentLine[6], 10, vert4 + 5*vertSpacing);
- text("BMS 3 Status: " + currentLine[7], 10, vert4 + 6*vertSpacing);
- text("BMS 4 Status:" + currentLine[8], 10, vert4 + 7*vertSpacing);
- text("BMS CB Status: " + currentLine[9], 10, vert4 + 8*vertSpacing);
- text("BMS FET Status: " + currentLine[10], 10, vert4 + 9*vertSpacing);
- // Saving Data to File
- stroke(255);
- if(recordingQ){
- fill(saveRectColor);
- }
- else{
- fill(100);
- }
- rect(rectX,rectY,rectL,rectH, 5);
- fill(saveTextColor);
- textSize(13);
- text("Recording", 25, 24);
- }
- void update(int x, int y) {
- if ( overRect(rectX, rectY, rectL, rectH) ) {
- rectOver = true;
- } else {
- rectOver = false;
- }
- }
- boolean overRect(int x, int y, int w, int h) {
- if (mouseX >= x && mouseX <= x+w &&
- mouseY >= y && mouseY <= y+h) {
- return true;
- } else {
- return false;
- }
- }
- void mousePressed() {
- if (rectOver && recordingQ) {
- recordingQ = !recordingQ;
- saveToFile();
- println("saving");
- println(recordingQ);
- }
- else if (rectOver) {
- recordingQ = !recordingQ;
- println(recordingQ);
- }
- }
- void record(String newString){
- recordingBuffer = append(recordingBuffer, newString);
- }
- void saveToFile(){
- String fileName = str(year()) + "_" + str(month()) + "_" + str(day()) + "_" + str(hour()) + "_" + str(minute()) + "_" + str(second()) + ".txt";
- println(fileName);
- saveStrings(fileName, recordingBuffer);
- recordingBuffer = new String[0];
- }
- void receive( byte[] data ) {
- String inString = new String( data );
- incomingLine = split(inString, ',');
- // If the incomingLine has fields missing then don't use it and repeat the previous
- // Improvement would be to flag the repeated line
- if(incomingLine.length == 28) {
- record(inString);
- currentLine = incomingLine;
- }
- // print the result
- println(incomingLine.length);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement