From 5f433563bf37aa6b8ee308061846a6c300424695 Mon Sep 17 00:00:00 2001 From: aster94 Date: Wed, 30 Jan 2019 23:44:49 +0100 Subject: [PATCH] reworking of almost everything --- Computer_Interface/Computer_Interface.pde | 963 ++++------------------ Computer_Interface/DrawFunctions.pde | 234 ++++++ Computer_Interface/MouseEvents.pde | 548 ++++++++++++ 3 files changed, 965 insertions(+), 780 deletions(-) create mode 100644 Computer_Interface/DrawFunctions.pde create mode 100644 Computer_Interface/MouseEvents.pde diff --git a/Computer_Interface/Computer_Interface.pde b/Computer_Interface/Computer_Interface.pde index d330b72..4ac3d41 100644 --- a/Computer_Interface/Computer_Interface.pde +++ b/Computer_Interface/Computer_Interface.pde @@ -4,7 +4,7 @@ //uncomment the line where your board is connected //String LA_port = "/dev/ttyACM0"; //linux DFU //String LA_port = "/dev/ttyUSB0"; //linux Serial -String LA_port = "COM5"; //windows +String LA_port = "COM3"; //windows //Uncomment the board that you are using //String board = "MEGA"; @@ -13,6 +13,10 @@ String board = "UNO"; //String board = "ESP8266"; //String board = "CUSTOM" +//samples = 10; + +String image_format = ".jpg"; // supported jpt, tif + /*------------------END SETUP-----------------*/ //////////////////////////////////////////////// @@ -70,14 +74,14 @@ String board = "UNO"; 35 -------> OFF -------> DigitalPIN 32 -------> OFF -------> OFF 36 -------> OFF -------> DigitalPIN 31 -------> OFF -------> OFF 37 -------> OFF -------> DigitalPIN 30 -------> OFF -------> OFF - Any other -------> OFF -------> OFF -------> OFF -------> OFF + Any other -----> OFF -------> OFF -------> OFF -------> OFF */ +// import needed modules import processing.serial.*; import java.util.Arrays; -Serial board_port; -//colors: +// colors: int white = 255; int black = 0; int green = #00FF00; @@ -86,12 +90,11 @@ int grey = 150; // shift, reducer and millisecond view float reducer = 1.0; -boolean milliseconds = true; +String time_format = "ms"; float xShift; -// start point in the processing window -float xEdge = 60; -float yEdge = 10; +float xEdge; // starting points from left edge +float yEdge = 10; // starting point from top edge float xEnd; float oldxEnd; float[] xPos = new float[16]; @@ -102,7 +105,8 @@ float ySave = yEdge; boolean textCovered; boolean drawTimes = true; -// Serial from mcu +// Serial from MCU +Serial board_port; int samples; int event; int initialState[] = new int[3]; @@ -120,46 +124,170 @@ int index1; int index2; int index3; boolean refresh = true; -int[] ChannelCursor1CurrentEvent0 = new int[2]; +int[] ChannelCursor1CurrentEvent0 = new int[2]; float CurrentEventFloat = 0; boolean IsAnyChannelMarked = false; -//buttons and others -int button1X = 8; -int button2X = 8; -int button3X = 80; -int button4X = 200; -int button5X = 270; -int buttonY; -int buttonH = 20; -int smallButtonW = 50; -int bigButtonW = 100; -int graphBoxH; -int textBoxH; -int immage = 1; -int corner = 10; +// screen size +int x_screen_size = 1300; +int y_screen_size = 700; + +int immage_number = 1; + String s; boolean initial = true; // bar scroll -int handleFill = grey; -float handleX; -float handleY; -float handleW = 20; -float handleH = 15; boolean isDraggable = false; +// processing doesn't have struct so we use classes https://forum.processing.org/one/topic/is-there-anything-like-a-struct-in-processing-language.html +class Box +{ + int from_left; + int from_top; + int width; + int height; + void clear() + { + stroke(white); // no borders + fill(black); + rect(from_left, from_top, width, height); + } +} + +//boolean box_left_drawn = false; +Box box_pin_names = new Box(); // box for the pin names and number +Box box_scroll_bar = new Box(); // a narrow box for the scroll bar +Box box_bottom = new Box(); // box for some settings and a very simple User Interface (UI) +Box box_graph = new Box(); // box for the core of this program + +class Button +{ + int from_left; + int from_top; + int width; + int height; + int corners = 5; + String text; + void draw() + { + fill(grey); + rect(from_left, from_top, width, height, corners); + fill(white); + text(text, from_left + 3, from_top + 14); // for center the text in the button + } +} + +Button button_start = new Button(); +Button button_time_draw = new Button(); +Button button_time_format = new Button(); +Button button_reducer = new Button(); +Button button_save = new Button(); +Button scroll_bar = new Button(); // tecnically it is not a button but we use the same class + +// necessary to have the size of the screen as a variables https://processing.org/reference/settings_.html +void settings() +{ + // reduce the screen size in small screen no need to check y_screen_size because it is set to 600 + // according to wikipedia is the lowest https://en.wikipedia.org/wiki/Display_resolution#Current_standards + if (x_screen_size > displayWidth) + { + x_screen_size = 800; + } + size(x_screen_size, y_screen_size); +} + +void pint_box(Box b) +{ + print("from_left: "); + println(b.from_left); + print("from_top: "); + println(b.from_top); + print("width: "); + println(b.width); + print("height: "); + println(b.height); +} + void setup() { - //p = new Serial(this, Serial.list()[0], 115200); - board_port = new Serial(this, LA_port, 115200); - board_port.bufferUntil('\n'); - - size(1300, 700); + //settings(); no need to call it background(black); smooth(4); - xShift = (width - handleW) / 2; - //Here you chose the pins that yuo want to show in the Logic Analizer. Put 00 to OFF the channel. + + // boxes + box_bottom.height = 50; + box_bottom.width = width; + + box_pin_names.height = y_screen_size - box_bottom.height; + box_pin_names.width = 60; //xEdge + + box_scroll_bar.height = 15; + box_scroll_bar.width = width - box_pin_names.width; + + box_graph.height = height - box_bottom.height - box_scroll_bar.height; + box_graph.width = width - box_pin_names.width; + + box_bottom.from_left = 0; + box_bottom.from_top = box_pin_names.height; + + box_pin_names.from_left = 0; + box_pin_names.from_top = 0; + + box_scroll_bar.from_left = box_pin_names.width; + box_scroll_bar.from_top = box_graph.height; + + box_graph.from_left = box_pin_names.width; + box_graph.from_top = 0; + + xEdge = box_graph.from_left; + + // Serial + board_port = new Serial(this, LA_port, 115200); // don't change the baudrate otherwise you have to change also the MCU code + board_port.bufferUntil('\n'); + + //todo + yBottom = box_graph.from_top; + int button_y_position = y_screen_size - 30; + xShift = (width - scroll_bar.width) / 2; + + // Buttons + button_start.from_left = 10; + button_start.from_top = button_y_position; + button_start.width = 50; + button_start.height = 20; + button_start.text = "Start"; + + button_time_draw.from_left = 80; + button_time_draw.from_top = button_y_position; + button_time_draw.width = 50; + button_time_draw.height = 20; + button_time_draw.text = "Draw Times: " + str(drawTimes); + + button_time_format.from_left = 240; + button_time_format.from_top = button_y_position; + button_time_format.width = 50; + button_time_format.height = 20; + button_time_format.text = time_format; + + button_reducer.from_left = 300; + button_reducer.from_top = button_y_position; + button_reducer.width = 50; + button_reducer.height = 20; + button_reducer.text = "Reducer: " + str(reducer); + + button_save.from_left = 400; + button_save.from_top = button_y_position; + button_save.width = 50; + button_save.height = 20; + button_save.text = "Save"; + + scroll_bar.width = 20; + scroll_bar.height = 15; + scroll_bar.from_left = int(xEdge); + scroll_bar.from_top = box_bottom.from_top - scroll_bar.height; + + //Here you chose the pins that yuo want to show in the Logic Analizer. Put 0 to OFF the channel. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // _____ _____ _ _ _ _ // | __ \_ _| \ | | /\ (_) | | @@ -186,7 +314,7 @@ void setup() PinAssignment[13] = 25; PinAssignment[14] = 26; PinAssignment[15] = 27; - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// for (int i = 0; i < 16; i++) { if (board == "MEGA") @@ -270,7 +398,6 @@ void setup() break; } } - else if (board == "UNO") { switch (PinAssignment[i]) @@ -295,7 +422,6 @@ void setup() break; } } - else if (board == "STM32F1") { switch (PinAssignment[i]) @@ -375,245 +501,33 @@ void setup() } } } - graphBoxH = height - 50; - textBoxH = height - 35; - yBottom = graphBoxH - 20; - buttonY = textBoxH + 8; - handleX = xEdge; - handleY = graphBoxH; } -void cleanGraph() -{ - noStroke(); // no borders - fill(black); - rect(xEdge, 0, width, graphBoxH); // cancel the graph - stroke(green); // green lines - Arrays.fill(xPos, 0); // reset start point of the graph - textCovered = false; -} -void drawCursorChannel(boolean CursorEnable) -{ - if (CursorEnable) - { - fill(50); - stroke(75); - if (ChannelCursor1CurrentEvent0[1] == 16) // This variable is used to define the channel on which we move or have marked, in this part we draw the rectangle that emphasizes a channel. - { - rect(0, yBottom - 12, width - xEdge, 34); - } - else - { - rect(0, yEdge + 36 * ChannelCursor1CurrentEvent0[1] - 2, width - xEdge, 34); - } - stroke(green); - } -} -void DrawChannelSignals() -{ -float firstchange; -boolean cares; -for (int i = 0; i < samples; i++) - { - cares = false; - firstchange = 0; - yPos = yEdge; // reset position - for (int n = 0; n < 16; n++) - { - if (PinArduinoNames[n] != 0) // draw only used pins - { - s = str(PinAssignment[n]); - index1 = s.charAt(1) - '0'; - index2 = s.charAt(0) - '1'; - //printArray(state[0][0]); - //print(state[i][index1][index2]+" , "); - if (state[i][index1][index2]) - { - cares = true; - if (firstchange == 0) - { - firstchange = yPos; - } - ySave = yPos; // save y value - - if (i == 0) // this is the first state - { - if (isLowInit[index1][index2]) // pin high - { - yDiff = yPos; - yPos += 30; - } - else // low - { - yDiff = yPos + 30; - } - isLow[index1][index2] = isLowInit[index1][index2]; - //println(isLowInit[index1][index2]); - } - else // all the others - { - if (isLow[index1][index2]) // pin high - { - yDiff = yPos; - yPos += 30; - isLow[index1][index2] = false; - } - else // low - { - yDiff = yPos + 30; - isLow[index1][index2] = true; - } - } - - // finally we draw the lines - line(xPos[n] + xShift, yPos, xTime[i] + xShift, yPos); // straight line - line(xTime[i] + xShift, yPos, xTime[i] + xShift, yDiff); // vertical line - - xPos[n] = xTime[i]; // save last position of the line for the pin - yPos = ySave; // load the initial value of the y - } - } - yPos += 36; // go to the next pin - } - // Text times - if ((drawTimes && cares) || i == 0) - { - if (ChannelCursor1CurrentEvent0[0] == i) - { - stroke(red); - fill(red); - } - else - { - stroke(grey); - fill(grey); - } - textSize(10); - textCovered = !textCovered; - dashline(xTime[i] + xShift, firstchange, xTime[i] + xShift, yBottom, spacing); - text(round(usTime[i]), xTime[i] + xShift + 2, (textCovered == true) ? yBottom : yBottom + 10); //write on different height - stroke(green); - } - } -} - -void drawText() -{ - stroke(white); // white borders - fill(black); - rect(0, 0, xEdge, graphBoxH); // clean left side - rect(xEdge, graphBoxH, width, handleH); // clean bar scroll - rect(0, textBoxH, width, height); // clean bottom side - - // write name of the pins - fill(white); - textSize(14); - - int x = 5; - int y = 30; - - for (byte i = 0; i < 16; i++) - { - line(x, y - 20, xEdge, y - 20); - line(x, y + 10, xEdge, y + 10); - stroke(#EF7F1A); - dashline(xEdge, y - 23, width, y - 23, spacingnew); - dashline(xEdge, y + 13, width, y + 13, spacingnew); - stroke(white); - if (board == "STM32F1") - { - if (PinArduinoNames[i] == 0) - { - text("PB " + "OFF", x, y); - } - else - { - text("PB " + str(PinArduinoNames[i]), x, y); - } - } - else - { - if (PinArduinoNames[i] == 0) - { - text("PIN " + "OFF", x, y); - } - else - { - text("PIN " + str(PinArduinoNames[i]), x, y); - } - } - y += 36; - } - - // draw buttons - fill(grey); - - rect(button1X, yBottom - 15, smallButtonW, buttonH, corner); - rect(button2X, buttonY, smallButtonW, buttonH, corner); - rect(button3X, buttonY, bigButtonW, buttonH, corner); - rect(button4X, buttonY, smallButtonW, buttonH, corner); - rect(button5X, buttonY, smallButtonW, buttonH, corner); - fill(white); - - text("Start", button2X + 3, buttonY + 14); - - text(reducer, button4X, buttonY + 14); - text("Save", button5X + 3, buttonY + 14); - text(milliseconds == true ? "milliseconds" : "microseconds", button3X + 3, buttonY + 14); - text("T:" + str(drawTimes), button1X + 3, yBottom); - //bar scroll - fill(handleFill); - rect(handleX, handleY, handleW, handleH); - - -} -void ScrollingBarPressed() -{ - if (isDraggable) - { - handleX = mouseX - handleW / 2; - if (handleX < xEdge) - handleX = xEdge; - if (handleX > width - handleW) - handleX = width - handleW; - updatepos(); - dataComplete = true; - } -} - - void draw() { if (dataComplete == true) { - cleanGraph(); + reset_graph(); + + // draw the signal pushMatrix(); // move the coordinate reference translate(xEdge, 0); drawCursorChannel(IsAnyChannelMarked); updatepos(); // Se encarga de decir que segmento de tiempos se va a escribir DrawChannelSignals(); - yPos = yEdge; - dataComplete = false; popMatrix(); - drawText(); + + dataComplete = false; + + draw_boxes(); } ScrollingBarPressed(); } -void mousePressed() -{ - if (mouseX > xEdge && mouseX < width && - mouseY > handleY && mouseY < handleY + handleH) - { - isDraggable = true; - handleFill = color(100, 200, 255); - } -} - void getChannelCursorCurrentEvent(int index) { float compare1; - CurrentEventFloat = -(xShift*100000 - mouseX*100000 + xEdge*100000); + CurrentEventFloat = -(xShift * 100000 - mouseX * 100000 + xEdge * 100000); ChannelCursor1CurrentEvent0[1] = index; if (index != 16) { @@ -622,13 +536,13 @@ void getChannelCursorCurrentEvent(int index) index2 = s.charAt(0) - '1'; ChannelCursor1CurrentEvent0[0] = 0; // Keep records of the event we are in. //println (abs(xTime[46]+xShift)); - if (CurrentEventFloat < 0 || CurrentEventFloat > xTime[samples - 1]*100000) + if (CurrentEventFloat < 0 || CurrentEventFloat > xTime[samples - 1] * 100000) { if (CurrentEventFloat <= 0) { ChannelCursor1CurrentEvent0[0] = 0; } - if (CurrentEventFloat >= xTime[samples - 1]*100000) + if (CurrentEventFloat >= xTime[samples - 1] * 100000) { ChannelCursor1CurrentEvent0[0] = samples - 1; } @@ -637,8 +551,8 @@ void getChannelCursorCurrentEvent(int index) { for (int i = 1; i < samples - 1; i++) { - compare1 = ((xTime[i]*100000) + (xTime[i + 1]*100000) - (2*CurrentEventFloat)); - if (compare1<0) + compare1 = ((xTime[i] * 100000) + (xTime[i + 1] * 100000) - (2 * CurrentEventFloat)); + if (compare1 < 0) { if (state[i][index1][index2]) { @@ -669,483 +583,18 @@ void updatepos() { xEnd = 0; } - xShift = -map(handleX, xEdge, width - handleW, 0, xEnd); - xShift = xShift + (width - handleW) / 2; + xShift = -map(scroll_bar.from_left, xEdge, width - scroll_bar.width, 0, xEnd); + xShift = xShift + (width - scroll_bar.width) / 2; } void movepos() { xShift = xTime[ChannelCursor1CurrentEvent0[0]]; - handleX = map(xShift, 0, xEnd, xEdge, width - handleW); - xShift = -xShift - (width - handleW) / 2; + scroll_bar.from_left = int(map(xShift, 0, xEnd, xEdge, width - scroll_bar.width)); + xShift = -xShift - (width - scroll_bar.width) / 2; dataComplete = true; } -void keyPressed() -{ - int number; - if (key == CODED) - { - if (keyCode == UP && IsAnyChannelMarked) - { - number = ChannelCursor1CurrentEvent0[1]; - ChannelCursor1CurrentEvent0[1] = ChannelCursor1CurrentEvent0[1] - 1; - for (int i = ChannelCursor1CurrentEvent0[1]; i >= 0; i--) - { - if (PinAssignment[ChannelCursor1CurrentEvent0[1]] == 0) - { - ChannelCursor1CurrentEvent0[1] = ChannelCursor1CurrentEvent0[1] - 1; - } - else - { - break; - } - } - if (ChannelCursor1CurrentEvent0[1] == -1) - { - ChannelCursor1CurrentEvent0[1] = number; - } - ChannelCursor1CurrentEvent0[1] = constrain(ChannelCursor1CurrentEvent0[1], 0, 16); - //println("cur1 "+ChannelCursor1CurrentEvent0[1]+"cur0 "+ChannelCursor1CurrentEvent0[0]); - dataComplete = true; - } - else if (keyCode == DOWN && IsAnyChannelMarked) - { - if (ChannelCursor1CurrentEvent0[1] < 16) - { - ChannelCursor1CurrentEvent0[1] = ChannelCursor1CurrentEvent0[1] + 1; - for (int i = ChannelCursor1CurrentEvent0[1]; i < 16; i++) - { - if (PinAssignment[ChannelCursor1CurrentEvent0[1]] == 0) - { - ChannelCursor1CurrentEvent0[1] = ChannelCursor1CurrentEvent0[1] + 1; - } - else - { - break; - } - ChannelCursor1CurrentEvent0[1] = constrain(ChannelCursor1CurrentEvent0[1], 0, 16); - } - } - //println("cur1 "+ChannelCursor1CurrentEvent0[1]+"cur0 "+ChannelCursor1CurrentEvent0[0]); - dataComplete = true; - } - else if (keyCode == RIGHT && IsAnyChannelMarked) - { - if (ChannelCursor1CurrentEvent0[1] == 16) - { - if (ChannelCursor1CurrentEvent0[0] != samples - 1) - { - ChannelCursor1CurrentEvent0[0] += 1; - } - } - else - { - s = str(PinAssignment[ChannelCursor1CurrentEvent0[1]]); - index1 = s.charAt(1) - '0'; - index2 = s.charAt(0) - '1'; - //println(ChannelCursor1CurrentEvent0[0]); - for (int i = ChannelCursor1CurrentEvent0[0] + 1; i < samples; i++) - { - ChannelCursor1CurrentEvent0[0] = i; - if (state[i][index1][index2]) - { - break; - } - else - { - // nothing here? - } - } - } - //updatepos(); - movepos(); - } - else if (keyCode == LEFT && IsAnyChannelMarked) - { - //println(ChannelCursor1CurrentEvent0[0]); - if (ChannelCursor1CurrentEvent0[1] == 16) - { - if (ChannelCursor1CurrentEvent0[0] != 0) - { - ChannelCursor1CurrentEvent0[0] -= 1; - } - } - else - { - s = str(PinAssignment[ChannelCursor1CurrentEvent0[1]]); - index1 = s.charAt(1) - '0'; - index2 = s.charAt(0) - '1'; - for (int i = ChannelCursor1CurrentEvent0[0] - 1; i > -1; i--) - { - ChannelCursor1CurrentEvent0[0] = i; - if (state[i][index1][index2]) - { - break; - } - else - { - } - } - } - //println("cur1 "+ChannelCursor1CurrentEvent0[1]+"cur0 "+ChannelCursor1CurrentEvent0[0]); - //updatepos(); - movepos(); - } - else if (keyCode == LEFT && !IsAnyChannelMarked) - { - handleX -= 1; - if (handleX < xEdge) - { - handleX = xEdge; - } - if (handleX > width - handleW) - { - handleX = width - handleW; - } - dataComplete = true; - } - else if (keyCode == RIGHT && !IsAnyChannelMarked) - { - handleX += 1; - if (handleX < xEdge) - { - handleX = xEdge; - } - if (handleX > width - handleW) - { - handleX = width - handleW; - } - dataComplete = true; - } - } -} - -void mouseClicked() -{ - // bootons over signals - if (mouseX > xEdge && mouseX < width && mouseY > yBottom - 15 && mouseY < yBottom - 15 + buttonH) - { - getChannelCursorCurrentEvent(16); - IsAnyChannelMarked = true; - movepos(); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge && mouseY < yEdge + 30 && PinAssignment[0] != 0) - { - getChannelCursorCurrentEvent(0); - IsAnyChannelMarked = true; - movepos(); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 && mouseY < yEdge + 36 + 30 && PinAssignment[1] != 0) - { - getChannelCursorCurrentEvent(1); - IsAnyChannelMarked = true; - movepos(); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 2 && mouseY < yEdge + 36 * 2 + 30 && PinAssignment[2] != 0) - { - getChannelCursorCurrentEvent(2); - IsAnyChannelMarked = true; - movepos(); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 3 && mouseY < yEdge + 36 * 3 + 30 && PinAssignment[3] != 0) - { - getChannelCursorCurrentEvent(3); - IsAnyChannelMarked = true; - movepos(); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 4 && mouseY < yEdge + 36 * 4 + 30 && PinAssignment[4] != 0) - { - getChannelCursorCurrentEvent(4); - IsAnyChannelMarked = true; - movepos(); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 5 && mouseY < yEdge + 36 * 5 + 30 && PinAssignment[5] != 0) - { - getChannelCursorCurrentEvent(5); - IsAnyChannelMarked = true; - movepos(); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 6 && mouseY < yEdge + 36 * 6 + 30 && PinAssignment[6] != 0) - { - getChannelCursorCurrentEvent(6); - IsAnyChannelMarked = true; - movepos(); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 7 && mouseY < yEdge + 36 * 7 + 30 && PinAssignment[7] != 0) - { - getChannelCursorCurrentEvent(7); - IsAnyChannelMarked = true; - movepos(); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 8 && mouseY < yEdge + 36 * 8 + 30 && PinAssignment[8] != 0) - { - getChannelCursorCurrentEvent(8); - IsAnyChannelMarked = true; - movepos(); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 9 && mouseY < yEdge + 36 * 9 + 30 && PinAssignment[9] != 0) - { - getChannelCursorCurrentEvent(9); - IsAnyChannelMarked = true; - movepos(); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 10 && mouseY < yEdge + 36 * 10 + 30 && PinAssignment[10] != 0) - { - getChannelCursorCurrentEvent(10); - IsAnyChannelMarked = true; - movepos(); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 11 && mouseY < yEdge + 36 * 11 + 30 && PinAssignment[11] != 0) - { - getChannelCursorCurrentEvent(11); - IsAnyChannelMarked = true; - movepos(); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 12 && mouseY < yEdge + 36 * 12 + 30 && PinAssignment[12] != 0) - { - getChannelCursorCurrentEvent(12); - IsAnyChannelMarked = true; - movepos(); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 13 && mouseY < yEdge + 36 * 13 + 30 && PinAssignment[13] != 0) - { - getChannelCursorCurrentEvent(13); - IsAnyChannelMarked = true; - movepos(); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 14 && mouseY < yEdge + 36 * 14 + 30 && PinAssignment[14] != 0) - { - getChannelCursorCurrentEvent(14); - IsAnyChannelMarked = true; - movepos(); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 15 && mouseY < yEdge + 36 * 15 + 30 && PinAssignment[15] != 0) - { - getChannelCursorCurrentEvent(15); - IsAnyChannelMarked = true; - movepos(); - } - else if (mouseY > yBottom - 15 && mouseY < yBottom - 15 + buttonH && mouseX > button1X && mouseX < button1X + smallButtonW) // draw times - { - drawTimes = !drawTimes; - refresh = true; - } - else if (mouseY > buttonY && mouseY < buttonY + buttonH && mouseX > button2X && mouseX < button2X + smallButtonW) // new read - { - refresh = true; - board_port.write('G'); - println("new data coming"); - board_port.clear(); - xShift = (width - handleW) / 2; - handleX = xEdge; - } - else if (mouseY > buttonY && mouseY < buttonY + buttonH && mouseX > button5X && mouseX < button5X + smallButtonW) // save frame - { - String a = "la_capture-" + immage; //+".jpg"; //if you prefer this format, default .tif - save(a); - immage++; - } - else if (mouseY > buttonY && mouseY < buttonY + buttonH && mouseX > button4X && mouseX < button4X + smallButtonW) // it is over the reducer button - { - if (mouseButton == LEFT) - { - if (reducer <= 1) - { - reducer += 0.1; - } - else if (reducer <= 10) - { - reducer += 1; - } - else if (reducer > 10) - { - reducer += 10; - } - - if (reducer > 90 && !milliseconds) // change from microseconds to milliseconds - { - reducer = 0.1; - milliseconds = !milliseconds; - } - reducer = constrain(reducer, 0.1, 100); - } - else if (mouseButton == RIGHT) - { - if (reducer <= 1) - { - reducer -= 0.1; - } - else if (reducer <= 10) - { - reducer -= 1; - } - else if (reducer > 10) - { - reducer -= 10; - } - - if (reducer < 0.1 && milliseconds) // change from milliseconds to microseconds - { - reducer = 100; - milliseconds = !milliseconds; - } - reducer = constrain(reducer, 0.1, 90); - } - scaletime(); - updatepos(); - dataComplete = true; - } - else // micro or millis - { - if (mouseY > buttonY && mouseY < buttonY + buttonH && mouseX > button3X && mouseX < button3X + bigButtonW) - { - - milliseconds = !milliseconds; - scaletime(); - dataComplete = true; - //updatepos(); - } - else - { - IsAnyChannelMarked = false; - dataComplete = true; - } - } -} - -void mouseReleased() -{ - isDraggable = false; - handleFill = grey; - if (refresh) - { - //scaletime('d'); - //xShift = -map(handleX, xEdge, width-handleW, 0, xEnd); - //xShift = xShift + (width-handleW)/2; - refresh = false; - //updatepos(); - //dataComplete=true; - } -} - -void mouseWheel(MouseEvent event) -{ - float wheel = event.getCount(); - //move the graph - if (milliseconds){ - handleX -= wheel * 50*reducer; - }else{ - handleX -= wheel * 50*reducer*0.001;} - if (handleX < xEdge) - handleX = xEdge; - if (handleX > width - handleW) - handleX = width - handleW; - //print(wheel); print(" - "); - //println(handleX); - dataComplete = true; -} - -void mouseMoved() -{ - if (mouseY > buttonY && mouseY < buttonY + buttonH && mouseX > button2X && mouseX < button2X + smallButtonW) - { - cursor(HAND); - } - else if (mouseY > buttonY && mouseY < buttonY + buttonH && mouseX > button3X && mouseX < button3X + bigButtonW) - { - cursor(HAND); - } - else if (mouseY > buttonY && mouseY < buttonY + buttonH && mouseX > button5X && mouseX < button5X + smallButtonW) - { - cursor(HAND); - } - else if (mouseY > buttonY && mouseY < buttonY + buttonH && mouseX > button4X && mouseX < button4X + smallButtonW) - { - cursor(HAND); - } - else if (mouseY > yBottom - 15 && mouseY < yBottom - 15 + buttonH && mouseX > button1X && mouseX < button1X + smallButtonW) - { - cursor(HAND); - } - else if (mouseX > handleX && mouseX < handleX + handleW && mouseY > handleY && mouseY < handleY + handleH) - { - cursor(HAND); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yBottom - 15 && mouseY < yBottom - 15 + buttonH) - { - cursor(HAND); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge && mouseY < yEdge + 30 && PinAssignment[0] != 0) - { - cursor(HAND); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 && mouseY < yEdge + 36 + 30 && PinAssignment[1] != 0) - { - cursor(HAND); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 2 && mouseY < yEdge + 36 * 2 + 30 && PinAssignment[2] != 0) - { - cursor(HAND); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 3 && mouseY < yEdge + 36 * 3 + 30 && PinAssignment[3] != 0) - { - cursor(HAND); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 4 && mouseY < yEdge + 36 * 4 + 30 && PinAssignment[4] != 0) - { - cursor(HAND); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 5 && mouseY < yEdge + 36 * 5 + 30 && PinAssignment[5] != 0) - { - cursor(HAND); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 6 && mouseY < yEdge + 36 * 6 + 30 && PinAssignment[6] != 0) - { - cursor(HAND); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 7 && mouseY < yEdge + 36 * 7 + 30 && PinAssignment[7] != 0) - { - cursor(HAND); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 8 && mouseY < yEdge + 36 * 8 + 30 && PinAssignment[8] != 0) - { - cursor(HAND); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 9 && mouseY < yEdge + 36 * 9 + 30 && PinAssignment[9] != 0) - { - cursor(HAND); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 10 && mouseY < yEdge + 36 * 10 + 30 && PinAssignment[10] != 0) - { - cursor(HAND); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 11 && mouseY < yEdge + 36 * 11 + 30 && PinAssignment[11] != 0) - { - cursor(HAND); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 12 && mouseY < yEdge + 36 * 12 + 30 && PinAssignment[12] != 0) - { - cursor(HAND); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 13 && mouseY < yEdge + 36 * 13 + 30 && PinAssignment[13] != 0) - { - cursor(HAND); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 14 && mouseY < yEdge + 36 * 14 + 30 && PinAssignment[14] != 0) - { - cursor(HAND); - } - else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 15 && mouseY < yEdge + 36 * 15 + 30 && PinAssignment[15] != 0) - { - cursor(HAND); - } - else - { - cursor(ARROW); - } -} - // Recupera los datos recibidos desde el arduino, y hace uso de la funcion get data para pasarlos de datos almacenados en 3bytes a matrices para utilizarlos facilmente void serialEvent(Serial board_port) { @@ -1200,14 +649,14 @@ void serialEvent(Serial board_port) void scaletime() // Poner una r indicara que la funcion solo va a rehacer los tiempos. { - if (milliseconds) + if (time_format == "ms") { for (int i = 0; i < samples; i++) { xTime[i] = usTime[i] / (reducer * 1000); //better to reduce the lenght of the x } } - else + else if (time_format == "μs") { for (int i = 0; i < samples; i++) { @@ -1260,53 +709,7 @@ void getData() //print(state[i][n][0]+" , "+state[i][n][1]+" , "+state[i][n][2]); //println(); } - //println(); } dataComplete = true; } - -float[] spacing = {5, 8}; //used for the dashline function, pixels -float[] spacingnew = {1, 50}; //used for the dashline function, pixels -void dashline(float x0, float y0, float x1, float y1, float[] spacing) -{ - - float distance = dist(x0, y0, x1, y1); - float[] xSpacing = new float[spacing.length]; - float[] ySpacing = new float[spacing.length]; - float drawn = 0.0; // amount of distance drawn - - if (distance > 0) - { - int i; - boolean drawLine = true; // alternate between dashes and gaps - - /* - Figure out x and y distances for each of the spacing values - I decided to trade memory for time; I'd rather allocate - a few dozen bytes than have to do a calculation every time - I draw. - */ - - for (i = 0; i < spacing.length; i++) - { - xSpacing[i] = lerp(0, (x1 - x0), spacing[i] / distance); - ySpacing[i] = lerp(0, (y1 - y0), spacing[i] / distance); - } - - i = 0; - while (drawn < distance) - { - if (drawLine) - { - line(x0, y0, x0 + xSpacing[i], y0 + ySpacing[i]); - } - x0 += xSpacing[i]; - y0 += ySpacing[i]; - /* Add distance "drawn" by this line or gap */ - drawn = drawn + mag(xSpacing[i], ySpacing[i]); - i = (i + 1) % spacing.length; // cycle through array - drawLine = !drawLine; // switch between dash and gap - } - } -} diff --git a/Computer_Interface/DrawFunctions.pde b/Computer_Interface/DrawFunctions.pde new file mode 100644 index 0000000..6179e97 --- /dev/null +++ b/Computer_Interface/DrawFunctions.pde @@ -0,0 +1,234 @@ +void reset_graph() +{ + box_graph.clear(); + Arrays.fill(xPos, 0); // reset start point of the graph + textCovered = false; + yPos = yEdge; // reset upper position + stroke(green); // green lines for the next draw +} + +void draw_boxes() +{ + // clear the boxes + box_bottom.clear(); + box_scroll_bar.clear(); + box_pin_names.clear(); + + // draw buttons + button_time_draw.text = "Draw Times: " + str(drawTimes); + button_time_format.text = time_format; + button_reducer.text = "Reducer: " + nf(reducer, 0, 2); + + button_start.draw(); + button_time_draw.draw(); + button_time_format.draw(); + button_reducer.draw(); + button_save.draw(); + + // scroll bar + fill(grey); + rect(scroll_bar.from_left, scroll_bar.from_top, scroll_bar.width, scroll_bar.height); + + // pin names + fill(white); + textSize(14); + + int x = 5; + int y = 30; + + for (byte i = 0; i < 16; i++) + { + line(x, y - 20, xEdge, y - 20); + line(x, y + 10, xEdge, y + 10); + stroke(#EF7F1A); + dashline(xEdge, y - 23, width, y - 23, spacing); + dashline(xEdge, y + 13, width, y + 13, spacing); + stroke(white); + if (board == "STM32F1") + { + if (PinArduinoNames[i] == 0) + { + text("PB " + "OFF", x, y); + } + else + { + text("PB " + str(PinArduinoNames[i]), x, y); + } + } + else // UNO MEGA ESP8266 + { + if (PinArduinoNames[i] == 0) + { + text("PIN " + "OFF", x, y); + } + else + { + text("PIN " + str(PinArduinoNames[i]), x, y); + } + } + y += 36; + } +} + +void drawCursorChannel(boolean CursorEnable) +{ + if (CursorEnable) + { + fill(50); + stroke(75); + if (ChannelCursor1CurrentEvent0[1] == 16) // This variable is used to define the channel on which we move or have marked, in this part we draw the rectangle that emphasizes a channel. + { + rect(0, yBottom - 12, width - xEdge, 34); + } + else + { + rect(0, yEdge + 36 * ChannelCursor1CurrentEvent0[1] - 2, width - xEdge, 34); + } + stroke(green); + } +} + +void DrawChannelSignals() +{ + float firstchange; + boolean cares; + for (int i = 0; i < samples; i++) + { + cares = false; + firstchange = 0; + yPos = yEdge; // reset position + for (int n = 0; n < 16; n++) + { + if (PinArduinoNames[n] != 0) // draw only used pins + { + s = str(PinAssignment[n]); + index1 = s.charAt(1) - '0'; + index2 = s.charAt(0) - '1'; + //printArray(state[0][0]); + //print(state[i][index1][index2]+" , "); + if (state[i][index1][index2]) + { + cares = true; + if (firstchange == 0) + { + firstchange = yPos; + } + ySave = yPos; // save y value + + if (i == 0) // this is the first state + { + if (isLowInit[index1][index2]) // pin high + { + yDiff = yPos; + yPos += 30; + } + else // low + { + yDiff = yPos + 30; + } + isLow[index1][index2] = isLowInit[index1][index2]; + //println(isLowInit[index1][index2]); + } + else // all the others + { + if (isLow[index1][index2]) // pin high + { + yDiff = yPos; + yPos += 30; + isLow[index1][index2] = false; + } + else // low + { + yDiff = yPos + 30; + isLow[index1][index2] = true; + } + } + + // finally we draw the lines + line(xPos[n] + xShift, yPos, xTime[i] + xShift, yPos); // straight line + line(xTime[i] + xShift, yPos, xTime[i] + xShift, yDiff); // vertical line + + xPos[n] = xTime[i]; // save last position of the line for the pin + yPos = ySave; // load the initial value of the y + } + } + yPos += 36; // go to the next pin + } + // Text times + if ((drawTimes && cares) || i == 0) + { + if (ChannelCursor1CurrentEvent0[0] == i) + { + stroke(red); + fill(red); + } + else + { + stroke(grey); + fill(grey); + } + textSize(10); + textCovered = !textCovered; + dashline(xTime[i] + xShift, firstchange, xTime[i] + xShift, yBottom, spacing); + text(round(usTime[i]), xTime[i] + xShift + 2, (textCovered == true) ? yBottom : yBottom + 10); //write on different height + stroke(green); + } + } +} + +void ScrollingBarPressed() +{ + if (isDraggable) + { + scroll_bar.from_left = mouseX - scroll_bar.width / 2; + if (scroll_bar.from_left < xEdge) + scroll_bar.from_left = int(xEdge); + if (scroll_bar.from_left > width - scroll_bar.width) + scroll_bar.from_left = width - scroll_bar.width; + updatepos(); + dataComplete = true; + } +} + +float[] spacing = {1, 50}; //used for the dashline function, pixels +void dashline(float x0, float y0, float x1, float y1, float[] spacing) +{ + float distance = dist(x0, y0, x1, y1); + float[] xSpacing = new float[spacing.length]; + float[] ySpacing = new float[spacing.length]; + float drawn = 0.0; // amount of distance drawn + + if (distance > 0) + { + int i; + boolean drawLine = true; // alternate between dashes and gaps + + /* + Figure out x and y distances for each of the spacing values + I decided to trade memory for time; I'd rather allocate + a few dozen bytes than have to do a calculation every time + I draw. + */ + + for (i = 0; i < spacing.length; i++) + { + xSpacing[i] = lerp(0, (x1 - x0), spacing[i] / distance); + ySpacing[i] = lerp(0, (y1 - y0), spacing[i] / distance); + } + + i = 0; + while (drawn < distance) + { + if (drawLine) + { + line(x0, y0, x0 + xSpacing[i], y0 + ySpacing[i]); + } + x0 += xSpacing[i]; + y0 += ySpacing[i]; + /* Add distance "drawn" by this line or gap */ + drawn = drawn + mag(xSpacing[i], ySpacing[i]); + i = (i + 1) % spacing.length; // cycle through array + drawLine = !drawLine; // switch between dash and gap + } + } +} diff --git a/Computer_Interface/MouseEvents.pde b/Computer_Interface/MouseEvents.pde new file mode 100644 index 0000000..1bd8bc9 --- /dev/null +++ b/Computer_Interface/MouseEvents.pde @@ -0,0 +1,548 @@ +boolean mouse_over_button(Button b) +{ + if (mouseY > b.from_top && mouseY < b.from_top + b.height && mouseX > b.from_left && mouseX < b.from_left + b.width) + { + return true; + } + else + { + return false; + } +} + +boolean mouse_over_channel(byte c) +{ + if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * c && mouseY < yEdge + 36 * c + 30 && PinAssignment[c] != 0) + { + return true; + } + else + { + return false; + } +} + +// this function is called every time a key is pressed +void keyPressed() +{ + int number; + if (key == CODED) // UP, DOWN, LEFT, RIGHT, ALT, CONTROL, and SHIFT + { + if (keyCode == UP && IsAnyChannelMarked) + { + number = ChannelCursor1CurrentEvent0[1]; + ChannelCursor1CurrentEvent0[1] = ChannelCursor1CurrentEvent0[1] - 1; + for (int i = ChannelCursor1CurrentEvent0[1]; i >= 0; i--) + { + if (PinAssignment[ChannelCursor1CurrentEvent0[1]] == 0) + { + ChannelCursor1CurrentEvent0[1] = ChannelCursor1CurrentEvent0[1] - 1; + } + else + { + break; + } + } + if (ChannelCursor1CurrentEvent0[1] == -1) + { + ChannelCursor1CurrentEvent0[1] = number; + } + ChannelCursor1CurrentEvent0[1] = constrain(ChannelCursor1CurrentEvent0[1], 0, 16); + //println("cur1 "+ChannelCursor1CurrentEvent0[1]+"cur0 "+ChannelCursor1CurrentEvent0[0]); + dataComplete = true; + } + else if (keyCode == DOWN && IsAnyChannelMarked) + { + if (ChannelCursor1CurrentEvent0[1] < 16) + { + ChannelCursor1CurrentEvent0[1] = ChannelCursor1CurrentEvent0[1] + 1; + for (int i = ChannelCursor1CurrentEvent0[1]; i < 16; i++) + { + if (PinAssignment[ChannelCursor1CurrentEvent0[1]] == 0) + { + ChannelCursor1CurrentEvent0[1] = ChannelCursor1CurrentEvent0[1] + 1; + } + else + { + break; + } + ChannelCursor1CurrentEvent0[1] = constrain(ChannelCursor1CurrentEvent0[1], 0, 16); + } + } + //println("cur1 "+ChannelCursor1CurrentEvent0[1]+"cur0 "+ChannelCursor1CurrentEvent0[0]); + dataComplete = true; + } + else if (keyCode == RIGHT && IsAnyChannelMarked) + { + if (ChannelCursor1CurrentEvent0[1] == 16) + { + if (ChannelCursor1CurrentEvent0[0] != samples - 1) + { + ChannelCursor1CurrentEvent0[0] += 1; + } + } + else + { + s = str(PinAssignment[ChannelCursor1CurrentEvent0[1]]); + index1 = s.charAt(1) - '0'; + index2 = s.charAt(0) - '1'; + //println(ChannelCursor1CurrentEvent0[0]); + for (int i = ChannelCursor1CurrentEvent0[0] + 1; i < samples; i++) + { + ChannelCursor1CurrentEvent0[0] = i; + if (state[i][index1][index2]) + { + break; + } + else + { + // nothing here? + } + } + } + //updatepos(); + movepos(); + } + else if (keyCode == LEFT && IsAnyChannelMarked) + { + //println(ChannelCursor1CurrentEvent0[0]); + if (ChannelCursor1CurrentEvent0[1] == 16) + { + if (ChannelCursor1CurrentEvent0[0] != 0) + { + ChannelCursor1CurrentEvent0[0] -= 1; + } + } + else + { + s = str(PinAssignment[ChannelCursor1CurrentEvent0[1]]); + index1 = s.charAt(1) - '0'; + index2 = s.charAt(0) - '1'; + for (int i = ChannelCursor1CurrentEvent0[0] - 1; i > -1; i--) + { + ChannelCursor1CurrentEvent0[0] = i; + if (state[i][index1][index2]) + { + break; + } + else + { + } + } + } + //println("cur1 "+ChannelCursor1CurrentEvent0[1]+"cur0 "+ChannelCursor1CurrentEvent0[0]); + //updatepos(); + movepos(); + } + else if (keyCode == LEFT && !IsAnyChannelMarked) + { + scroll_bar.from_left -= 1; + if (scroll_bar.from_left < xEdge) + { + scroll_bar.from_left = int(xEdge); + } + if (scroll_bar.from_left > width - scroll_bar.width) + { + scroll_bar.from_left = width - scroll_bar.width; + } + dataComplete = true; + } + else if (keyCode == RIGHT && !IsAnyChannelMarked) + { + scroll_bar.from_left += 1; + if (scroll_bar.from_left < xEdge) + { + scroll_bar.from_left = int(xEdge); + } + if (scroll_bar.from_left > width - scroll_bar.width) + { + scroll_bar.from_left = width - scroll_bar.width; + } + dataComplete = true; + } + } +} + +// this function is called after a mouse button has been pressed and then released +void mouseClicked() +{ + for (byte channel = 0; channel < 16; channel++) + { + if (mouse_over_channel(channel)) + { + getChannelCursorCurrentEvent(channel); + IsAnyChannelMarked = true; + movepos(); + // exit from the for loop + break; + } + } + /* + if (mouseX > xEdge && mouseX < width && mouseY > yEdge && mouseY < yEdge + 30 && PinAssignment[0] != 0) + { + getChannelCursorCurrentEvent(0); + IsAnyChannelMarked = true; + movepos(); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 && mouseY < yEdge + 36 + 30 && PinAssignment[1] != 0) + { + getChannelCursorCurrentEvent(1); + IsAnyChannelMarked = true; + movepos(); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 2 && mouseY < yEdge + 36 * 2 + 30 && PinAssignment[2] != 0) + { + getChannelCursorCurrentEvent(2); + IsAnyChannelMarked = true; + movepos(); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 3 && mouseY < yEdge + 36 * 3 + 30 && PinAssignment[3] != 0) + { + getChannelCursorCurrentEvent(3); + IsAnyChannelMarked = true; + movepos(); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 4 && mouseY < yEdge + 36 * 4 + 30 && PinAssignment[4] != 0) + { + getChannelCursorCurrentEvent(4); + IsAnyChannelMarked = true; + movepos(); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 5 && mouseY < yEdge + 36 * 5 + 30 && PinAssignment[5] != 0) + { + getChannelCursorCurrentEvent(5); + IsAnyChannelMarked = true; + movepos(); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 6 && mouseY < yEdge + 36 * 6 + 30 && PinAssignment[6] != 0) + { + getChannelCursorCurrentEvent(6); + IsAnyChannelMarked = true; + movepos(); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 7 && mouseY < yEdge + 36 * 7 + 30 && PinAssignment[7] != 0) + { + getChannelCursorCurrentEvent(7); + IsAnyChannelMarked = true; + movepos(); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 8 && mouseY < yEdge + 36 * 8 + 30 && PinAssignment[8] != 0) + { + getChannelCursorCurrentEvent(8); + IsAnyChannelMarked = true; + movepos(); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 9 && mouseY < yEdge + 36 * 9 + 30 && PinAssignment[9] != 0) + { + getChannelCursorCurrentEvent(9); + IsAnyChannelMarked = true; + movepos(); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 10 && mouseY < yEdge + 36 * 10 + 30 && PinAssignment[10] != 0) + { + getChannelCursorCurrentEvent(10); + IsAnyChannelMarked = true; + movepos(); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 11 && mouseY < yEdge + 36 * 11 + 30 && PinAssignment[11] != 0) + { + getChannelCursorCurrentEvent(11); + IsAnyChannelMarked = true; + movepos(); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 12 && mouseY < yEdge + 36 * 12 + 30 && PinAssignment[12] != 0) + { + getChannelCursorCurrentEvent(12); + IsAnyChannelMarked = true; + movepos(); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 13 && mouseY < yEdge + 36 * 13 + 30 && PinAssignment[13] != 0) + { + getChannelCursorCurrentEvent(13); + IsAnyChannelMarked = true; + movepos(); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 14 && mouseY < yEdge + 36 * 14 + 30 && PinAssignment[14] != 0) + { + getChannelCursorCurrentEvent(14); + IsAnyChannelMarked = true; + movepos(); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 15 && mouseY < yEdge + 36 * 15 + 30 && PinAssignment[15] != 0) + { + getChannelCursorCurrentEvent(15); + IsAnyChannelMarked = true; + movepos(); + } + */ + + if (mouse_over_button(button_time_draw)) + { + drawTimes = !drawTimes; + refresh = true; + } + else if (mouse_over_button(button_start)) + { + refresh = true; + board_port.write('G'); + println("new data coming"); + board_port.clear(); + xShift = (width - scroll_bar.width) / 2; + scroll_bar.from_left = int(xEdge); + } + else if (mouse_over_button(button_save)) + { + save("la_capture_" + immage_number + image_format); + immage_number++; + } + else if (mouse_over_button(button_reducer)) + { + if (mouseButton == LEFT) // increase + { + if (reducer <= 1) + { + reducer += 0.1; + } + else if (reducer <= 10) + { + reducer += 1; + } + else if (reducer > 10) + { + reducer += 10; + } + + if (reducer > 90 && time_format == "μs") // change from microseconds to milliseconds + { + reducer = 0.1; + time_format = "ms"; + } + reducer = constrain(reducer, 0.1, 100); + } + else if (mouseButton == RIGHT) // reduce + { + if (reducer <= 1) + { + reducer -= 0.1; + } + else if (reducer <= 10) + { + reducer -= 1; + } + else if (reducer > 10) + { + reducer -= 10; + } + + if (reducer < 0.1 && time_format == "ms") // change from milliseconds to microseconds + { + reducer = 100; + time_format = "μs"; + } + reducer = constrain(reducer, 0.1, 90); + } + scaletime(); + updatepos(); + dataComplete = true; + } + else if (mouse_over_button(button_time_format)) + { + if (time_format == "μs") + { + time_format = "ms"; + } + else if (time_format == "ms") + { + time_format = "μs"; + } + + scaletime(); + dataComplete = true; + //updatepos(); + } + else + { + IsAnyChannelMarked = false; + dataComplete = true; + } +} + +void mouseReleased() +{ + isDraggable = false; + //scroll_bar_color = grey; + if (refresh) + { + //scaletime('d'); + //xShift = -map(scroll_bar.from_left, xEdge, width-scroll_bar.width, 0, xEnd); + //xShift = xShift + (width-scroll_bar.width)/2; + refresh = false; + //updatepos(); + //dataComplete=true; + } +} + +// this function returns positive values when the mouse wheel is rotated down, and negative values for the other direction +void mouseWheel(MouseEvent event) +{ + // get the mouse movement and invert it + float wheel = map(event.getCount(), -1, 1, 1, -1); + + // change the step of the mouse wheel depending on the reducer and time_format + if (time_format == "ms") + { + scroll_bar.from_left -= wheel * 50 * reducer; + } + else if (time_format == "μs") + { + scroll_bar.from_left -= wheel * 50 * reducer * 0.1; + } + + //move the graph + if (scroll_bar.from_left < xEdge) + { + scroll_bar.from_left = int(xEdge); + } + if (scroll_bar.from_left > width - scroll_bar.width) + { + scroll_bar.from_left = width - scroll_bar.width; + } + //print("wheel: "); println(wheel); + //print("scroll_bar: "); println(scroll_bar.from_left); + dataComplete = true; +} + +// this function is called every time the mouse moves and a mouse button is not pressed +void mouseMoved() +{ + if (mouse_over_button(button_start)) + { + cursor(HAND); + return; + } + else if (mouse_over_button(button_time_draw)) + { + cursor(HAND); + return; + } + else if (mouse_over_button(button_time_format)) + { + cursor(HAND); + return; + } + else if (mouse_over_button(button_reducer)) + { + cursor(HAND); + return; + } + else if (mouse_over_button(button_save)) + { + cursor(HAND); + return; + } + else if (mouse_over_button(scroll_bar)) + { + cursor(HAND); + return; + } + else + { + cursor(ARROW); + } + + for (byte channel = 0; channel < 16; channel++) + { + if (mouse_over_channel(channel)) + { + cursor(HAND); + return; + // exit from the for loop + } + else + { + cursor(ARROW); + } + } + + /* + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge && mouseY < yEdge + 30 && PinAssignment[0] != 0) + { + cursor(HAND); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 && mouseY < yEdge + 36 + 30 && PinAssignment[1] != 0) + { + cursor(HAND); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 2 && mouseY < yEdge + 36 * 2 + 30 && PinAssignment[2] != 0) + { + cursor(HAND); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 3 && mouseY < yEdge + 36 * 3 + 30 && PinAssignment[3] != 0) + { + cursor(HAND); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 4 && mouseY < yEdge + 36 * 4 + 30 && PinAssignment[4] != 0) + { + cursor(HAND); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 5 && mouseY < yEdge + 36 * 5 + 30 && PinAssignment[5] != 0) + { + cursor(HAND); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 6 && mouseY < yEdge + 36 * 6 + 30 && PinAssignment[6] != 0) + { + cursor(HAND); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 7 && mouseY < yEdge + 36 * 7 + 30 && PinAssignment[7] != 0) + { + cursor(HAND); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 8 && mouseY < yEdge + 36 * 8 + 30 && PinAssignment[8] != 0) + { + cursor(HAND); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 9 && mouseY < yEdge + 36 * 9 + 30 && PinAssignment[9] != 0) + { + cursor(HAND); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 10 && mouseY < yEdge + 36 * 10 + 30 && PinAssignment[10] != 0) + { + cursor(HAND); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 11 && mouseY < yEdge + 36 * 11 + 30 && PinAssignment[11] != 0) + { + cursor(HAND); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 12 && mouseY < yEdge + 36 * 12 + 30 && PinAssignment[12] != 0) + { + cursor(HAND); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 13 && mouseY < yEdge + 36 * 13 + 30 && PinAssignment[13] != 0) + { + cursor(HAND); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 14 && mouseY < yEdge + 36 * 14 + 30 && PinAssignment[14] != 0) + { + cursor(HAND); + } + else if (mouseX > xEdge && mouseX < width && mouseY > yEdge + 36 * 15 && mouseY < yEdge + 36 * 15 + 30 && PinAssignment[15] != 0) + { + cursor(HAND); + } + else + { + cursor(ARROW); + } + */ +} + +// this function is called every time a mouse button is pressed +void mousePressed() +{ + if (mouse_over_button(scroll_bar)) + { + isDraggable = true; + + //scroll_bar_color = color(100, 200, 255); change color of the scroll bar + } +}