From 0b87ec4e7a4928eb9ff9bc217010ea4341f851c0 Mon Sep 17 00:00:00 2001 From: sancho11 Date: Sat, 12 Jan 2019 01:02:23 -0600 Subject: [PATCH 1/4] Added the Mega version for processing and arduino, New navigation features added too. --- Computer_Interface/processing_for_MEGA.pde | 936 +++++++++++++++++++++ Microcontroller_Code/MEGA/MEGA.ino | 193 ++--- 2 files changed, 1017 insertions(+), 112 deletions(-) create mode 100644 Computer_Interface/processing_for_MEGA.pde diff --git a/Computer_Interface/processing_for_MEGA.pde b/Computer_Interface/processing_for_MEGA.pde new file mode 100644 index 0000000..7b1b444 --- /dev/null +++ b/Computer_Interface/processing_for_MEGA.pde @@ -0,0 +1,936 @@ + +import processing.serial.*; +import java.util.Arrays; +Serial p; + +//////////////////////////////////////////////// +/*--------------------SETUP-------------------*/ + +//uncomment the line where your arduino/STM32 is connected +//String LA_port = "/dev/ttyACM0"; //linux DFU +//String LA_port = "/dev/ttyUSB0"; //linux Serial +String LA_port = "COM3"; //windows + +final int baudrate = 115200; //check if it is the same in arduino + + +/*------------------END SETUP-----------------*/ +//////////////////////////////////////////////// + + +//colors: +int white = 255; +int black = 0; +int green = #00FF00; +int red = #FF0000; +int grey = 150; + + +// shift, reducer and millisecond view +float reducer = 1.0; +boolean milliseconds = true; +float xShift; + + +// start point in the processing window +float xEdge = 60; +float yEdge = 10; +float xEnd; +float oldxEnd; +float[] xPos = new float[16]; +float yBottom; +float yDiff; +float yPos = yEdge; +float ySave = yEdge; +boolean textCovered; +boolean drawTimes = true; + + +//Serial from mcu +//initial data +int samples; +int event; +int initialState[]= new int[3]; +boolean first = false; +boolean dataComplete = false; +//following data +boolean [][][] state; +boolean [][] isLow = new boolean[8][3]; +boolean [][] isLowinit = new boolean[8][3]; +float[] usTime; +float[] xTime; +int[][] pinChanged; +int[] PinAssignment = new int[16]; +int[] PinArduinoNames = new int[16]; +int index1; +int index2; +int index3; +boolean refresh= true; +int []cursora= new int[2]; +float cursoraf= 0; +boolean cursorplay=false; + + + +/* +ENGLISH +How the assign of the pins works?. +Since the arduino MEGA2560 has enough pins more than the arduino one, and also its processor can reach 2MHz and I suppose it must also have a better IPC ratio (Instructions per cycle) +I decided to read 24 pins of which we will deplete 16 in the program, among the reasons to do this are, the location of the pins which are not always where one would like, +and the mapping of the digital pins in the arduino microcontroller, since I wanted to take advantage of the greater number of pins doing the fewer instructions to avoid +damaging the process. + +The entries will be depleted in the order they appear in the whole PinAssignment that goes from 0 to 15 for a total of 16, the value of the integer in each position will +reference the pin to be used. Then the value that must be entered in the integer will be shown to observe the desired pin. + +In case you do not want to show anything on that channel, just assign 00 so that the channel will not be written. +The pins that do not appear in the table can not be used because they were not considered in the arduino programming, to avoid overloading the +arduino and obtain more satisfactory response times. + +SPANISH +Funcionamiento de la asignacion de pines. +Dado que el arduino MEGA2560 tiene bastantes pines más que el arduino uno, y además su procesador puede llegar a los 2MHz y supongo también debe de tener un mejor ratio +IPC (Instrucciones por ciclo) decidí hacer lectura de 24 pines de los cuales deplegaremos 16 en el programa, entre las razones para hacer esto estan, la ubicacion de los +pines los cuales no siempre estan donde uno quisiera, y el mapeo de los pines digitales en el microcontrolador del arduino, ya que queria aprovechar la mayor cantidad de +pines haciendo la menor cantidad de instrucciones para no perjudicar el proceso. + +Las entradas se deplegaran en el orden que aparezcan en el entero PinAssignment que va del 0 al 15 para un total de 16, el valor del entero en cada posicion referenciara +el pin a utilizar. A continuacion se mostrara el valor que se debe introducir en el entero para observar el pin deseado. + +En caso de no querer mostrar nada en ese canal basta con asignar 00 para que el canal no sea escrito. +Los pines que no aparecen en la tabla no podrán ser utilizados por que no fueron considerados en la programacion de arduino, esto para evitar sobrecargar al +arduino y obtener tiempos de respuesta más satisfactorios. + +EN Number of Pin in the Arduino Mega Number to enter in the PinAssignment +ES Numero de Pin en el Arduino Mega Numero a introducir en el PinAssignment +Digital PIN 22 -------------------------------------------------------> 10 +Digital PIN 23 -------------------------------------------------------> 11 +Digital PIN 24 -------------------------------------------------------> 12 +Digital PIN 25 -------------------------------------------------------> 13 +Digital PIN 26 -------------------------------------------------------> 14 +Digital PIN 27 -------------------------------------------------------> 15 +Digital PIN 28 -------------------------------------------------------> 16 +Digital PIN 29 -------------------------------------------------------> 17 +Digital PIN 49 -------------------------------------------------------> 20 +Digital PIN 48 -------------------------------------------------------> 21 +Digital PIN 47 -------------------------------------------------------> 22 +Digital PIN 46 -------------------------------------------------------> 23 +Digital PIN 45 -------------------------------------------------------> 24 +Digital PIN 44 -------------------------------------------------------> 25 +Digital PIN 43 -------------------------------------------------------> 26 +Digital PIN 42 -------------------------------------------------------> 27 +Digital PIN 37 -------------------------------------------------------> 30 +Digital PIN 36 -------------------------------------------------------> 31 +Digital PIN 35 -------------------------------------------------------> 32 +Digital PIN 34 -------------------------------------------------------> 33 +Digital PIN 33 -------------------------------------------------------> 34 +Digital PIN 32 -------------------------------------------------------> 35 +Digital PIN 31 -------------------------------------------------------> 36 +Digital PIN 30 -------------------------------------------------------> 37 + + + +*/ + +//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; +String s; +boolean initial=true; + +// bar scroll +int handleFill = grey; +float handleX; +float handleY; +float handleW = 20; +float handleH = 15; +boolean isDraggable = false; + + + +void setup () { + //p = new Serial(this, Serial.list()[0], 115200); + p = new Serial(this, LA_port, baudrate); + p.bufferUntil('\n'); + + size(1300, 700); + 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. + //Aquí escoges los pines que quieres desplegar. + PinAssignment[0] = 10; + PinAssignment[1] = 11; + PinAssignment[2] = 12; + PinAssignment[3] = 13; + PinAssignment[4] = 14; + PinAssignment[5] = 15; + PinAssignment[6] = 16; + PinAssignment[7] = 17; + PinAssignment[8] = 20; + PinAssignment[9] = 21; + PinAssignment[10]= 22; + PinAssignment[11]= 23; + PinAssignment[12]= 24; + PinAssignment[13]= 25; + PinAssignment[14]= 26; + PinAssignment[15]= 27; + + for (int i=0; i<16; i++) { + switch (PinAssignment[i]) { + case (10): + PinArduinoNames[i]=22; + break; + case (11): + PinArduinoNames[i]=23; + break; + case (12): + PinArduinoNames[i]=24; + break; + case (13): + PinArduinoNames[i]=25; + break; + case (14): + PinArduinoNames[i]=26; + break; + case (15): + PinArduinoNames[i]=27; + break; + case (16): + PinArduinoNames[i]=28; + break; + case (17): + PinArduinoNames[i]=29; + break; + case (20): + PinArduinoNames[i]=49; + break; + case (21): + PinArduinoNames[i]=48; + break; + case (22): + PinArduinoNames[i]=47; + break; + case (23): + PinArduinoNames[i]=46; + break; + case (24): + PinArduinoNames[i]=45; + break; + case (25): + PinArduinoNames[i]=44; + break; + case (26): + PinArduinoNames[i]=43; + break; + case (27): + PinArduinoNames[i]=42; + break; + case (30): + PinArduinoNames[i]=37; + break; + case (31): + PinArduinoNames[i]=36; + break; + case (32): + PinArduinoNames[i]=35; + break; + case (33): + PinArduinoNames[i]=34; + break; + case (34): + PinArduinoNames[i]=33; + break; + case (35): + PinArduinoNames[i]=32; + break; + case (36): + PinArduinoNames[i]=31; + break; + case (37): + PinArduinoNames[i]=30; + break; + default: + PinArduinoNames[i]=00; + break; + + } + } + 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 draw() { + + if (dataComplete==true) { + cleanGraph(); + pushMatrix(); //move the coordinate reference + translate(xEdge, 0); + float firstchange; + boolean cares; + if (cursorplay){ + fill(50); + stroke(75); + if(cursora[1]==16){ //Esta variable la utilizamos para definir el canal sobre el cual estamos trabajando, en esta parte marcamos el rectangulo en el que trabajamos. + rect(0, yBottom-12, width-xEdge, 34); + } + else{ + rect(0, yEdge+36*cursora[1]-2, width-xEdge, 34); + } + stroke(green); + } + updatepos(); //Se encarga de decir que segmento de tiempos se va a escribir + for (int i=0; i// + yDiff=yPos; + yPos+=30; + + } else { + yDiff=yPos+30; + } + isLow[index1][index2]=isLowinit[index1][index2]; + //println(isLowinit[index1][index2]); + } + else { + if (isLow[index1][index2]) { //pin high else low + yDiff=yPos; + yPos+=30; + isLow[index1][index2]=false; + } else { + yDiff=yPos+30; + isLow[index1][index2]=true; + } + } + + + + // Graph 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 (cursora[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); + } + } + + yPos = yEdge; + for (int n = 0; n < 16; n++) { + if (PinAssignment[n]!=0){ + s= str(PinAssignment[n]); + index1 = s.charAt(1)-'0'; + index2 = s.charAt(0)-'1'; + if (xPos[n]==0) { + if (isLowinit[index1][index2]==true) line(xPos[n]+xShift, yPos+30, xEnd+xShift, yPos+30); + else line(xPos[n]+xShift, yPos, xEnd+xShift, yPos); + } + + } + yPos+=36; + } + dataComplete = false; + popMatrix(); + } + drawText(); +} + + +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; + + /* if (STM32) { + + for (byte i = 12; i<=15; i++) { + line(x, y-20, xEdge, y-20); + line(x, y+10, xEdge, y+10); + text ("PB"+i, x, y); + y+=60; + } + } else { +*/ + 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 (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); + + if (isDraggable) { + handleX = mouseX-handleW/2; + if (handleXwidth-handleW) handleX = width-handleW; + updatepos(); + dataComplete = true; + + + } + +} + + +void mousePressed() { + if (mouseX>xEdge && mouseXhandleY && mouseYxTime[samples-1]){ + if (cursoraf<=0){ + cursora[0]=0; + } + if (cursoraf>=xTime[samples-1]){ + cursora[0]=samples-1; + } + }else{ + for (int i=1; iabs(xTime[i+1]-cursoraf)&&state[i][index1][index2]){ + if (abs(xTime[i]-cursoraf)>abs(xTime[i+1]-cursoraf)){ + if(state[i][index1][index2]){ + cursora[0]=i; + } + }else { + break; + } + //println (abs(xTime[i]+xShift)); + //println ("wut"); + } + } + } + println( cursora[0]); + dataComplete=true; +} +void updatepos(){ + if (samples!=0) { + xEnd = (xTime[samples-1]); + // xEnd = xEnd + } else { + xEnd = 0; + } + xShift = -map(handleX, xEdge, width-handleW, 0, xEnd); + xShift = xShift + (width-handleW)/2; + +} + +void movepos(){ + xShift = xTime[cursora[0]]; + handleX = map(xShift, 0, xEnd, xEdge, width-handleW); + xShift = -xShift - (width-handleW)/2; +dataComplete=true; + +} + +void keyPressed() { + int number; + if (key == CODED) { + if (keyCode == UP && cursorplay) { + number=cursora[1]; + cursora[1]= cursora[1]-1; + for (int i=cursora[1]; i>=0; i--){ + if (PinAssignment[cursora[1]]==0){ + cursora[1]= cursora[1]-1; + }else { + break; + } + } + if (cursora[1]==-1){ + cursora[1]= number; + } + cursora[1]=constrain(cursora[1], 0, 16); + //println("cur1 "+cursora[1]+"cur0 "+cursora[0]); + dataComplete=true; + } else if (keyCode == DOWN && cursorplay) { + if(cursora[1]<16){ + cursora[1]= cursora[1]+1; + for (int i=cursora[1]; i<16; i++){ + if (PinAssignment[cursora[1]]==0){ + cursora[1]= cursora[1]+1; + }else { + break; + } + + cursora[1]=constrain(cursora[1], 0, 16); + } } + //println("cur1 "+cursora[1]+"cur0 "+cursora[0]); + dataComplete=true; + } else if (keyCode == RIGHT && cursorplay) { + if (cursora[1]==16){ + if (cursora[0]!=samples-1){ + cursora[0]+=1; + } + } + else{ + s = str(PinAssignment[cursora[1]]); + index1 = s.charAt(1)-'0'; + index2 = s.charAt(0)-'1'; + //println(cursora[0]); + for (int i=cursora[0]+1; i-1; i--){ + cursora[0]=i; + if (state[i][index1][index2]){ + break; + }else { + + } } + } + //println("cur1 "+cursora[1]+"cur0 "+cursora[0]); + //updatepos(); + movepos(); + }else if (keyCode == LEFT && !cursorplay) { + handleX-=1; + if (handleXwidth-handleW) handleX = width-handleW; + dataComplete=true; + }else if (keyCode == RIGHT && !cursorplay) { + handleX+=1; + if (handleXwidth-handleW) handleX = width-handleW; + dataComplete=true; + } + } +} + +void mouseClicked() { + + // bootons over signals + if(mouseX>xEdge && mouseX yBottom-15 && mouseY xEdge && mouseX yEdge && mouseY xEdge && mouseX yEdge+36 && mouseY xEdge && mouseX yEdge+36*2 && mouseY xEdge && mouseX yEdge+36*3 && mouseY xEdge && mouseX yEdge+36*4 && mouseY xEdge && mouseX yEdge+36*5 && mouseY xEdge && mouseX yEdge+36*6 && mouseY xEdge && mouseX yEdge+36*7 && mouseY xEdge && mouseX yEdge+36*8 && mouseY xEdge && mouseX yEdge+36*9 && mouseY xEdge && mouseX yEdge+36*10 && mouseY xEdge && mouseX yEdge+36*11 && mouseY xEdge && mouseX yEdge+36*12 && mouseY xEdge && mouseX yEdge+36*13 && mouseY xEdge && mouseX yEdge+36*14 && mouseY xEdge && mouseX yEdge+36*15 && mouseY yBottom-15 && mouseY button1X && mouseX buttonY && mouseY button2X && mouseX buttonY && mouseY button5X && mouseX buttonY && mouseY button4X && mouseX 90 && !milliseconds){ + reducer=0.1; + milliseconds = !milliseconds; + } + reducer = constrain(reducer, 0.1, 100); + } else { //move the graph + if (reducer<=1){ + reducer-= 0.1; + }else if (reducer<=10){ + reducer-=1; + }else { + reducer-=10; + } + if (reducer<0.1 && milliseconds){ + reducer=100; + milliseconds = !milliseconds; + } + reducer = constrain(reducer, 0.1, 90); + } + scaletime(); + updatepos(); + dataComplete=true; + } else + // micro or millis + if (mouseY>buttonY && mouseY button3X && mouseX width-handleW) handleX = width-handleW; + dataComplete=true; + +} + + +void mouseMoved() { + if (mouseY>buttonY && mouseY button2X && mouseX buttonY && mouseY button3X && mouseX buttonY && mouseY button5X && mouseX buttonY && mouseY button4X && mouseX yBottom-15 && mouseY button1X && mouseX handleX && mouseXhandleY && mouseYxEdge && mouseX yBottom-15 && mouseY xEdge && mouseX yEdge && mouseY xEdge && mouseX yEdge+36 && mouseY xEdge && mouseX yEdge+36*2 && mouseY xEdge && mouseX yEdge+36*3 && mouseY xEdge && mouseX yEdge+36*4 && mouseY xEdge && mouseX yEdge+36*5 && mouseY xEdge && mouseX yEdge+36*6 && mouseY xEdge && mouseX yEdge+36*7 && mouseY xEdge && mouseX yEdge+36*8 && mouseY xEdge && mouseX yEdge+36*9 && mouseY xEdge && mouseX yEdge+36*10 && mouseY xEdge && mouseX yEdge+36*11 && mouseY xEdge && mouseX yEdge+36*12 && mouseY xEdge && mouseX yEdge+36*13 && mouseY xEdge && mouseX yEdge+36*14 && mouseY xEdge && mouseX yEdge+36*15 && mouseY 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/Microcontroller_Code/MEGA/MEGA.ino b/Microcontroller_Code/MEGA/MEGA.ino index a42c886..e6b24a7 100644 --- a/Microcontroller_Code/MEGA/MEGA.ino +++ b/Microcontroller_Code/MEGA/MEGA.ino @@ -1,21 +1,14 @@ /* - * MEGA.ino + * LA.cpp * * Created: 11/12/2016 19.35.51 - * Author : Vincenzo / sancho - * Modificaciones agregadas para funcionar con ArduinoMega2560 por Enmanuel Sancho Quintanilla - * La unidad minima en tiempo para este sistema es de 8 micro segundos lo que idealmente permitiria - * observar clocks con periodos de 62 kHz sin embargo para poder apreciar las señales logicas con suficiente - * resolucion se recomienda no superar los 30 kHz en el clock del sistema. - */ + * Author : Vincenzo + */ -#define baudrate 115200 // check if it is the same in processing -#define samples 200 // the number of samples you want to take - - -#define pin_used +#define baudrate 115200 //check if it is the same in processing +#define samples 400 #define timezerooffset 125 //microsegundos -#define PULLUP true //Si queremos entradas con PULLUP lo dejamos activado(true), si queremos dejarlas al "aire" (false), en caso de desactivarlo deberemos aterrizar todos los pines que no utilizemos. +#define PULLUP true //Si queremos entradas con PULLUP lo dejamos activado(true), si queremos dejarlas al "aire" (false), en caso de desactivarlo deberemos aterrizar todos los pines que no utilizemos. #define F_CPU 16000000UL #include #include @@ -30,32 +23,27 @@ uint8_t pinChanged3[samples]; uint32_t timer[samples]; uint32_t timefix; uint16_t event = 0; -uint8_t cambio = 0; -void init_board() -{ - - // PORTC = (0 << 0); DDRC |= (1 << 0); // led A0 - - DDRB = 0x00; - DDRC = 0x00; +uint8_t cambio=0; +void init_board() { + +// PORTC = (0 << 0); DDRC |= (1 << 0); // led A0 + DDRB = 0x00; + DDRC = 0x00; DDRL = 0x00; - - if (PULLUP) - { - PORTA = B11111111; // pull-up - PORTC = B11111111; // Activamos el pull-up para que de no conectarse nada a puerto lea un uno siempre - PORTL = B11111111; - } - else - { - PORTA = B00000000; - PORTC = B00000000; - PORTL = B00000000; + if (PULLUP){ + PORTA = B11111111; // pull-up + PORTC = B11111111; // Activamos el pull-up para que de no conectarse nada a puerto lea un uno siempre + PORTL = B11111111; } + else{ + PORTA = B00000000; + PORTC = B00000000; + PORTL = B00000000; + } } -void init_timer() -{ +void init_timer() { + //clear TCCR1A = 0b00000000; TCCR1B = 0b00000000; @@ -63,43 +51,40 @@ void init_timer() //settings TCCR1A |= (0 << COM1A1) | (0 << COM1A0) | (0 << COM1B1) | (0 << COM1B0); //normal port operation - TCCR1A |= (0 << WGM11) | (0 << WGM10); //normal operation - TCCR1B |= (0 << WGM13) | (0 << WGM12); //normal operation - TCCR1B |= prescaler; //(0 << CS12) | (0 << CS11) | (1 << CS10); //clock prescaler - sei(); //enable interrupts - TIMSK1 |= (1 << TOIE1); // enable overflow interrupt + TCCR1A |= (0 << WGM11) | (0 << WGM10); //normal operation + TCCR1B |= (0 << WGM13) | (0 << WGM12); //normal operation + TCCR1B |= prescaler; //(0 << CS12) | (0 << CS11) | (1 << CS10); //clock prescaler + + sei(); //enable interrupts + TIMSK1 |= (1 << TOIE1); // enable overflow interrupt + } -ISR(TIMER1_OVF_vect) -{ +ISR(TIMER1_OVF_vect) { timer1_overflow_count++; } -void reset_timer1() -{ +void reset_timer1 () { TCNT1 = 0; timer1_overflow_count = 0; } -uint32_t myMicros() -{ +uint32_t myMicros () { cli(); - if (TIFR1 & (1 << TOV1)) - { + if (TIFR1 & (1 << TOV1)) { TIFR1 = (0 << TOV1); timer1_overflow_count++; } - + uint32_t total_time = (65536 * timer1_overflow_count + TCNT1) / 2; sei(); return total_time; } -void start() -{ +void start() { _delay_ms(1000); - // Serial.print("hi"); + // Serial.print("hi"); reset_timer1(); event = 0; @@ -110,58 +95,50 @@ void start() state1 = initial1; state2 = initial2; state3 = initial3; - for (int i = 0; i < samples; i++) - { - pinChanged1[i] = 0; - pinChanged2[i] = 0; - pinChanged3[i] = 0; - //Serial.print(pinChanged1[i]); Serial.print(','); Serial.print(pinChanged2[i]); Serial.print(','); Serial.println(pinChanged3[i]); //debug - } + for (int i=0; i < samples; i++) { + pinChanged1[i]=0; + pinChanged2[i]=0; + pinChanged3[i]=0; + //Serial.print(pinChanged1[i]); Serial.print(','); Serial.print(pinChanged2[i]); Serial.print(','); Serial.println(pinChanged3[i]); + + } + } -void sendData() -{ + +void sendData() { //PORTC = (0 << 0); //turn off led //initial data Serial.println("S"); - Serial.print(initial1); - Serial.print(','); - Serial.print(initial2); - Serial.print(','); - Serial.print(initial3); - Serial.print(":"); - Serial.println(samples); - - timefix = -timer[0] + timezerooffset; - - for (int i = 0; i < samples; i++) - { - timer[i] = timer[i] + timefix; + Serial.print(initial1); Serial.print(','); Serial.print(initial2); Serial.print(','); Serial.print(initial3); Serial.print(":"); + Serial.println(samples+3); + timefix = -timer[0]+timezerooffset; + for (int i = 0; i < samples; i++) { + timer[i]=timer[i]+timefix; } + Serial.print(B11111111);Serial.print(','); Serial.print(B11111111); Serial.print(','); Serial.print(B11111111); Serial.print(":");//Este segmento de codigo introduce un cambio en todos los + Serial.println(0); //canales, lo que soluciona un error en el codigo en processing + Serial.print(B11111111);Serial.print(','); Serial.print(B11111111); Serial.print(','); Serial.print(B11111111); Serial.print(":");//al final se hace un cambio en todos los canales, lo que soluciona + Serial.println(1); //otro pequeño fallo visual. //data - for (int i = 0; i < samples; i++) - { - Serial.print(pinChanged1[i]); - Serial.print(','); - Serial.print(pinChanged2[i]); - Serial.print(','); - Serial.print(pinChanged3[i]); - Serial.print(":"); + for (int i = 0; i < samples; i++) { + Serial.print(pinChanged1[i]);Serial.print(','); Serial.print(pinChanged2[i]); Serial.print(','); Serial.print(pinChanged3[i]); Serial.print(":"); Serial.println(timer[i]); } + Serial.print(B11111111);Serial.print(','); Serial.print(B11111111); Serial.print(','); Serial.print(B11111111); Serial.print(":"); + Serial.println((timer[samples-1]+400)); } -int main(void) -{ + +int main(void) { Serial.begin(baudrate); init_board(); init_timer(); start(); - while (1) - { - cambio = 0; + while (1) { + cambio=0; old_state1 = state1; old_state2 = state2; old_state3 = state3; @@ -169,36 +146,28 @@ int main(void) state2 = PINL; state3 = PINC; //Serial.print(state1);Serial.print(" , ");Serial.print(state2);Serial.print(" , ");Serial.print(state3);Serial.print(" : ");Serial.println(event); - - if (old_state1 != state1) - { - pinChanged1[event] = state1 ^ old_state1; - cambio = 1; + + if (old_state1 != state1 ) { + pinChanged1[event] = state1 ^ old_state1; + cambio=1; } - if (old_state2 != state2) - { - pinChanged2[event] = state2 ^ old_state2; - cambio = 1; + if (old_state2 != state2 ) { + pinChanged2[event] = state2 ^ old_state2; + cambio=1; } - if (old_state3 != state3) - { - pinChanged3[event] = state3 ^ old_state3; - cambio = 1; + if (old_state3 != state3 ) { + pinChanged3[event] = state3 ^ old_state3; + cambio = 1; } - if (cambio == 1) - { - timer[event] = myMicros(); - event++; - } - if (event == samples) - { + if (cambio == 1) { + timer[event] = myMicros(); + event++; + } + if (event == samples) { sendData(); - while (Serial.read() != 'G') - { - ; - } //wait for the "go" + while (Serial.read() != 'G') ; //wait for the "go" start(); - } + } } } From df602c7423b7add6d1ca0517b41bcd8c16e40322 Mon Sep 17 00:00:00 2001 From: sancho11 Date: Sat, 12 Jan 2019 02:05:43 -0600 Subject: [PATCH 2/4] Added the modifications to work on arduino UNO almost the same features for arduino MEGA, now for arduino UNO! --- .../processing_for_UNO_newmod.pde | 854 ++++++++++++++++++ Microcontroller_Code/UNO/UNO_newmod.ino | 139 +++ 2 files changed, 993 insertions(+) create mode 100644 Computer_Interface/processing_for_UNO_newmod.pde create mode 100644 Microcontroller_Code/UNO/UNO_newmod.ino diff --git a/Computer_Interface/processing_for_UNO_newmod.pde b/Computer_Interface/processing_for_UNO_newmod.pde new file mode 100644 index 0000000..198299c --- /dev/null +++ b/Computer_Interface/processing_for_UNO_newmod.pde @@ -0,0 +1,854 @@ + +import processing.serial.*; +import java.util.Arrays; +Serial p; + +//////////////////////////////////////////////// +/*--------------------SETUP-------------------*/ + +//uncomment the line where your arduino/STM32 is connected +//String LA_port = "/dev/ttyACM0"; //linux DFU +//String LA_port = "/dev/ttyUSB0"; //linux Serial +String LA_port = "COM3"; //windows + +final int baudrate = 115200; //check if it is the same in arduino + + +/*------------------END SETUP-----------------*/ +//////////////////////////////////////////////// + + +//colors: +int white = 255; +int black = 0; +int green = #00FF00; +int red = #FF0000; +int grey = 150; + + +// shift, reducer and millisecond view +float reducer = 1.0; +boolean milliseconds = true; +float xShift; + + +// start point in the processing window +float xEdge = 60; +float yEdge = 10; +float xEnd; +float oldxEnd; +float[] xPos = new float[16]; +float yBottom; +float yDiff; +float yPos = yEdge; +float ySave = yEdge; +boolean textCovered; +boolean drawTimes = true; + + +//Serial from mcu +//initial data +int samples; +int event; +int initialState[]= new int[3]; +boolean first = false; +boolean dataComplete = false; +//following data +boolean [][][] state; +boolean [][] isLow = new boolean[8][3]; +boolean [][] isLowinit = new boolean[8][3]; +float[] usTime; +float[] xTime; +int[][] pinChanged; +int[] PinAssignment = new int[16]; +int[] PinArduinoNames = new int[16]; +int index1; +int index2; +int index3; +boolean refresh= true; +int []cursora= new int[2]; +float cursoraf= 0; +boolean cursorplay=false; + + + +/* +ENGLISH +How the assign of the pins works?. +The entries will be depleted in the order they appear in the whole PinAssignment that goes from 0 to 15 for a total of 16, the value of the integer in each position will +reference the pin to be used. Then the value that must be entered in the integer will be shown to observe the desired pin. + +In case you do not want to show anything on that channel, just assign 00 so that the channel will not be written. +The pins that do not appear in the table can not be used because they were not considered in the arduino programming, to avoid overloading the +arduino and obtain more satisfactory response times. + +SPANISH +Funcionamiento de la asignacion de pines. +Las entradas se deplegaran en el orden que aparezcan en el entero PinAssignment que va del 0 al 15 para un total de 16, el valor del entero en cada posicion referenciara +el pin a utilizar. A continuacion se mostrara el valor que se debe introducir en el entero para observar el pin deseado. + +En caso de no querer mostrar nada en ese canal basta con asignar 00 para que el canal no sea escrito. +Los pines que no aparecen en la tabla no podrán ser utilizados por que no fueron considerados en la programacion de arduino, esto para evitar sobrecargar al +arduino y obtener tiempos de respuesta más satisfactorios. + +EN Number of Pin in the Arduino UNO Number to enter in the PinAssignment +ES Numero de Pin en el Arduino UNO Numero a introducir en el PinAssignment +Digital PIN 8 -------------------------------------------------------> 10 +Digital PIN 9 -------------------------------------------------------> 11 +Digital PIN 10 -------------------------------------------------------> 12 +Digital PIN 11 -------------------------------------------------------> 13 +Digital PIN 12 -------------------------------------------------------> 14 +Digital PIN 13 -------------------------------------------------------> 15 + + + +*/ + +//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; +String s; +boolean initial=true; + +// bar scroll +int handleFill = grey; +float handleX; +float handleY; +float handleW = 20; +float handleH = 15; +boolean isDraggable = false; + + + +void setup () { + //p = new Serial(this, Serial.list()[0], 115200); + p = new Serial(this, LA_port, baudrate); + p.bufferUntil('\n'); + + size(1300, 700); + 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. + //Aquí escoges los pines que quieres desplegar. + PinAssignment[0] = 10; + PinAssignment[1] = 11; + PinAssignment[2] = 12; + PinAssignment[3] = 13; + PinAssignment[4] = 14; + PinAssignment[5] = 15; + PinAssignment[6] = 00; + PinAssignment[7] = 00; + PinAssignment[8] = 00; + PinAssignment[9] = 00; + PinAssignment[10]= 00; + PinAssignment[11]= 00; + PinAssignment[12]= 00; + PinAssignment[13]= 00; + PinAssignment[14]= 00; + PinAssignment[15]= 00; + + for (int i=0; i<16; i++) { + switch (PinAssignment[i]) { + case (10): + PinArduinoNames[i]=08; + break; + case (11): + PinArduinoNames[i]=09; + break; + case (12): + PinArduinoNames[i]=10; + break; + case (13): + PinArduinoNames[i]=11; + break; + case (14): + PinArduinoNames[i]=12; + break; + case (15): + PinArduinoNames[i]=13; + break; + default: + PinArduinoNames[i]=00; + break; + + } + } + 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 draw() { + + if (dataComplete==true) { + cleanGraph(); + pushMatrix(); //move the coordinate reference + translate(xEdge, 0); + float firstchange; + boolean cares; + if (cursorplay){ + fill(50); + stroke(75); + if(cursora[1]==16){ //Esta variable la utilizamos para definir el canal sobre el cual estamos trabajando, en esta parte marcamos el rectangulo en el que trabajamos. + rect(0, yBottom-12, width-xEdge, 34); + } + else{ + rect(0, yEdge+36*cursora[1]-2, width-xEdge, 34); + } + stroke(green); + } + updatepos(); //Se encarga de decir que segmento de tiempos se va a escribir + for (int i=0; i// + yDiff=yPos; + yPos+=30; + + } else { + yDiff=yPos+30; + } + isLow[index1][index2]=isLowinit[index1][index2]; + //println(isLowinit[index1][index2]); + } + else { + if (isLow[index1][index2]) { //pin high else low + yDiff=yPos; + yPos+=30; + isLow[index1][index2]=false; + } else { + yDiff=yPos+30; + isLow[index1][index2]=true; + } + } + + + + // Graph 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 (cursora[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); + } + } + + yPos = yEdge; + for (int n = 0; n < 16; n++) { + if (PinAssignment[n]!=0){ + s= str(PinAssignment[n]); + index1 = s.charAt(1)-'0'; + index2 = s.charAt(0)-'1'; + if (xPos[n]==0) { + if (isLowinit[index1][index2]==true) line(xPos[n]+xShift, yPos+30, xEnd+xShift, yPos+30); + else line(xPos[n]+xShift, yPos, xEnd+xShift, yPos); + } + + } + yPos+=36; + } + dataComplete = false; + popMatrix(); + } + drawText(); +} + + +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; + + /* if (STM32) { + + for (byte i = 12; i<=15; i++) { + line(x, y-20, xEdge, y-20); + line(x, y+10, xEdge, y+10); + text ("PB"+i, x, y); + y+=60; + } + } else { +*/ + 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 (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); + + if (isDraggable) { + handleX = mouseX-handleW/2; + if (handleXwidth-handleW) handleX = width-handleW; + updatepos(); + dataComplete = true; + + + } + +} + + +void mousePressed() { + if (mouseX>xEdge && mouseXhandleY && mouseYxTime[samples-1]){ + if (cursoraf<=0){ + cursora[0]=0; + } + if (cursoraf>=xTime[samples-1]){ + cursora[0]=samples-1; + } + }else{ + for (int i=1; iabs(xTime[i+1]-cursoraf)&&state[i][index1][index2]){ + if (abs(xTime[i]-cursoraf)>abs(xTime[i+1]-cursoraf)){ + if(state[i][index1][index2]){ + cursora[0]=i; + } + }else { + break; + } + //println (abs(xTime[i]+xShift)); + //println ("wut"); + } + } + } + println( cursora[0]); + dataComplete=true; +} +void updatepos(){ + if (samples!=0) { + xEnd = (xTime[samples-1]); + // xEnd = xEnd + } else { + xEnd = 0; + } + xShift = -map(handleX, xEdge, width-handleW, 0, xEnd); + xShift = xShift + (width-handleW)/2; + +} + +void movepos(){ + xShift = xTime[cursora[0]]; + handleX = map(xShift, 0, xEnd, xEdge, width-handleW); + xShift = -xShift - (width-handleW)/2; +dataComplete=true; + +} + +void keyPressed() { + int number; + if (key == CODED) { + if (keyCode == UP && cursorplay) { + number=cursora[1]; + cursora[1]= cursora[1]-1; + for (int i=cursora[1]; i>=0; i--){ + if (PinAssignment[cursora[1]]==0){ + cursora[1]= cursora[1]-1; + }else { + break; + } + } + if (cursora[1]==-1){ + cursora[1]= number; + } + cursora[1]=constrain(cursora[1], 0, 16); + //println("cur1 "+cursora[1]+"cur0 "+cursora[0]); + dataComplete=true; + } else if (keyCode == DOWN && cursorplay) { + if(cursora[1]<16){ + cursora[1]= cursora[1]+1; + for (int i=cursora[1]; i<16; i++){ + if (PinAssignment[cursora[1]]==0){ + cursora[1]= cursora[1]+1; + }else { + break; + } + + cursora[1]=constrain(cursora[1], 0, 16); + } } + //println("cur1 "+cursora[1]+"cur0 "+cursora[0]); + dataComplete=true; + } else if (keyCode == RIGHT && cursorplay) { + if (cursora[1]==16){ + if (cursora[0]!=samples-1){ + cursora[0]+=1; + } + } + else{ + s = str(PinAssignment[cursora[1]]); + index1 = s.charAt(1)-'0'; + index2 = s.charAt(0)-'1'; + //println(cursora[0]); + for (int i=cursora[0]+1; i-1; i--){ + cursora[0]=i; + if (state[i][index1][index2]){ + break; + }else { + + } } + } + //println("cur1 "+cursora[1]+"cur0 "+cursora[0]); + //updatepos(); + movepos(); + }else if (keyCode == LEFT && !cursorplay) { + handleX-=1; + if (handleXwidth-handleW) handleX = width-handleW; + dataComplete=true; + }else if (keyCode == RIGHT && !cursorplay) { + handleX+=1; + if (handleXwidth-handleW) handleX = width-handleW; + dataComplete=true; + } + } +} + +void mouseClicked() { + + // bootons over signals + if(mouseX>xEdge && mouseX yBottom-15 && mouseY xEdge && mouseX yEdge && mouseY xEdge && mouseX yEdge+36 && mouseY xEdge && mouseX yEdge+36*2 && mouseY xEdge && mouseX yEdge+36*3 && mouseY xEdge && mouseX yEdge+36*4 && mouseY xEdge && mouseX yEdge+36*5 && mouseY xEdge && mouseX yEdge+36*6 && mouseY xEdge && mouseX yEdge+36*7 && mouseY xEdge && mouseX yEdge+36*8 && mouseY xEdge && mouseX yEdge+36*9 && mouseY xEdge && mouseX yEdge+36*10 && mouseY xEdge && mouseX yEdge+36*11 && mouseY xEdge && mouseX yEdge+36*12 && mouseY xEdge && mouseX yEdge+36*13 && mouseY xEdge && mouseX yEdge+36*14 && mouseY xEdge && mouseX yEdge+36*15 && mouseY yBottom-15 && mouseY button1X && mouseX buttonY && mouseY button2X && mouseX buttonY && mouseY button5X && mouseX buttonY && mouseY button4X && mouseX 90 && !milliseconds){ + reducer=0.1; + milliseconds = !milliseconds; + } + reducer = constrain(reducer, 0.1, 100); + } else { //move the graph + if (reducer<=1){ + reducer-= 0.1; + }else if (reducer<=10){ + reducer-=1; + }else { + reducer-=10; + } + if (reducer<0.1 && milliseconds){ + reducer=100; + milliseconds = !milliseconds; + } + reducer = constrain(reducer, 0.1, 90); + } + scaletime(); + updatepos(); + dataComplete=true; + } else + // micro or millis + if (mouseY>buttonY && mouseY button3X && mouseX width-handleW) handleX = width-handleW; + dataComplete=true; + +} + + +void mouseMoved() { + if (mouseY>buttonY && mouseY button2X && mouseX buttonY && mouseY button3X && mouseX buttonY && mouseY button5X && mouseX buttonY && mouseY button4X && mouseX yBottom-15 && mouseY button1X && mouseX handleX && mouseXhandleY && mouseYxEdge && mouseX yBottom-15 && mouseY xEdge && mouseX yEdge && mouseY xEdge && mouseX yEdge+36 && mouseY xEdge && mouseX yEdge+36*2 && mouseY xEdge && mouseX yEdge+36*3 && mouseY xEdge && mouseX yEdge+36*4 && mouseY xEdge && mouseX yEdge+36*5 && mouseY xEdge && mouseX yEdge+36*6 && mouseY xEdge && mouseX yEdge+36*7 && mouseY xEdge && mouseX yEdge+36*8 && mouseY xEdge && mouseX yEdge+36*9 && mouseY xEdge && mouseX yEdge+36*10 && mouseY xEdge && mouseX yEdge+36*11 && mouseY xEdge && mouseX yEdge+36*12 && mouseY xEdge && mouseX yEdge+36*13 && mouseY xEdge && mouseX yEdge+36*14 && mouseY xEdge && mouseX yEdge+36*15 && mouseY 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/Microcontroller_Code/UNO/UNO_newmod.ino b/Microcontroller_Code/UNO/UNO_newmod.ino new file mode 100644 index 0000000..426ef4d --- /dev/null +++ b/Microcontroller_Code/UNO/UNO_newmod.ino @@ -0,0 +1,139 @@ +/* + * UNO.ino + * + * Created: 11/12/2016 19.35.51 + * Author : Vincenzo + * Led on A0 + */ + +#define baudrate 115200 // check if it is the same in processing +#define samples 200 // the number of samples you want to take +#define timezerooffset 125 //microsegundos +#define F_CPU 16000000UL +#include +#include +#include +#define prescaler 0x02 +volatile uint16_t timer1_overflow_count; + +uint8_t initial, state, old_state; +uint8_t pinChanged[samples]; +uint32_t timer[samples]; +uint32_t timefix; +uint16_t event = 0; + +void init_board() { + + PORTC = (0 << 0); DDRC |= (1 << 0); // led A0 + DDRB |= 0x00; // pin 8-13 input + PORTB |= 0x3F; // pull-up + +} + +void init_timer() { + + //clear + TCCR1A = 0b00000000; + TCCR1B = 0b00000000; + TIMSK1 = 0b00000000; + + //settings + TCCR1A |= (0 << COM1A1) | (0 << COM1A0) | (0 << COM1B1) | (0 << COM1B0); //normal port operation + TCCR1A |= (0 << WGM11) | (0 << WGM10); //normal operation + TCCR1B |= (0 << WGM13) | (0 << WGM12); //normal operation + TCCR1B |= prescaler; //(0 << CS12) | (0 << CS11) | (1 << CS10); //clock prescaler + + sei(); //enable interrupts + TIMSK1 |= (1 << TOIE1); // enable overflow interrupt + +} + +ISR(TIMER1_OVF_vect) { + timer1_overflow_count++; +} + +void reset_timer1 () { + TCNT1 = 0; + timer1_overflow_count = 0; +} + +uint32_t myMicros () { + cli(); + + if (TIFR1 & (1 << TOV1)) { + TIFR1 = (0 << TOV1); + timer1_overflow_count++; + } + + uint32_t total_time = (65536 * timer1_overflow_count + TCNT1) / 2; + sei(); + return total_time; +} + +void start() { + _delay_ms(1000); + + reset_timer1(); + event = 0; + + PORTC = (1 << 0); + initial = PINB; + state = initial; + for (int i=0; i < samples; i++) { + pinChanged[i]=0; + + } +} + + +void sendData() { + PORTC = (0 << 0); //turn off led + + //initial data + Serial.println("S"); + Serial.print(initial); Serial.print(','); Serial.print(B11111111); Serial.print(','); Serial.print(B11111111); Serial.print(":"); + Serial.println(samples+3); + timefix = -timer[0]+timezerooffset; + for (int i = 0; i < samples; i++) { + timer[i]=timer[i]+timefix; + } + Serial.print(B11111111);Serial.print(','); Serial.print(B11111111); Serial.print(','); Serial.print(B11111111); Serial.print(":");//Este segmento de codigo introduce un cambio en todos los + Serial.println(0); //canales, lo que soluciona un error en el codigo en processing + Serial.print(B11111111);Serial.print(','); Serial.print(B11111111); Serial.print(','); Serial.print(B11111111); Serial.print(":");//al final se hace un cambio en todos los canales, lo que soluciona + Serial.println(1); //otro pequeño fallo visual. + //data + for (int i = 0; i < samples; i++) { + Serial.print(pinChanged[i]);Serial.print(','); Serial.print(B00000000); Serial.print(','); Serial.print(B00000000); Serial.print(":"); + Serial.println(timer[i]); + } + Serial.print(B11111111);Serial.print(','); Serial.print(B11111111); Serial.print(','); Serial.print(B11111111); Serial.print(":"); + Serial.println((timer[samples-1]+400)); +} + + +int main(void) { + Serial.begin(baudrate); + + init_board(); + init_timer(); + + start(); + + while (1) { + + old_state = state; + state = PINB; + + if (old_state != state) { + timer[event] = myMicros(); + pinChanged[event] = state ^ old_state; + event++; + + if (event == samples) { + sendData(); + while (Serial.read() != 'G') ; //wait for the "go" + start(); + } + } + } +} From 66cd99689e9ea5d8a6796e9c2db5876917a37b9a Mon Sep 17 00:00:00 2001 From: sancho11 Date: Wed, 16 Jan 2019 00:58:54 -0600 Subject: [PATCH 3/4] Integration of all boards Added a way to every board work with a single one processing code. --- Computer_Interface/processing.pde | 967 ++++++++++++++---- Computer_Interface/processing_for_MEGA.pde | 936 ----------------- .../processing_for_UNO_newmod.pde | 854 ---------------- Microcontroller_Code/ESP8266/ESP8266.ino | 23 +- Microcontroller_Code/MEGA/MEGA.ino | 13 +- Microcontroller_Code/STM32F1/STM32F1.ino | 51 +- Microcontroller_Code/UNO/UNO.ino | 25 +- Microcontroller_Code/UNO/UNO_newmod.ino | 139 --- 8 files changed, 859 insertions(+), 2149 deletions(-) delete mode 100644 Computer_Interface/processing_for_MEGA.pde delete mode 100644 Computer_Interface/processing_for_UNO_newmod.pde delete mode 100644 Microcontroller_Code/UNO/UNO_newmod.ino diff --git a/Computer_Interface/processing.pde b/Computer_Interface/processing.pde index d217f6e..cc48223 100644 --- a/Computer_Interface/processing.pde +++ b/Computer_Interface/processing.pde @@ -8,12 +8,15 @@ Serial p; //uncomment the line where your arduino/STM32 is connected //String LA_port = "/dev/ttyACM0"; //linux DFU //String LA_port = "/dev/ttyUSB0"; //linux Serial -String LA_port = "COM10"; //windows +String LA_port = "COM3"; //windows final int baudrate = 115200; //check if it is the same in arduino -//change it to true if you are using a STM32 instead of arduino UNO, MEGA or ESP8266 -final boolean STM32 = false; +//Uncomment the board that you are using +//String board ="MEGA"; +String board ="UNO"; +//String board ="STM32F1"; +//String board ="ESP8266"; /*------------------END SETUP-----------------*/ //////////////////////////////////////////////// @@ -23,24 +26,26 @@ final boolean STM32 = false; int white = 255; int black = 0; int green = #00FF00; +int red = #FF0000; int grey = 150; // shift, reducer and millisecond view float reducer = 1.0; -boolean milliseconds = false; +boolean milliseconds = true; float xShift; // start point in the processing window -int xEdge = 60; -int yEdge = 30; -int xEnd; -float[] xPos = {0, 0, 0, 0, 0, 0}; -int yBottom; -int yDiff; -int yPos = yEdge; -int ySave = yEdge; +float xEdge = 60; +float yEdge = 10; +float xEnd; +float oldxEnd; +float[] xPos = new float[16]; +float yBottom; +float yDiff; +float yPos = yEdge; +float ySave = yEdge; boolean textCovered; boolean drawTimes = true; @@ -49,16 +54,101 @@ boolean drawTimes = true; //initial data int samples; int event; -int initialState; +int initialState[]= new int[3]; boolean first = false; boolean dataComplete = false; //following data -boolean [][] state; -boolean [] isLow = new boolean[6]; +boolean [][][] state; +boolean [][] isLow = new boolean[8][3]; +boolean [][] isLowinit = new boolean[8][3]; float[] usTime; float[] xTime; -int[] pinChanged; +int[][] pinChanged; +int[] PinAssignment = new int[16]; +int[] PinArduinoNames = new int[16]; +int index1; +int index2; +int index3; +boolean refresh= true; +int []cursora= new int[2]; +float cursoraf= 0; +boolean cursorplay=false; +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// .___ __ __ .__ +// | | ____ _______/ |________ __ __ _____/ |_|__| ____ ____ ______ +// | |/ \ / ___/\ __\_ __ \ | \_/ ___\ __\ |/ _ \ / \ / ___/ +// | | | \\___ \ | | | | \/ | /\ \___| | | ( <_> ) | \\___ \ +// |___|___| /____ > |__| |__| |____/ \___ >__| |__|\____/|___| /____ > +// \/ \/ \/ \/ \/ +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +/* +ENGLISH +Operation of the pin assignment. +The entries will be depleted in the order they appear in the whole PinAssignment that goes from 0 to 15 for a total of 16, the value of the integer in each position will +reference the pin to be used. Then the value that must be entered in the integer will be shown to observe the desired pin. + +In case you do not want to show anything on that channel, just assign 00 so that the channel will not be written. +The pins that do not appear in the table can not be used because they were not considered in the arduino programming, to avoid overloading the +arduino and obtain more satisfactory response times. + +Notes: + +If you are using an Arduino MEGA you shoud know that, since the arduino MEGA2560 has enough pins more than the arduino one, and also its processor can reach 2MHz and I suppose it must also have a better IPC ratio (Instructions per cycle) +this code read 24 pins of which we will deplete 16 in the program, among the reasons to do this are, the location of the pins which are not always where one would like, +and the mapping of the digital pins in the arduino microcontroller, since I wanted to take advantage of the greater number of pins doing the fewer instructions to avoid +damaging the process. + +SPANISH +Funcionamiento de la asignacion de pines. + +Las entradas se deplegaran en el orden que aparezcan en el entero PinAssignment que va del 0 al 15 para un total de 16, el valor del entero en cada posicion referenciara +el pin a utilizar. A continuacion se mostrara el valor que se debe introducir en el entero para observar el pin deseado. + +En caso de no querer mostrar nada en ese canal basta con asignar 00 para que el canal no sea escrito. +Los pines que no aparecen en la tabla no podrán ser utilizados por que no fueron considerados en la programacion de arduino, esto para evitar sobrecargar al +arduino y obtener tiempos de respuesta más satisfactorios. + +Notas: + +Si utilizas el Arduino MEGA deberias saber, que dado que el arduino MEGA2560 tiene bastantes pines más que el arduino uno, y además su procesador puede llegar a los 2MHz y supongo también debe de tener un mejor ratio +IPC (Instrucciones por ciclo) el codigo hace lectura de 24 pines de los cuales deplegaremos 16 en el programa, entre las razones para hacer esto estan, la ubicacion de los +pines los cuales no siempre estan donde uno quisiera, y el mapeo de los pines digitales en el microcontrolador del arduino, ya que la intencion es aprovechar la mayor cantidad de +pines haciendo la menor cantidad de instrucciones para no perjudicar el proceso. + +Si utilizas un Arduino STM32 deberias saber, que este es mucho mas potente que un Arduino UNO o MEGA, por lo que puede ser utilizado para lecturas mas veloces, ademas en este caso +se disponen de todos los pines B ("PB") por lo que se tienen varios canales para trabajar. + + Number to enter in the Arduino Arduino Arduino Arduino + PinAssignment UNO MEGA STM32 ESP8266 + 10 -------> DigitalPIN 8 -------> DigitalPIN 22 -------> PB 0 -------> DigitalPIN1 + 11 -------> DigitalPIN 9 -------> DigitalPIN 23 -------> PB 1 -------> DigitalPIN2 + 12 -------> DigitalPIN 10 -------> DigitalPIN 24 -------> PB 2 -------> DigitalPIN5 + 13 -------> DigitalPIN 11 -------> DigitalPIN 25 -------> PB 3 -------> DigitalPIN6 + 14 -------> DigitalPIN 12 -------> DigitalPIN 26 -------> PB 4 -------> OFF + 15 -------> DigitalPIN 13 -------> DigitalPIN 27 -------> PB 5 -------> OFF + 16 -------> OFF -------> DigitalPIN 28 -------> PB 6 -------> OFF + 17 -------> OFF -------> DigitalPIN 29 -------> PB 7 -------> OFF + 20 -------> OFF -------> DigitalPIN 49 -------> PB 8 -------> OFF + 21 -------> OFF -------> DigitalPIN 48 -------> PB 9 -------> OFF + 22 -------> OFF -------> DigitalPIN 47 -------> PB 10 -------> OFF + 23 -------> OFF -------> DigitalPIN 46 -------> PB 11 -------> OFF + 24 -------> OFF -------> DigitalPIN 45 -------> PB 12 -------> OFF + 25 -------> OFF -------> DigitalPIN 44 -------> PB 13 -------> OFF + 26 -------> OFF -------> DigitalPIN 43 -------> PB 14 -------> OFF + 27 -------> OFF -------> DigitalPIN 42 -------> PB 15 -------> OFF + 30 -------> OFF -------> DigitalPIN 37 -------> OFF -------> OFF + 31 -------> OFF -------> DigitalPIN 36 -------> OFF -------> OFF + 32 -------> OFF -------> DigitalPIN 35 -------> OFF -------> OFF + 33 -------> OFF -------> DigitalPIN 34 -------> OFF -------> OFF + 34 -------> OFF -------> DigitalPIN 33 -------> OFF -------> OFF + 35 -------> OFF -------> DigitalPIN 32 -------> OFF -------> OFF + 36 -------> OFF -------> DigitalPIN 31 -------> OFF -------> OFF + 37 -------> OFF -------> DigitalPIN 30 -------> OFF -------> OFF + Any other -------> OFF -------> OFF -------> OFF -------> OFF + + +*/ //buttons and others int button1X = 8; @@ -74,7 +164,8 @@ int graphBoxH; int textBoxH; int immage = 1; int corner = 10; - +String s; +boolean initial=true; // bar scroll int handleFill = grey; @@ -91,10 +182,220 @@ void setup () { p = new Serial(this, LA_port, baudrate); p.bufferUntil('\n'); - size(1000, 460); + size(1300, 700); 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. + //Aquí escoges los pines que quieres desplegar. + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // _____ _____ _ _ _ _ + // | __ \_ _| \ | | /\ (_) | | + // | |__) || | | \| | / \ ___ ___ _ __ _ _ __ _ __ ___ ___ _ __ | |_ + // | ___/ | | | . ` | / /\ \ / __/ __| |/ _` | '_ \| '_ ` _ \ / _ \ '_ \| __| + // | | _| |_| |\ |/ ____ \\__ \__ \ | (_| | | | | | | | | | __/ | | | |_ + // |_| |_____|_| \_/_/ \_\___/___/_|\__, |_| |_|_| |_| |_|\___|_| |_|\__| + // __/ | + // |___/ + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + PinAssignment[0] = 10; + PinAssignment[1] = 11; + PinAssignment[2] = 12; + PinAssignment[3] = 13; + PinAssignment[4] = 14; + PinAssignment[5] = 15; + PinAssignment[6] = 16; + PinAssignment[7] = 17; + PinAssignment[8] = 20; + PinAssignment[9] = 21; + PinAssignment[10]= 22; + PinAssignment[11]= 23; + PinAssignment[12]= 24; + PinAssignment[13]= 25; + PinAssignment[14]= 26; + PinAssignment[15]= 27; + + for (int i=0; i<16; i++) { + if (board == "MEGA"){ + switch (PinAssignment[i]) { + case (10): + PinArduinoNames[i]=22; + break; + case (11): + PinArduinoNames[i]=23; + break; + case (12): + PinArduinoNames[i]=24; + break; + case (13): + PinArduinoNames[i]=25; + break; + case (14): + PinArduinoNames[i]=26; + break; + case (15): + PinArduinoNames[i]=27; + break; + case (16): + PinArduinoNames[i]=28; + break; + case (17): + PinArduinoNames[i]=29; + break; + case (20): + PinArduinoNames[i]=49; + break; + case (21): + PinArduinoNames[i]=48; + break; + case (22): + PinArduinoNames[i]=47; + break; + case (23): + PinArduinoNames[i]=46; + break; + case (24): + PinArduinoNames[i]=45; + break; + case (25): + PinArduinoNames[i]=44; + break; + case (26): + PinArduinoNames[i]=43; + break; + case (27): + PinArduinoNames[i]=42; + break; + case (30): + PinArduinoNames[i]=37; + break; + case (31): + PinArduinoNames[i]=36; + break; + case (32): + PinArduinoNames[i]=35; + break; + case (33): + PinArduinoNames[i]=34; + break; + case (34): + PinArduinoNames[i]=33; + break; + case (35): + PinArduinoNames[i]=32; + break; + case (36): + PinArduinoNames[i]=31; + break; + case (37): + PinArduinoNames[i]=30; + break; + default: + PinArduinoNames[i]=00; + break; + } + }else if (board=="UNO") { + switch (PinAssignment[i]) { + case (10): + PinArduinoNames[i]=8; + break; + case (11): + PinArduinoNames[i]=9; + break; + case (12): + PinArduinoNames[i]=10; + break; + case (13): + PinArduinoNames[i]=11; + break; + case (14): + PinArduinoNames[i]=12; + break; + case (15): + PinArduinoNames[i]=13; + break; + default: + PinArduinoNames[i]=00; + break; + + } + }else if (board=="STM32F1") { + switch (PinAssignment[i]) { + case (10): + PinArduinoNames[i]=100; + break; + case (11): + PinArduinoNames[i]=1; + break; + case (12): + PinArduinoNames[i]=2; + break; + case (13): + PinArduinoNames[i]=3; + break; + case (14): + PinArduinoNames[i]=4; + break; + case (15): + PinArduinoNames[i]=5; + break; + case (16): + PinArduinoNames[i]=6; + break; + case (17): + PinArduinoNames[i]=7; + break; + case (20): + PinArduinoNames[i]=8; + break; + case (21): + PinArduinoNames[i]=9; + break; + case (22): + PinArduinoNames[i]=10; + break; + case (23): + PinArduinoNames[i]=11; + break; + case (24): + PinArduinoNames[i]=12; + break; + case (25): + PinArduinoNames[i]=13; + break; + case (26): + PinArduinoNames[i]=14; + break; + case (27): + PinArduinoNames[i]=15; + break; + default: + PinArduinoNames[i]=00; + break; + + } + }else if (board=="ESP8266") { + switch (PinAssignment[i]) { + case (10): + PinArduinoNames[i]=1; + break; + case (11): + PinArduinoNames[i]=2; + break; + case (12): + PinArduinoNames[i]=5; + break; + case (13): + PinArduinoNames[i]=6; + break; + default: + PinArduinoNames[i]=00; + break; + + } + } + } graphBoxH = height -50; textBoxH = height - 35; yBottom = graphBoxH-20; @@ -106,7 +407,7 @@ void setup () { void cleanGraph() { noStroke(); //no borders - fill(black); + fill(black); rect(xEdge, 0, width, graphBoxH); //cancel the graph stroke(green); //green lines Arrays.fill(xPos, 0); //reset start point of the graph @@ -114,64 +415,109 @@ void cleanGraph() { } -void draw () { +void draw() { - if (dataComplete==true) { + if (dataComplete==true) { cleanGraph(); pushMatrix(); //move the coordinate reference translate(xEdge, 0); - for (int i=0; i// + yDiff=yPos; + yPos+=30; + + } else { + yDiff=yPos+30; + } + isLow[index1][index2]=isLowinit[index1][index2]; + //println(isLowinit[index1][index2]); + } + else { + if (isLow[index1][index2]) { //pin high else low + yDiff=yPos; + yPos+=30; + isLow[index1][index2]=false; + } else { + yDiff=yPos+30; + isLow[index1][index2]=true; + } + } + + + + // Graph 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 (cursora[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); + } } yPos = yEdge; - for (int n = 0; n < 6; n++) { - if (xPos[n]!=0) { //draw only the pin which are active - if (isLow[n]==true) line(xPos[n]+xShift, yPos+30, xEnd+xShift, yPos+30); - else line(xPos[n]+xShift, yPos, xEnd+xShift, yPos); + for (int n = 0; n < 16; n++) { + if (PinAssignment[n]!=0){ + s= str(PinAssignment[n]); + index1 = s.charAt(1)-'0'; + index2 = s.charAt(0)-'1'; + if (xPos[n]==0) { + if (isLowinit[index1][index2]==true) line(xPos[n]+xShift, yPos+30, xEnd+xShift, yPos+30); + else line(xPos[n]+xShift, yPos, xEnd+xShift, yPos); + } + } - yPos+=60; + yPos+=36; } - dataComplete = false; popMatrix(); } @@ -180,7 +526,6 @@ void draw () { void drawText() { - stroke(white); //white borders fill(black); rect(0, 0, xEdge, graphBoxH); //clean left side @@ -189,29 +534,36 @@ void drawText() { // write name of the pins - fill(white); + fill(white); textSize(14); - int x=10; - int y=50; + int x=5; + int y=30; - if (STM32) { - for (byte i = 12; i<=15; i++) { + for (byte i = 0; i<16; i++) { line(x, y-20, xEdge, y-20); line(x, y+10, xEdge, y+10); - text ("PB"+i, x, y); - y+=60; + 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; } - } else { - - for (byte i = 8; i<=13; i++) { - line(x, y-20, xEdge, y-20); - line(x, y+10, xEdge, y+10); - text ("Pin "+i, x, y); - y+=60; - } - } + // draw buttons fill(grey); @@ -222,79 +574,225 @@ void drawText() { rect(button4X, buttonY, smallButtonW, buttonH, corner); rect(button5X, buttonY, smallButtonW, buttonH, corner); fill(white); - text("T:"+ str (drawTimes), button1X+3, yBottom); + text("Start", button2X+3, buttonY+14); - text(milliseconds == true ? "milliseconds" : "microseconds", button3X+3, buttonY+14); - text(reducer, button4X+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); if (isDraggable) { - handleX = mouseX-(handleW/2); + handleX = mouseX-handleW/2; if (handleXwidth-handleW) handleX = width-handleW; - - getData(); - xShift = -map(handleX, xEdge, width-handleW, 0, xEnd-900); + if (handleX>width-handleW) handleX = width-handleW; + updatepos(); + dataComplete = true; + + } + } void mousePressed() { - if (mouseX>handleX && mouseXxEdge && mouseXhandleY && mouseYxTime[samples-1]){ + if (cursoraf<=0){ + cursora[0]=0; + } + if (cursoraf>=xTime[samples-1]){ + cursora[0]=samples-1; + } + }else{ + for (int i=1; iabs(xTime[i+1]-cursoraf)&&state[i][index1][index2]){ + if (abs(xTime[i]-cursoraf)>abs(xTime[i+1]-cursoraf)){ + if(state[i][index1][index2]){ + cursora[0]=i; + } + }else { + break; + } + //println (abs(xTime[i]+xShift)); + //println ("wut"); + } + } + } + println( cursora[0]); + dataComplete=true; +} +void updatepos(){ + if (samples!=0) { + xEnd = (xTime[samples-1]); + // xEnd = xEnd + } else { + xEnd = 0; + } + xShift = -map(handleX, xEdge, width-handleW, 0, xEnd); + xShift = xShift + (width-handleW)/2; -void mouseReleased() { - isDraggable = false; - handleFill = grey; } +void movepos(){ + xShift = xTime[cursora[0]]; + handleX = map(xShift, 0, xEnd, xEdge, width-handleW); + xShift = -xShift - (width-handleW)/2; +dataComplete=true; + +} + +void keyPressed() { + int number; + if (key == CODED) { + if (keyCode == UP && cursorplay) { + number=cursora[1]; + cursora[1]= cursora[1]-1; + for (int i=cursora[1]; i>=0; i--){ + if (PinAssignment[cursora[1]]==0){ + cursora[1]= cursora[1]-1; + }else { + break; + } + } + if (cursora[1]==-1){ + cursora[1]= number; + } + cursora[1]=constrain(cursora[1], 0, 16); + //println("cur1 "+cursora[1]+"cur0 "+cursora[0]); + dataComplete=true; + } else if (keyCode == DOWN && cursorplay) { + if(cursora[1]<16){ + cursora[1]= cursora[1]+1; + for (int i=cursora[1]; i<16; i++){ + if (PinAssignment[cursora[1]]==0){ + cursora[1]= cursora[1]+1; + }else { + break; + } + + cursora[1]=constrain(cursora[1], 0, 16); + } } + //println("cur1 "+cursora[1]+"cur0 "+cursora[0]); + dataComplete=true; + } else if (keyCode == RIGHT && cursorplay) { + if (cursora[1]==16){ + if (cursora[0]!=samples-1){ + cursora[0]+=1; + } + } + else{ + s = str(PinAssignment[cursora[1]]); + index1 = s.charAt(1)-'0'; + index2 = s.charAt(0)-'1'; + //println(cursora[0]); + for (int i=cursora[0]+1; i-1; i--){ + cursora[0]=i; + if (state[i][index1][index2]){ + break; + }else { + + } } + } + //println("cur1 "+cursora[1]+"cur0 "+cursora[0]); + //updatepos(); + movepos(); + }else if (keyCode == LEFT && !cursorplay) { + handleX-=1; + if (handleXwidth-handleW) handleX = width-handleW; + dataComplete=true; + }else if (keyCode == RIGHT && !cursorplay) { + handleX+=1; + if (handleXwidth-handleW) handleX = width-handleW; + dataComplete=true; + } + } +} void mouseClicked() { + // bootons over signals + if(mouseX>xEdge && mouseX yBottom-15 && mouseY xEdge && mouseX yEdge && mouseY xEdge && mouseX yEdge+36 && mouseY xEdge && mouseX yEdge+36*2 && mouseY xEdge && mouseX yEdge+36*3 && mouseY xEdge && mouseX yEdge+36*4 && mouseY xEdge && mouseX yEdge+36*5 && mouseY xEdge && mouseX yEdge+36*6 && mouseY xEdge && mouseX yEdge+36*7 && mouseY xEdge && mouseX yEdge+36*8 && mouseY xEdge && mouseX yEdge+36*9 && mouseY xEdge && mouseX yEdge+36*10 && mouseY xEdge && mouseX yEdge+36*11 && mouseY xEdge && mouseX yEdge+36*12 && mouseY xEdge && mouseX yEdge+36*13 && mouseY xEdge && mouseX yEdge+36*14 && mouseY xEdge && mouseX yEdge+36*15 && mouseY yBottom-15 && mouseY button1X && mouseX buttonY && mouseY button2X && mouseX buttonY && mouseY button3X && mouseX buttonY && mouseY buttonY && mouseY button4X && mouseX 90 && !milliseconds){ + reducer=0.1; + milliseconds = !milliseconds; + } + reducer = constrain(reducer, 0.1, 100); + } else { //move the graph + if (reducer<=1){ + reducer-= 0.1; + }else if (reducer<=10){ + reducer-=1; + }else { + reducer-=10; + } + if (reducer<0.1 && milliseconds){ + reducer=100; + milliseconds = !milliseconds; + } + reducer = constrain(reducer, 0.1, 90); + } + scaletime(); + updatepos(); + dataComplete=true; + } else + // micro or millis + if (mouseY>buttonY && mouseY button3X && mouseX buttonY && mouseY button4X && mouseX width-handleW) handleX = width-handleW; + dataComplete=true; + } @@ -331,25 +883,46 @@ void mouseMoved() { cursor(HAND); } else if (mouseY>buttonY && mouseY button5X && mouseX yBottom-15 && mouseY button1X && mouseX buttonY && mouseY button4X && mouseX yBottom-15 && mouseY button1X && mouseX handleX && mouseXhandleY && mouseYxEdge && mouseX yBottom-15 && mouseY xEdge && mouseX yEdge && mouseY xEdge && mouseX yEdge+36 && mouseY xEdge && mouseX yEdge+36*2 && mouseY xEdge && mouseX yEdge+36*3 && mouseY xEdge && mouseX yEdge+36*4 && mouseY xEdge && mouseX yEdge+36*5 && mouseY xEdge && mouseX yEdge+36*6 && mouseY xEdge && mouseX yEdge+36*7 && mouseY xEdge && mouseX yEdge+36*8 && mouseY xEdge && mouseX yEdge+36*9 && mouseY xEdge && mouseX yEdge+36*10 && mouseY xEdge && mouseX yEdge+36*11 && mouseY xEdge && mouseX yEdge+36*12 && mouseY xEdge && mouseX yEdge+36*13 && mouseY xEdge && mouseX yEdge+36*14 && mouseY xEdge && mouseX yEdge+36*15 && mouseY 0) - { - int i; - boolean drawLine = true; // alternate between dashes and gaps + 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. + /* + 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); + 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) - { + i = 0; + while (drawn < distance) + { + if (drawLine) + { line(x0, y0, x0 + xSpacing[i], y0 + ySpacing[i]); - } - 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 + 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/processing_for_MEGA.pde b/Computer_Interface/processing_for_MEGA.pde deleted file mode 100644 index 7b1b444..0000000 --- a/Computer_Interface/processing_for_MEGA.pde +++ /dev/null @@ -1,936 +0,0 @@ - -import processing.serial.*; -import java.util.Arrays; -Serial p; - -//////////////////////////////////////////////// -/*--------------------SETUP-------------------*/ - -//uncomment the line where your arduino/STM32 is connected -//String LA_port = "/dev/ttyACM0"; //linux DFU -//String LA_port = "/dev/ttyUSB0"; //linux Serial -String LA_port = "COM3"; //windows - -final int baudrate = 115200; //check if it is the same in arduino - - -/*------------------END SETUP-----------------*/ -//////////////////////////////////////////////// - - -//colors: -int white = 255; -int black = 0; -int green = #00FF00; -int red = #FF0000; -int grey = 150; - - -// shift, reducer and millisecond view -float reducer = 1.0; -boolean milliseconds = true; -float xShift; - - -// start point in the processing window -float xEdge = 60; -float yEdge = 10; -float xEnd; -float oldxEnd; -float[] xPos = new float[16]; -float yBottom; -float yDiff; -float yPos = yEdge; -float ySave = yEdge; -boolean textCovered; -boolean drawTimes = true; - - -//Serial from mcu -//initial data -int samples; -int event; -int initialState[]= new int[3]; -boolean first = false; -boolean dataComplete = false; -//following data -boolean [][][] state; -boolean [][] isLow = new boolean[8][3]; -boolean [][] isLowinit = new boolean[8][3]; -float[] usTime; -float[] xTime; -int[][] pinChanged; -int[] PinAssignment = new int[16]; -int[] PinArduinoNames = new int[16]; -int index1; -int index2; -int index3; -boolean refresh= true; -int []cursora= new int[2]; -float cursoraf= 0; -boolean cursorplay=false; - - - -/* -ENGLISH -How the assign of the pins works?. -Since the arduino MEGA2560 has enough pins more than the arduino one, and also its processor can reach 2MHz and I suppose it must also have a better IPC ratio (Instructions per cycle) -I decided to read 24 pins of which we will deplete 16 in the program, among the reasons to do this are, the location of the pins which are not always where one would like, -and the mapping of the digital pins in the arduino microcontroller, since I wanted to take advantage of the greater number of pins doing the fewer instructions to avoid -damaging the process. - -The entries will be depleted in the order they appear in the whole PinAssignment that goes from 0 to 15 for a total of 16, the value of the integer in each position will -reference the pin to be used. Then the value that must be entered in the integer will be shown to observe the desired pin. - -In case you do not want to show anything on that channel, just assign 00 so that the channel will not be written. -The pins that do not appear in the table can not be used because they were not considered in the arduino programming, to avoid overloading the -arduino and obtain more satisfactory response times. - -SPANISH -Funcionamiento de la asignacion de pines. -Dado que el arduino MEGA2560 tiene bastantes pines más que el arduino uno, y además su procesador puede llegar a los 2MHz y supongo también debe de tener un mejor ratio -IPC (Instrucciones por ciclo) decidí hacer lectura de 24 pines de los cuales deplegaremos 16 en el programa, entre las razones para hacer esto estan, la ubicacion de los -pines los cuales no siempre estan donde uno quisiera, y el mapeo de los pines digitales en el microcontrolador del arduino, ya que queria aprovechar la mayor cantidad de -pines haciendo la menor cantidad de instrucciones para no perjudicar el proceso. - -Las entradas se deplegaran en el orden que aparezcan en el entero PinAssignment que va del 0 al 15 para un total de 16, el valor del entero en cada posicion referenciara -el pin a utilizar. A continuacion se mostrara el valor que se debe introducir en el entero para observar el pin deseado. - -En caso de no querer mostrar nada en ese canal basta con asignar 00 para que el canal no sea escrito. -Los pines que no aparecen en la tabla no podrán ser utilizados por que no fueron considerados en la programacion de arduino, esto para evitar sobrecargar al -arduino y obtener tiempos de respuesta más satisfactorios. - -EN Number of Pin in the Arduino Mega Number to enter in the PinAssignment -ES Numero de Pin en el Arduino Mega Numero a introducir en el PinAssignment -Digital PIN 22 -------------------------------------------------------> 10 -Digital PIN 23 -------------------------------------------------------> 11 -Digital PIN 24 -------------------------------------------------------> 12 -Digital PIN 25 -------------------------------------------------------> 13 -Digital PIN 26 -------------------------------------------------------> 14 -Digital PIN 27 -------------------------------------------------------> 15 -Digital PIN 28 -------------------------------------------------------> 16 -Digital PIN 29 -------------------------------------------------------> 17 -Digital PIN 49 -------------------------------------------------------> 20 -Digital PIN 48 -------------------------------------------------------> 21 -Digital PIN 47 -------------------------------------------------------> 22 -Digital PIN 46 -------------------------------------------------------> 23 -Digital PIN 45 -------------------------------------------------------> 24 -Digital PIN 44 -------------------------------------------------------> 25 -Digital PIN 43 -------------------------------------------------------> 26 -Digital PIN 42 -------------------------------------------------------> 27 -Digital PIN 37 -------------------------------------------------------> 30 -Digital PIN 36 -------------------------------------------------------> 31 -Digital PIN 35 -------------------------------------------------------> 32 -Digital PIN 34 -------------------------------------------------------> 33 -Digital PIN 33 -------------------------------------------------------> 34 -Digital PIN 32 -------------------------------------------------------> 35 -Digital PIN 31 -------------------------------------------------------> 36 -Digital PIN 30 -------------------------------------------------------> 37 - - - -*/ - -//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; -String s; -boolean initial=true; - -// bar scroll -int handleFill = grey; -float handleX; -float handleY; -float handleW = 20; -float handleH = 15; -boolean isDraggable = false; - - - -void setup () { - //p = new Serial(this, Serial.list()[0], 115200); - p = new Serial(this, LA_port, baudrate); - p.bufferUntil('\n'); - - size(1300, 700); - 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. - //Aquí escoges los pines que quieres desplegar. - PinAssignment[0] = 10; - PinAssignment[1] = 11; - PinAssignment[2] = 12; - PinAssignment[3] = 13; - PinAssignment[4] = 14; - PinAssignment[5] = 15; - PinAssignment[6] = 16; - PinAssignment[7] = 17; - PinAssignment[8] = 20; - PinAssignment[9] = 21; - PinAssignment[10]= 22; - PinAssignment[11]= 23; - PinAssignment[12]= 24; - PinAssignment[13]= 25; - PinAssignment[14]= 26; - PinAssignment[15]= 27; - - for (int i=0; i<16; i++) { - switch (PinAssignment[i]) { - case (10): - PinArduinoNames[i]=22; - break; - case (11): - PinArduinoNames[i]=23; - break; - case (12): - PinArduinoNames[i]=24; - break; - case (13): - PinArduinoNames[i]=25; - break; - case (14): - PinArduinoNames[i]=26; - break; - case (15): - PinArduinoNames[i]=27; - break; - case (16): - PinArduinoNames[i]=28; - break; - case (17): - PinArduinoNames[i]=29; - break; - case (20): - PinArduinoNames[i]=49; - break; - case (21): - PinArduinoNames[i]=48; - break; - case (22): - PinArduinoNames[i]=47; - break; - case (23): - PinArduinoNames[i]=46; - break; - case (24): - PinArduinoNames[i]=45; - break; - case (25): - PinArduinoNames[i]=44; - break; - case (26): - PinArduinoNames[i]=43; - break; - case (27): - PinArduinoNames[i]=42; - break; - case (30): - PinArduinoNames[i]=37; - break; - case (31): - PinArduinoNames[i]=36; - break; - case (32): - PinArduinoNames[i]=35; - break; - case (33): - PinArduinoNames[i]=34; - break; - case (34): - PinArduinoNames[i]=33; - break; - case (35): - PinArduinoNames[i]=32; - break; - case (36): - PinArduinoNames[i]=31; - break; - case (37): - PinArduinoNames[i]=30; - break; - default: - PinArduinoNames[i]=00; - break; - - } - } - 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 draw() { - - if (dataComplete==true) { - cleanGraph(); - pushMatrix(); //move the coordinate reference - translate(xEdge, 0); - float firstchange; - boolean cares; - if (cursorplay){ - fill(50); - stroke(75); - if(cursora[1]==16){ //Esta variable la utilizamos para definir el canal sobre el cual estamos trabajando, en esta parte marcamos el rectangulo en el que trabajamos. - rect(0, yBottom-12, width-xEdge, 34); - } - else{ - rect(0, yEdge+36*cursora[1]-2, width-xEdge, 34); - } - stroke(green); - } - updatepos(); //Se encarga de decir que segmento de tiempos se va a escribir - for (int i=0; i// - yDiff=yPos; - yPos+=30; - - } else { - yDiff=yPos+30; - } - isLow[index1][index2]=isLowinit[index1][index2]; - //println(isLowinit[index1][index2]); - } - else { - if (isLow[index1][index2]) { //pin high else low - yDiff=yPos; - yPos+=30; - isLow[index1][index2]=false; - } else { - yDiff=yPos+30; - isLow[index1][index2]=true; - } - } - - - - // Graph 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 (cursora[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); - } - } - - yPos = yEdge; - for (int n = 0; n < 16; n++) { - if (PinAssignment[n]!=0){ - s= str(PinAssignment[n]); - index1 = s.charAt(1)-'0'; - index2 = s.charAt(0)-'1'; - if (xPos[n]==0) { - if (isLowinit[index1][index2]==true) line(xPos[n]+xShift, yPos+30, xEnd+xShift, yPos+30); - else line(xPos[n]+xShift, yPos, xEnd+xShift, yPos); - } - - } - yPos+=36; - } - dataComplete = false; - popMatrix(); - } - drawText(); -} - - -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; - - /* if (STM32) { - - for (byte i = 12; i<=15; i++) { - line(x, y-20, xEdge, y-20); - line(x, y+10, xEdge, y+10); - text ("PB"+i, x, y); - y+=60; - } - } else { -*/ - 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 (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); - - if (isDraggable) { - handleX = mouseX-handleW/2; - if (handleXwidth-handleW) handleX = width-handleW; - updatepos(); - dataComplete = true; - - - } - -} - - -void mousePressed() { - if (mouseX>xEdge && mouseXhandleY && mouseYxTime[samples-1]){ - if (cursoraf<=0){ - cursora[0]=0; - } - if (cursoraf>=xTime[samples-1]){ - cursora[0]=samples-1; - } - }else{ - for (int i=1; iabs(xTime[i+1]-cursoraf)&&state[i][index1][index2]){ - if (abs(xTime[i]-cursoraf)>abs(xTime[i+1]-cursoraf)){ - if(state[i][index1][index2]){ - cursora[0]=i; - } - }else { - break; - } - //println (abs(xTime[i]+xShift)); - //println ("wut"); - } - } - } - println( cursora[0]); - dataComplete=true; -} -void updatepos(){ - if (samples!=0) { - xEnd = (xTime[samples-1]); - // xEnd = xEnd - } else { - xEnd = 0; - } - xShift = -map(handleX, xEdge, width-handleW, 0, xEnd); - xShift = xShift + (width-handleW)/2; - -} - -void movepos(){ - xShift = xTime[cursora[0]]; - handleX = map(xShift, 0, xEnd, xEdge, width-handleW); - xShift = -xShift - (width-handleW)/2; -dataComplete=true; - -} - -void keyPressed() { - int number; - if (key == CODED) { - if (keyCode == UP && cursorplay) { - number=cursora[1]; - cursora[1]= cursora[1]-1; - for (int i=cursora[1]; i>=0; i--){ - if (PinAssignment[cursora[1]]==0){ - cursora[1]= cursora[1]-1; - }else { - break; - } - } - if (cursora[1]==-1){ - cursora[1]= number; - } - cursora[1]=constrain(cursora[1], 0, 16); - //println("cur1 "+cursora[1]+"cur0 "+cursora[0]); - dataComplete=true; - } else if (keyCode == DOWN && cursorplay) { - if(cursora[1]<16){ - cursora[1]= cursora[1]+1; - for (int i=cursora[1]; i<16; i++){ - if (PinAssignment[cursora[1]]==0){ - cursora[1]= cursora[1]+1; - }else { - break; - } - - cursora[1]=constrain(cursora[1], 0, 16); - } } - //println("cur1 "+cursora[1]+"cur0 "+cursora[0]); - dataComplete=true; - } else if (keyCode == RIGHT && cursorplay) { - if (cursora[1]==16){ - if (cursora[0]!=samples-1){ - cursora[0]+=1; - } - } - else{ - s = str(PinAssignment[cursora[1]]); - index1 = s.charAt(1)-'0'; - index2 = s.charAt(0)-'1'; - //println(cursora[0]); - for (int i=cursora[0]+1; i-1; i--){ - cursora[0]=i; - if (state[i][index1][index2]){ - break; - }else { - - } } - } - //println("cur1 "+cursora[1]+"cur0 "+cursora[0]); - //updatepos(); - movepos(); - }else if (keyCode == LEFT && !cursorplay) { - handleX-=1; - if (handleXwidth-handleW) handleX = width-handleW; - dataComplete=true; - }else if (keyCode == RIGHT && !cursorplay) { - handleX+=1; - if (handleXwidth-handleW) handleX = width-handleW; - dataComplete=true; - } - } -} - -void mouseClicked() { - - // bootons over signals - if(mouseX>xEdge && mouseX yBottom-15 && mouseY xEdge && mouseX yEdge && mouseY xEdge && mouseX yEdge+36 && mouseY xEdge && mouseX yEdge+36*2 && mouseY xEdge && mouseX yEdge+36*3 && mouseY xEdge && mouseX yEdge+36*4 && mouseY xEdge && mouseX yEdge+36*5 && mouseY xEdge && mouseX yEdge+36*6 && mouseY xEdge && mouseX yEdge+36*7 && mouseY xEdge && mouseX yEdge+36*8 && mouseY xEdge && mouseX yEdge+36*9 && mouseY xEdge && mouseX yEdge+36*10 && mouseY xEdge && mouseX yEdge+36*11 && mouseY xEdge && mouseX yEdge+36*12 && mouseY xEdge && mouseX yEdge+36*13 && mouseY xEdge && mouseX yEdge+36*14 && mouseY xEdge && mouseX yEdge+36*15 && mouseY yBottom-15 && mouseY button1X && mouseX buttonY && mouseY button2X && mouseX buttonY && mouseY button5X && mouseX buttonY && mouseY button4X && mouseX 90 && !milliseconds){ - reducer=0.1; - milliseconds = !milliseconds; - } - reducer = constrain(reducer, 0.1, 100); - } else { //move the graph - if (reducer<=1){ - reducer-= 0.1; - }else if (reducer<=10){ - reducer-=1; - }else { - reducer-=10; - } - if (reducer<0.1 && milliseconds){ - reducer=100; - milliseconds = !milliseconds; - } - reducer = constrain(reducer, 0.1, 90); - } - scaletime(); - updatepos(); - dataComplete=true; - } else - // micro or millis - if (mouseY>buttonY && mouseY button3X && mouseX width-handleW) handleX = width-handleW; - dataComplete=true; - -} - - -void mouseMoved() { - if (mouseY>buttonY && mouseY button2X && mouseX buttonY && mouseY button3X && mouseX buttonY && mouseY button5X && mouseX buttonY && mouseY button4X && mouseX yBottom-15 && mouseY button1X && mouseX handleX && mouseXhandleY && mouseYxEdge && mouseX yBottom-15 && mouseY xEdge && mouseX yEdge && mouseY xEdge && mouseX yEdge+36 && mouseY xEdge && mouseX yEdge+36*2 && mouseY xEdge && mouseX yEdge+36*3 && mouseY xEdge && mouseX yEdge+36*4 && mouseY xEdge && mouseX yEdge+36*5 && mouseY xEdge && mouseX yEdge+36*6 && mouseY xEdge && mouseX yEdge+36*7 && mouseY xEdge && mouseX yEdge+36*8 && mouseY xEdge && mouseX yEdge+36*9 && mouseY xEdge && mouseX yEdge+36*10 && mouseY xEdge && mouseX yEdge+36*11 && mouseY xEdge && mouseX yEdge+36*12 && mouseY xEdge && mouseX yEdge+36*13 && mouseY xEdge && mouseX yEdge+36*14 && mouseY xEdge && mouseX yEdge+36*15 && mouseY 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/processing_for_UNO_newmod.pde b/Computer_Interface/processing_for_UNO_newmod.pde deleted file mode 100644 index 198299c..0000000 --- a/Computer_Interface/processing_for_UNO_newmod.pde +++ /dev/null @@ -1,854 +0,0 @@ - -import processing.serial.*; -import java.util.Arrays; -Serial p; - -//////////////////////////////////////////////// -/*--------------------SETUP-------------------*/ - -//uncomment the line where your arduino/STM32 is connected -//String LA_port = "/dev/ttyACM0"; //linux DFU -//String LA_port = "/dev/ttyUSB0"; //linux Serial -String LA_port = "COM3"; //windows - -final int baudrate = 115200; //check if it is the same in arduino - - -/*------------------END SETUP-----------------*/ -//////////////////////////////////////////////// - - -//colors: -int white = 255; -int black = 0; -int green = #00FF00; -int red = #FF0000; -int grey = 150; - - -// shift, reducer and millisecond view -float reducer = 1.0; -boolean milliseconds = true; -float xShift; - - -// start point in the processing window -float xEdge = 60; -float yEdge = 10; -float xEnd; -float oldxEnd; -float[] xPos = new float[16]; -float yBottom; -float yDiff; -float yPos = yEdge; -float ySave = yEdge; -boolean textCovered; -boolean drawTimes = true; - - -//Serial from mcu -//initial data -int samples; -int event; -int initialState[]= new int[3]; -boolean first = false; -boolean dataComplete = false; -//following data -boolean [][][] state; -boolean [][] isLow = new boolean[8][3]; -boolean [][] isLowinit = new boolean[8][3]; -float[] usTime; -float[] xTime; -int[][] pinChanged; -int[] PinAssignment = new int[16]; -int[] PinArduinoNames = new int[16]; -int index1; -int index2; -int index3; -boolean refresh= true; -int []cursora= new int[2]; -float cursoraf= 0; -boolean cursorplay=false; - - - -/* -ENGLISH -How the assign of the pins works?. -The entries will be depleted in the order they appear in the whole PinAssignment that goes from 0 to 15 for a total of 16, the value of the integer in each position will -reference the pin to be used. Then the value that must be entered in the integer will be shown to observe the desired pin. - -In case you do not want to show anything on that channel, just assign 00 so that the channel will not be written. -The pins that do not appear in the table can not be used because they were not considered in the arduino programming, to avoid overloading the -arduino and obtain more satisfactory response times. - -SPANISH -Funcionamiento de la asignacion de pines. -Las entradas se deplegaran en el orden que aparezcan en el entero PinAssignment que va del 0 al 15 para un total de 16, el valor del entero en cada posicion referenciara -el pin a utilizar. A continuacion se mostrara el valor que se debe introducir en el entero para observar el pin deseado. - -En caso de no querer mostrar nada en ese canal basta con asignar 00 para que el canal no sea escrito. -Los pines que no aparecen en la tabla no podrán ser utilizados por que no fueron considerados en la programacion de arduino, esto para evitar sobrecargar al -arduino y obtener tiempos de respuesta más satisfactorios. - -EN Number of Pin in the Arduino UNO Number to enter in the PinAssignment -ES Numero de Pin en el Arduino UNO Numero a introducir en el PinAssignment -Digital PIN 8 -------------------------------------------------------> 10 -Digital PIN 9 -------------------------------------------------------> 11 -Digital PIN 10 -------------------------------------------------------> 12 -Digital PIN 11 -------------------------------------------------------> 13 -Digital PIN 12 -------------------------------------------------------> 14 -Digital PIN 13 -------------------------------------------------------> 15 - - - -*/ - -//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; -String s; -boolean initial=true; - -// bar scroll -int handleFill = grey; -float handleX; -float handleY; -float handleW = 20; -float handleH = 15; -boolean isDraggable = false; - - - -void setup () { - //p = new Serial(this, Serial.list()[0], 115200); - p = new Serial(this, LA_port, baudrate); - p.bufferUntil('\n'); - - size(1300, 700); - 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. - //Aquí escoges los pines que quieres desplegar. - PinAssignment[0] = 10; - PinAssignment[1] = 11; - PinAssignment[2] = 12; - PinAssignment[3] = 13; - PinAssignment[4] = 14; - PinAssignment[5] = 15; - PinAssignment[6] = 00; - PinAssignment[7] = 00; - PinAssignment[8] = 00; - PinAssignment[9] = 00; - PinAssignment[10]= 00; - PinAssignment[11]= 00; - PinAssignment[12]= 00; - PinAssignment[13]= 00; - PinAssignment[14]= 00; - PinAssignment[15]= 00; - - for (int i=0; i<16; i++) { - switch (PinAssignment[i]) { - case (10): - PinArduinoNames[i]=08; - break; - case (11): - PinArduinoNames[i]=09; - break; - case (12): - PinArduinoNames[i]=10; - break; - case (13): - PinArduinoNames[i]=11; - break; - case (14): - PinArduinoNames[i]=12; - break; - case (15): - PinArduinoNames[i]=13; - break; - default: - PinArduinoNames[i]=00; - break; - - } - } - 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 draw() { - - if (dataComplete==true) { - cleanGraph(); - pushMatrix(); //move the coordinate reference - translate(xEdge, 0); - float firstchange; - boolean cares; - if (cursorplay){ - fill(50); - stroke(75); - if(cursora[1]==16){ //Esta variable la utilizamos para definir el canal sobre el cual estamos trabajando, en esta parte marcamos el rectangulo en el que trabajamos. - rect(0, yBottom-12, width-xEdge, 34); - } - else{ - rect(0, yEdge+36*cursora[1]-2, width-xEdge, 34); - } - stroke(green); - } - updatepos(); //Se encarga de decir que segmento de tiempos se va a escribir - for (int i=0; i// - yDiff=yPos; - yPos+=30; - - } else { - yDiff=yPos+30; - } - isLow[index1][index2]=isLowinit[index1][index2]; - //println(isLowinit[index1][index2]); - } - else { - if (isLow[index1][index2]) { //pin high else low - yDiff=yPos; - yPos+=30; - isLow[index1][index2]=false; - } else { - yDiff=yPos+30; - isLow[index1][index2]=true; - } - } - - - - // Graph 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 (cursora[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); - } - } - - yPos = yEdge; - for (int n = 0; n < 16; n++) { - if (PinAssignment[n]!=0){ - s= str(PinAssignment[n]); - index1 = s.charAt(1)-'0'; - index2 = s.charAt(0)-'1'; - if (xPos[n]==0) { - if (isLowinit[index1][index2]==true) line(xPos[n]+xShift, yPos+30, xEnd+xShift, yPos+30); - else line(xPos[n]+xShift, yPos, xEnd+xShift, yPos); - } - - } - yPos+=36; - } - dataComplete = false; - popMatrix(); - } - drawText(); -} - - -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; - - /* if (STM32) { - - for (byte i = 12; i<=15; i++) { - line(x, y-20, xEdge, y-20); - line(x, y+10, xEdge, y+10); - text ("PB"+i, x, y); - y+=60; - } - } else { -*/ - 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 (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); - - if (isDraggable) { - handleX = mouseX-handleW/2; - if (handleXwidth-handleW) handleX = width-handleW; - updatepos(); - dataComplete = true; - - - } - -} - - -void mousePressed() { - if (mouseX>xEdge && mouseXhandleY && mouseYxTime[samples-1]){ - if (cursoraf<=0){ - cursora[0]=0; - } - if (cursoraf>=xTime[samples-1]){ - cursora[0]=samples-1; - } - }else{ - for (int i=1; iabs(xTime[i+1]-cursoraf)&&state[i][index1][index2]){ - if (abs(xTime[i]-cursoraf)>abs(xTime[i+1]-cursoraf)){ - if(state[i][index1][index2]){ - cursora[0]=i; - } - }else { - break; - } - //println (abs(xTime[i]+xShift)); - //println ("wut"); - } - } - } - println( cursora[0]); - dataComplete=true; -} -void updatepos(){ - if (samples!=0) { - xEnd = (xTime[samples-1]); - // xEnd = xEnd - } else { - xEnd = 0; - } - xShift = -map(handleX, xEdge, width-handleW, 0, xEnd); - xShift = xShift + (width-handleW)/2; - -} - -void movepos(){ - xShift = xTime[cursora[0]]; - handleX = map(xShift, 0, xEnd, xEdge, width-handleW); - xShift = -xShift - (width-handleW)/2; -dataComplete=true; - -} - -void keyPressed() { - int number; - if (key == CODED) { - if (keyCode == UP && cursorplay) { - number=cursora[1]; - cursora[1]= cursora[1]-1; - for (int i=cursora[1]; i>=0; i--){ - if (PinAssignment[cursora[1]]==0){ - cursora[1]= cursora[1]-1; - }else { - break; - } - } - if (cursora[1]==-1){ - cursora[1]= number; - } - cursora[1]=constrain(cursora[1], 0, 16); - //println("cur1 "+cursora[1]+"cur0 "+cursora[0]); - dataComplete=true; - } else if (keyCode == DOWN && cursorplay) { - if(cursora[1]<16){ - cursora[1]= cursora[1]+1; - for (int i=cursora[1]; i<16; i++){ - if (PinAssignment[cursora[1]]==0){ - cursora[1]= cursora[1]+1; - }else { - break; - } - - cursora[1]=constrain(cursora[1], 0, 16); - } } - //println("cur1 "+cursora[1]+"cur0 "+cursora[0]); - dataComplete=true; - } else if (keyCode == RIGHT && cursorplay) { - if (cursora[1]==16){ - if (cursora[0]!=samples-1){ - cursora[0]+=1; - } - } - else{ - s = str(PinAssignment[cursora[1]]); - index1 = s.charAt(1)-'0'; - index2 = s.charAt(0)-'1'; - //println(cursora[0]); - for (int i=cursora[0]+1; i-1; i--){ - cursora[0]=i; - if (state[i][index1][index2]){ - break; - }else { - - } } - } - //println("cur1 "+cursora[1]+"cur0 "+cursora[0]); - //updatepos(); - movepos(); - }else if (keyCode == LEFT && !cursorplay) { - handleX-=1; - if (handleXwidth-handleW) handleX = width-handleW; - dataComplete=true; - }else if (keyCode == RIGHT && !cursorplay) { - handleX+=1; - if (handleXwidth-handleW) handleX = width-handleW; - dataComplete=true; - } - } -} - -void mouseClicked() { - - // bootons over signals - if(mouseX>xEdge && mouseX yBottom-15 && mouseY xEdge && mouseX yEdge && mouseY xEdge && mouseX yEdge+36 && mouseY xEdge && mouseX yEdge+36*2 && mouseY xEdge && mouseX yEdge+36*3 && mouseY xEdge && mouseX yEdge+36*4 && mouseY xEdge && mouseX yEdge+36*5 && mouseY xEdge && mouseX yEdge+36*6 && mouseY xEdge && mouseX yEdge+36*7 && mouseY xEdge && mouseX yEdge+36*8 && mouseY xEdge && mouseX yEdge+36*9 && mouseY xEdge && mouseX yEdge+36*10 && mouseY xEdge && mouseX yEdge+36*11 && mouseY xEdge && mouseX yEdge+36*12 && mouseY xEdge && mouseX yEdge+36*13 && mouseY xEdge && mouseX yEdge+36*14 && mouseY xEdge && mouseX yEdge+36*15 && mouseY yBottom-15 && mouseY button1X && mouseX buttonY && mouseY button2X && mouseX buttonY && mouseY button5X && mouseX buttonY && mouseY button4X && mouseX 90 && !milliseconds){ - reducer=0.1; - milliseconds = !milliseconds; - } - reducer = constrain(reducer, 0.1, 100); - } else { //move the graph - if (reducer<=1){ - reducer-= 0.1; - }else if (reducer<=10){ - reducer-=1; - }else { - reducer-=10; - } - if (reducer<0.1 && milliseconds){ - reducer=100; - milliseconds = !milliseconds; - } - reducer = constrain(reducer, 0.1, 90); - } - scaletime(); - updatepos(); - dataComplete=true; - } else - // micro or millis - if (mouseY>buttonY && mouseY button3X && mouseX width-handleW) handleX = width-handleW; - dataComplete=true; - -} - - -void mouseMoved() { - if (mouseY>buttonY && mouseY button2X && mouseX buttonY && mouseY button3X && mouseX buttonY && mouseY button5X && mouseX buttonY && mouseY button4X && mouseX yBottom-15 && mouseY button1X && mouseX handleX && mouseXhandleY && mouseYxEdge && mouseX yBottom-15 && mouseY xEdge && mouseX yEdge && mouseY xEdge && mouseX yEdge+36 && mouseY xEdge && mouseX yEdge+36*2 && mouseY xEdge && mouseX yEdge+36*3 && mouseY xEdge && mouseX yEdge+36*4 && mouseY xEdge && mouseX yEdge+36*5 && mouseY xEdge && mouseX yEdge+36*6 && mouseY xEdge && mouseX yEdge+36*7 && mouseY xEdge && mouseX yEdge+36*8 && mouseY xEdge && mouseX yEdge+36*9 && mouseY xEdge && mouseX yEdge+36*10 && mouseY xEdge && mouseX yEdge+36*11 && mouseY xEdge && mouseX yEdge+36*12 && mouseY xEdge && mouseX yEdge+36*13 && mouseY xEdge && mouseX yEdge+36*14 && mouseY xEdge && mouseX yEdge+36*15 && mouseY 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/Microcontroller_Code/ESP8266/ESP8266.ino b/Microcontroller_Code/ESP8266/ESP8266.ino index 3ea3bed..53d9b0a 100644 --- a/Microcontroller_Code/ESP8266/ESP8266.ino +++ b/Microcontroller_Code/ESP8266/ESP8266.ino @@ -9,6 +9,7 @@ #define baudrate 115200 // check if it is the same in processing // number of samples to collect +#define timezerooffset 125 static const int N_SAMPLES = 300; @@ -40,6 +41,7 @@ void setup() { unsigned long times[N_SAMPLES]; // when did change happen uint32_t values[N_SAMPLES]; // GPI value at time +uint32_t timefix; extern void ICACHE_RAM_ATTR collect() { times[0] = micros(); @@ -73,15 +75,20 @@ int compactValue(uint32_t value) { void report() { Serial.println("S"); - Serial.print(compactValue(values[0])); - Serial.print(":"); - Serial.println(N_SAMPLES - 1); - - for (int i = 1; i < N_SAMPLES; ++i) { - Serial.print(compactValue(values[i] ^ values[i - 1])); - Serial.print(":"); - Serial.println(times[i] - times[0]); + Serial.print(compactValue(values[0])); Serial.print(','); Serial.print(B00000000); Serial.print(','); Serial.print(B00000000); Serial.print(":"); + Serial.println(N_SAMPLES +1); + timefix = -times[0]+timezerooffset; + for (int i = 0; i < N_SAMPLES; i++) { + times[i]=times[i]+timefix; } + Serial.print(B11111111);Serial.print(','); Serial.print(B11111111); Serial.print(','); Serial.print(B11111111); Serial.print(":");//Este segmento de codigo introduce un cambio en todos los + Serial.println(0); + for (int i = 1; i < N_SAMPLES; ++i) { + Serial.print(compactValue(values[i] ^ values[i - 1])); Serial.print(','); Serial.print(B00000000); Serial.print(','); Serial.print(B00000000); Serial.print(":"); + Serial.println(times[i]); + } + Serial.print(B11111111);Serial.print(','); Serial.print(B11111111); Serial.print(','); Serial.print(B11111111); Serial.print(":"); + Serial.println((times[N_SAMPLES-1]+400)); } void loop() { diff --git a/Microcontroller_Code/MEGA/MEGA.ino b/Microcontroller_Code/MEGA/MEGA.ino index e6b24a7..fea308f 100644 --- a/Microcontroller_Code/MEGA/MEGA.ino +++ b/Microcontroller_Code/MEGA/MEGA.ino @@ -1,14 +1,14 @@ /* - * LA.cpp + * * * Created: 11/12/2016 19.35.51 * Author : Vincenzo */ #define baudrate 115200 //check if it is the same in processing -#define samples 400 +#define samples 500 #define timezerooffset 125 //microsegundos -#define PULLUP true //Si queremos entradas con PULLUP lo dejamos activado(true), si queremos dejarlas al "aire" (false), en caso de desactivarlo deberemos aterrizar todos los pines que no utilizemos. +#define PULLUP true//Si queremos entradas con PULLUP lo dejamos activado(true), si queremos dejarlas al "aire" (false), en caso de desactivarlo deberemos aterrizar todos los pines que no utilizemos. #define F_CPU 16000000UL #include #include @@ -111,16 +111,15 @@ void sendData() { //initial data Serial.println("S"); Serial.print(initial1); Serial.print(','); Serial.print(initial2); Serial.print(','); Serial.print(initial3); Serial.print(":"); - Serial.println(samples+3); + Serial.println(samples+2); timefix = -timer[0]+timezerooffset; for (int i = 0; i < samples; i++) { timer[i]=timer[i]+timefix; } Serial.print(B11111111);Serial.print(','); Serial.print(B11111111); Serial.print(','); Serial.print(B11111111); Serial.print(":");//Este segmento de codigo introduce un cambio en todos los Serial.println(0); //canales, lo que soluciona un error en el codigo en processing - Serial.print(B11111111);Serial.print(','); Serial.print(B11111111); Serial.print(','); Serial.print(B11111111); Serial.print(":");//al final se hace un cambio en todos los canales, lo que soluciona - Serial.println(1); //otro pequeño fallo visual. - //data + //al final se hace un cambio en todos los canales, lo que soluciona //otro pequeño fallo visual. + //data for (int i = 0; i < samples; i++) { Serial.print(pinChanged1[i]);Serial.print(','); Serial.print(pinChanged2[i]); Serial.print(','); Serial.print(pinChanged3[i]); Serial.print(":"); Serial.println(timer[i]); diff --git a/Microcontroller_Code/STM32F1/STM32F1.ino b/Microcontroller_Code/STM32F1/STM32F1.ino index a0cb99b..de53ea9 100644 --- a/Microcontroller_Code/STM32F1/STM32F1.ino +++ b/Microcontroller_Code/STM32F1/STM32F1.ino @@ -9,12 +9,13 @@ #define baudrate 115200 // check if it is the same in processing #define samples 200 // the number of samples you want to take -#define boardLed PB1 +#define boardLed PA1 -uint8_t initial, state, old_state; -uint8_t pinChanged[samples]; +uint16_t initial, state, old_state; +uint16_t pinChanged[samples]; +uint8_t initial1, initial2, pinChanged1, pinChanged2; uint32_t timer[samples]; uint16_t event = 0; @@ -27,7 +28,18 @@ void setup() { pinMode (boardLed, OUTPUT); digitalWrite(boardLed, LOW); - + pinMode(PB0, INPUT_PULLUP); + pinMode(PB1, INPUT_PULLUP); + pinMode(PB2, INPUT_PULLUP); + pinMode(PB3, INPUT_PULLUP); + pinMode(PB4, INPUT_PULLUP); + pinMode(PB5, INPUT_PULLUP); + pinMode(PB6, INPUT_PULLUP); + pinMode(PB7, INPUT_PULLUP); + pinMode(PB8, INPUT_PULLUP); + pinMode(PB9, INPUT_PULLUP); + pinMode(PB10, INPUT_PULLUP); + pinMode(PB11, INPUT_PULLUP); pinMode(PB12, INPUT_PULLUP); pinMode(PB13, INPUT_PULLUP); pinMode(PB14, INPUT_PULLUP); @@ -45,15 +57,20 @@ void startLA() { digitalWrite(boardLed, HIGH); reset_timer(); - initial = GPIOB->regs->IDR >> 12; + initial = GPIOB->regs->IDR; state = initial; + for (int i=0; i < samples; i++) { + pinChanged[i]=0; + //Serial.print(pinChanged1[i]); Serial.print(','); Serial.print(pinChanged2[i]); Serial.print(','); Serial.println(pinChanged3[i]); + + } } void loop() { old_state = state; - state = GPIOB->regs->IDR >> 12; + state = GPIOB->regs->IDR; if (old_state != state) { timer[event] = micros(); @@ -72,15 +89,27 @@ void sendData() { digitalWrite(boardLed, LOW); //initial data + initial1=initial; + initial2=initial>>8; Serial.println("S"); - Serial.print(initial); Serial.print(":"); - Serial.println(samples); - - //data + Serial.print(initial1); Serial.print(','); Serial.print(initial2); Serial.print(','); Serial.print(B00000000); Serial.print(":"); + Serial.println(samples+2); + timefix = -timer[0]+timezerooffset; for (int i = 0; i < samples; i++) { - Serial.print(pinChanged[i]); Serial.print(":"); + timer[i]=timer[i]+timefix; + } + Serial.print(B11111111);Serial.print(','); Serial.print(B11111111); Serial.print(','); Serial.print(B11111111); Serial.print(":");//Este segmento de codigo introduce un cambio en todos los + Serial.println(0); //canales, lo que soluciona un error en el codigo en processing + //al final se hace un cambio en todos los canales, lo que soluciona //otro pequeño fallo visual. + //data + for (int i = 0; i < samples; i++) { + pinChanged1=pinChanged; + pinChanged2=pinChanged>>8; + Serial.print(pinChanged1);Serial.print(','); Serial.print(pinChanged2); Serial.print(','); Serial.print(B00000000); Serial.print(":"); Serial.println(timer[i]); } + Serial.print(B11111111);Serial.print(','); Serial.print(B11111111); Serial.print(','); Serial.print(B11111111); Serial.print(":"); + Serial.println((timer[samples-1]+400)); } void reset_timer() { diff --git a/Microcontroller_Code/UNO/UNO.ino b/Microcontroller_Code/UNO/UNO.ino index 7a39992..72c6ab3 100644 --- a/Microcontroller_Code/UNO/UNO.ino +++ b/Microcontroller_Code/UNO/UNO.ino @@ -8,7 +8,7 @@ #define baudrate 115200 // check if it is the same in processing #define samples 200 // the number of samples you want to take - +#define timezerooffset 125 //microsegundos #define F_CPU 16000000UL #include #include @@ -19,6 +19,7 @@ volatile uint16_t timer1_overflow_count; uint8_t initial, state, old_state; uint8_t pinChanged[samples]; uint32_t timer[samples]; +uint32_t timefix; uint16_t event = 0; void init_board() { @@ -78,7 +79,10 @@ void start() { PORTC = (1 << 0); initial = PINB; state = initial; - + for (int i=0; i < samples; i++) { + pinChanged[i]=0; + + } } @@ -86,15 +90,22 @@ void sendData() { PORTC = (0 << 0); //turn off led //initial data - Serial.println("S"); - Serial.print(initial); Serial.print(":"); - Serial.println(samples); - + Serial.println("S"); + Serial.print(initial); Serial.print(','); Serial.print(B11111111); Serial.print(','); Serial.print(B11111111); Serial.print(":"); + Serial.println(samples+2); + timefix = -timer[0]+timezerooffset; + for (int i = 0; i < samples; i++) { + timer[i]=timer[i]+timefix; + } + Serial.print(B11111111);Serial.print(','); Serial.print(B11111111); Serial.print(','); Serial.print(B11111111); Serial.print(":");//Este segmento de codigo introduce un cambio en todos los + Serial.println(0); //canales evita fallo visual. //data for (int i = 0; i < samples; i++) { - Serial.print(pinChanged[i]); Serial.print(":"); + Serial.print(pinChanged[i]);Serial.print(','); Serial.print(B00000000); Serial.print(','); Serial.print(B00000000); Serial.print(":"); Serial.println(timer[i]); } + Serial.print(B11111111);Serial.print(','); Serial.print(B11111111); Serial.print(','); Serial.print(B11111111); Serial.print(":"); + Serial.println((timer[samples-1]+400)); } diff --git a/Microcontroller_Code/UNO/UNO_newmod.ino b/Microcontroller_Code/UNO/UNO_newmod.ino deleted file mode 100644 index 426ef4d..0000000 --- a/Microcontroller_Code/UNO/UNO_newmod.ino +++ /dev/null @@ -1,139 +0,0 @@ -/* - * UNO.ino - * - * Created: 11/12/2016 19.35.51 - * Author : Vincenzo - * Led on A0 - */ - -#define baudrate 115200 // check if it is the same in processing -#define samples 200 // the number of samples you want to take -#define timezerooffset 125 //microsegundos -#define F_CPU 16000000UL -#include -#include -#include -#define prescaler 0x02 -volatile uint16_t timer1_overflow_count; - -uint8_t initial, state, old_state; -uint8_t pinChanged[samples]; -uint32_t timer[samples]; -uint32_t timefix; -uint16_t event = 0; - -void init_board() { - - PORTC = (0 << 0); DDRC |= (1 << 0); // led A0 - DDRB |= 0x00; // pin 8-13 input - PORTB |= 0x3F; // pull-up - -} - -void init_timer() { - - //clear - TCCR1A = 0b00000000; - TCCR1B = 0b00000000; - TIMSK1 = 0b00000000; - - //settings - TCCR1A |= (0 << COM1A1) | (0 << COM1A0) | (0 << COM1B1) | (0 << COM1B0); //normal port operation - TCCR1A |= (0 << WGM11) | (0 << WGM10); //normal operation - TCCR1B |= (0 << WGM13) | (0 << WGM12); //normal operation - TCCR1B |= prescaler; //(0 << CS12) | (0 << CS11) | (1 << CS10); //clock prescaler - - sei(); //enable interrupts - TIMSK1 |= (1 << TOIE1); // enable overflow interrupt - -} - -ISR(TIMER1_OVF_vect) { - timer1_overflow_count++; -} - -void reset_timer1 () { - TCNT1 = 0; - timer1_overflow_count = 0; -} - -uint32_t myMicros () { - cli(); - - if (TIFR1 & (1 << TOV1)) { - TIFR1 = (0 << TOV1); - timer1_overflow_count++; - } - - uint32_t total_time = (65536 * timer1_overflow_count + TCNT1) / 2; - sei(); - return total_time; -} - -void start() { - _delay_ms(1000); - - reset_timer1(); - event = 0; - - PORTC = (1 << 0); - initial = PINB; - state = initial; - for (int i=0; i < samples; i++) { - pinChanged[i]=0; - - } -} - - -void sendData() { - PORTC = (0 << 0); //turn off led - - //initial data - Serial.println("S"); - Serial.print(initial); Serial.print(','); Serial.print(B11111111); Serial.print(','); Serial.print(B11111111); Serial.print(":"); - Serial.println(samples+3); - timefix = -timer[0]+timezerooffset; - for (int i = 0; i < samples; i++) { - timer[i]=timer[i]+timefix; - } - Serial.print(B11111111);Serial.print(','); Serial.print(B11111111); Serial.print(','); Serial.print(B11111111); Serial.print(":");//Este segmento de codigo introduce un cambio en todos los - Serial.println(0); //canales, lo que soluciona un error en el codigo en processing - Serial.print(B11111111);Serial.print(','); Serial.print(B11111111); Serial.print(','); Serial.print(B11111111); Serial.print(":");//al final se hace un cambio en todos los canales, lo que soluciona - Serial.println(1); //otro pequeño fallo visual. - //data - for (int i = 0; i < samples; i++) { - Serial.print(pinChanged[i]);Serial.print(','); Serial.print(B00000000); Serial.print(','); Serial.print(B00000000); Serial.print(":"); - Serial.println(timer[i]); - } - Serial.print(B11111111);Serial.print(','); Serial.print(B11111111); Serial.print(','); Serial.print(B11111111); Serial.print(":"); - Serial.println((timer[samples-1]+400)); -} - - -int main(void) { - Serial.begin(baudrate); - - init_board(); - init_timer(); - - start(); - - while (1) { - - old_state = state; - state = PINB; - - if (old_state != state) { - timer[event] = myMicros(); - pinChanged[event] = state ^ old_state; - event++; - - if (event == samples) { - sendData(); - while (Serial.read() != 'G') ; //wait for the "go" - start(); - } - } - } -} From 0d3b249c5a341db17979addf1c443108a18c5fcd Mon Sep 17 00:00:00 2001 From: sancho11 Date: Fri, 25 Jan 2019 19:33:03 -0600 Subject: [PATCH 4/4] Some things are ready -Fixed Scroll reducer. -Some functions were broken down into simpler functions, to facilitate the reading of the code. -The spanish comments were changed to english -Some variables like cursera or curseraf now they have names that give meaning to what they are. --- Computer_Interface/Computer_Interface.pde | 1312 +++++++++++++++++++++ Computer_Interface/processing.pde | 1064 ----------------- {tester => Extras/tester}/tester.ino | 16 +- Microcontroller_Code/ESP8266/ESP8266.ino | 3 +- Microcontroller_Code/MEGA/MEGA.ino | 26 +- Microcontroller_Code/STM32F1/STM32F1.ino | 12 +- 6 files changed, 1338 insertions(+), 1095 deletions(-) create mode 100644 Computer_Interface/Computer_Interface.pde delete mode 100644 Computer_Interface/processing.pde rename {tester => Extras/tester}/tester.ino (58%) diff --git a/Computer_Interface/Computer_Interface.pde b/Computer_Interface/Computer_Interface.pde new file mode 100644 index 0000000..d330b72 --- /dev/null +++ b/Computer_Interface/Computer_Interface.pde @@ -0,0 +1,1312 @@ +//////////////////////////////////////////////// +/*--------------------SETUP-------------------*/ + +//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 + +//Uncomment the board that you are using +//String board = "MEGA"; +String board = "UNO"; +//String board = "STM32F1"; +//String board = "ESP8266"; +//String board = "CUSTOM" + +/*------------------END SETUP-----------------*/ +//////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// .___ __ __ .__ +// | | ____ _______/ |________ __ __ _____/ |_|__| ____ ____ ______ +// | |/ \ / ___/\ __\_ __ \ | \_/ ___\ __\ |/ _ \ / \ / ___/ +// | | | \\___ \ | | | | \/ | /\ \___| | | ( <_> ) | \\___ \ +// |___|___| /____ > |__| |__| |____/ \___ >__| |__|\____/|___| /____ > +// \/ \/ \/ \/ \/ +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +/* + ENGLISH + Operation of the pin assignment. + The entries will be depleted in the order they appear in the whole PinAssignment that goes from 0 to 15 for a total of 16, the value of the integer in each position will + reference the pin to be used. Then the value that must be entered in the integer will be shown to observe the desired pin. + + In case you do not want to show anything on that channel, just assign 0 so that the channel will not be written. + The pins that do not appear in the table can not be used because they were not considered in the arduino programming, to avoid overloading the + arduino and obtain more satisfactory response times. + + Notes: + + If you are using an Arduino MEGA you shoud know that, since the arduino MEGA2560 has enough pins more than the arduino one, and also its processor can reach 2MHz and I suppose it must also have a better IPC ratio (Instructions per cycle) + this code read 24 pins of which we will deplete 16 in the program, among the reasons to do this are, the location of the pins which are not always where one would like, + and the mapping of the digital pins in the arduino microcontroller, since I wanted to take advantage of the greater number of pins doing the fewer instructions to avoid + damaging the process. + + If you use an Arduino STM32 you should know, that this is much more powerful than an Arduino UNO or MEGA, so it can be used for faster readings, + besides in this case all pins B ("PB") are available. that you have several channels to work with. + + + PinAssignment UNO MEGA STM32 ESP8266 + 10 -------> DigitalPIN 8 -------> DigitalPIN 22 -------> PB 0 -------> DigitalPIN1 + 11 -------> DigitalPIN 9 -------> DigitalPIN 23 -------> PB 1 -------> DigitalPIN2 + 12 -------> DigitalPIN 10 -------> DigitalPIN 24 -------> PB 2 -------> DigitalPIN5 + 13 -------> DigitalPIN 11 -------> DigitalPIN 25 -------> PB 3 -------> DigitalPIN6 + 14 -------> DigitalPIN 12 -------> DigitalPIN 26 -------> PB 4 -------> OFF + 15 -------> OFF -------> DigitalPIN 27 -------> PB 5 -------> OFF + 16 -------> OFF -------> DigitalPIN 28 -------> PB 6 -------> OFF + 17 -------> OFF -------> DigitalPIN 29 -------> PB 7 -------> OFF + 20 -------> OFF -------> DigitalPIN 49 -------> PB 8 -------> OFF + 21 -------> OFF -------> DigitalPIN 48 -------> PB 9 -------> OFF + 22 -------> OFF -------> DigitalPIN 47 -------> PB 10 -------> OFF + 23 -------> OFF -------> DigitalPIN 46 -------> PB 11 -------> OFF + 24 -------> OFF -------> DigitalPIN 45 -------> PB 12 -------> OFF + 25 -------> OFF -------> DigitalPIN 44 -------> PB 13 -------> OFF + 26 -------> OFF -------> DigitalPIN 43 -------> PB 14 -------> OFF + 27 -------> OFF -------> DigitalPIN 42 -------> PB 15 -------> OFF + 30 -------> OFF -------> DigitalPIN 37 -------> OFF -------> OFF + 31 -------> OFF -------> DigitalPIN 36 -------> OFF -------> OFF + 32 -------> OFF -------> DigitalPIN 35 -------> OFF -------> OFF + 33 -------> OFF -------> DigitalPIN 34 -------> OFF -------> OFF + 34 -------> OFF -------> DigitalPIN 33 -------> OFF -------> OFF + 35 -------> OFF -------> DigitalPIN 32 -------> OFF -------> OFF + 36 -------> OFF -------> DigitalPIN 31 -------> OFF -------> OFF + 37 -------> OFF -------> DigitalPIN 30 -------> OFF -------> OFF + Any other -------> OFF -------> OFF -------> OFF -------> OFF +*/ + +import processing.serial.*; +import java.util.Arrays; +Serial board_port; + +//colors: +int white = 255; +int black = 0; +int green = #00FF00; +int red = #FF0000; +int grey = 150; + +// shift, reducer and millisecond view +float reducer = 1.0; +boolean milliseconds = true; +float xShift; + +// start point in the processing window +float xEdge = 60; +float yEdge = 10; +float xEnd; +float oldxEnd; +float[] xPos = new float[16]; +float yBottom; +float yDiff; +float yPos = yEdge; +float ySave = yEdge; +boolean textCovered; +boolean drawTimes = true; + +// Serial from mcu +int samples; +int event; +int initialState[] = new int[3]; +boolean first = false; +boolean dataComplete = true; +boolean[][][] state; +boolean[][] isLow = new boolean[8][3]; +boolean[][] isLowInit = new boolean[8][3]; +float[] usTime; +float[] xTime; +int[][] pinChanged; +int[] PinAssignment = new int[16]; +int[] PinArduinoNames = new int[16]; +int index1; +int index2; +int index3; +boolean refresh = true; +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; +String s; +boolean initial = true; + +// bar scroll +int handleFill = grey; +float handleX; +float handleY; +float handleW = 20; +float handleH = 15; +boolean isDraggable = false; + +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); + 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. + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // _____ _____ _ _ _ _ + // | __ \_ _| \ | | /\ (_) | | + // | |__) || | | \| | / \ ___ ___ _ __ _ _ __ _ __ ___ ___ _ __ | |_ + // | ___/ | | | . ` | / /\ \ / __/ __| |/ _` | '_ \| '_ ` _ \ / _ \ '_ \| __| + // | | _| |_| |\ |/ ____ \\__ \__ \ | (_| | | | | | | | | | __/ | | | |_ + // |_| |_____|_| \_/_/ \_\___/___/_|\__, |_| |_|_| |_| |_|\___|_| |_|\__| + // __/ | + // |___/ + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + PinAssignment[0] = 10; + PinAssignment[1] = 11; + PinAssignment[2] = 12; + PinAssignment[3] = 13; + PinAssignment[4] = 14; + PinAssignment[5] = 15; + PinAssignment[6] = 16; + PinAssignment[7] = 17; + PinAssignment[8] = 20; + PinAssignment[9] = 21; + PinAssignment[10] = 22; + PinAssignment[11] = 23; + PinAssignment[12] = 24; + PinAssignment[13] = 25; + PinAssignment[14] = 26; + PinAssignment[15] = 27; + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + for (int i = 0; i < 16; i++) + { + if (board == "MEGA") + { + switch (PinAssignment[i]) + { + case (10): + PinArduinoNames[i] = 22; + break; + case (11): + PinArduinoNames[i] = 23; + break; + case (12): + PinArduinoNames[i] = 24; + break; + case (13): + PinArduinoNames[i] = 25; + break; + case (14): + PinArduinoNames[i] = 26; + break; + case (15): + PinArduinoNames[i] = 27; + break; + case (16): + PinArduinoNames[i] = 28; + break; + case (17): + PinArduinoNames[i] = 29; + break; + case (20): + PinArduinoNames[i] = 49; + break; + case (21): + PinArduinoNames[i] = 48; + break; + case (22): + PinArduinoNames[i] = 47; + break; + case (23): + PinArduinoNames[i] = 46; + break; + case (24): + PinArduinoNames[i] = 45; + break; + case (25): + PinArduinoNames[i] = 44; + break; + case (26): + PinArduinoNames[i] = 43; + break; + case (27): + PinArduinoNames[i] = 42; + break; + case (30): + PinArduinoNames[i] = 37; + break; + case (31): + PinArduinoNames[i] = 36; + break; + case (32): + PinArduinoNames[i] = 35; + break; + case (33): + PinArduinoNames[i] = 34; + break; + case (34): + PinArduinoNames[i] = 33; + break; + case (35): + PinArduinoNames[i] = 32; + break; + case (36): + PinArduinoNames[i] = 31; + break; + case (37): + PinArduinoNames[i] = 30; + break; + default: + PinArduinoNames[i] = 0; + break; + } + } + + else if (board == "UNO") + { + switch (PinAssignment[i]) + { + case (10): + PinArduinoNames[i] = 8; + break; + case (11): + PinArduinoNames[i] = 9; + break; + case (12): + PinArduinoNames[i] = 10; + break; + case (13): + PinArduinoNames[i] = 11; + break; + case (14): + PinArduinoNames[i] = 12; + break; + default: + PinArduinoNames[i] = 0; + break; + } + } + + else if (board == "STM32F1") + { + switch (PinAssignment[i]) + { + case (10): + PinArduinoNames[i] = 100; + break; + case (11): + PinArduinoNames[i] = 1; + break; + case (12): + PinArduinoNames[i] = 2; + break; + case (13): + PinArduinoNames[i] = 3; + break; + case (14): + PinArduinoNames[i] = 4; + break; + case (15): + PinArduinoNames[i] = 5; + break; + case (16): + PinArduinoNames[i] = 6; + break; + case (17): + PinArduinoNames[i] = 7; + break; + case (20): + PinArduinoNames[i] = 8; + break; + case (21): + PinArduinoNames[i] = 9; + break; + case (22): + PinArduinoNames[i] = 10; + break; + case (23): + PinArduinoNames[i] = 11; + break; + case (24): + PinArduinoNames[i] = 12; + break; + case (25): + PinArduinoNames[i] = 13; + break; + case (26): + PinArduinoNames[i] = 14; + break; + case (27): + PinArduinoNames[i] = 15; + break; + default: + PinArduinoNames[i] = 0; + break; + } + } + else if (board == "ESP8266") + { + switch (PinAssignment[i]) + { + case (10): + PinArduinoNames[i] = 1; + break; + case (11): + PinArduinoNames[i] = 2; + break; + case (12): + PinArduinoNames[i] = 5; + break; + case (13): + PinArduinoNames[i] = 6; + break; + default: + PinArduinoNames[i] = 0; + break; + } + } + } + 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(); + 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(); + } + 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); + ChannelCursor1CurrentEvent0[1] = index; + if (index != 16) + { + s = str(PinAssignment[index]); + index1 = s.charAt(1) - '0'; + 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) + { + ChannelCursor1CurrentEvent0[0] = 0; + } + if (CurrentEventFloat >= xTime[samples - 1]*100000) + { + ChannelCursor1CurrentEvent0[0] = samples - 1; + } + } + else + { + for (int i = 1; i < samples - 1; i++) + { + compare1 = ((xTime[i]*100000) + (xTime[i + 1]*100000) - (2*CurrentEventFloat)); + if (compare1<0) + { + if (state[i][index1][index2]) + { + ChannelCursor1CurrentEvent0[0] = i; + } + } + else + { + break; + } + //println (abs(xTime[i]+xShift)); + //println ("wut"); + } + } + } + //println(ChannelCursor1CurrentEvent0[0]); + dataComplete = true; +} + +void updatepos() +{ + if (samples != 0) + { + xEnd = (xTime[samples - 1]); + // xEnd = xEnd + } + else + { + xEnd = 0; + } + xShift = -map(handleX, xEdge, width - handleW, 0, xEnd); + xShift = xShift + (width - handleW) / 2; +} + +void movepos() +{ + xShift = xTime[ChannelCursor1CurrentEvent0[0]]; + handleX = map(xShift, 0, xEnd, xEdge, width - handleW); + xShift = -xShift - (width - handleW) / 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) +{ + String inString = board_port.readStringUntil('\n'); + inString = trim(inString); + //println("incoming: "+inString); + + if (inString.equals("S")) + { + initialState[0] = 0; + initialState[1] = 0; + initialState[2] = 0; + samples = 0; + event = -2; + + first = true; + } + else + { + String list[] = split(inString, ':'); + String sublistate[] = split(list[0], ','); + if (first == true) + { + + initialState[0] = int(sublistate[0]); + initialState[1] = int(sublistate[1]); + initialState[2] = int(sublistate[2]); + samples = int(list[1]); + + pinChanged = new int[samples][3]; + usTime = new float[samples]; + xTime = new float[samples]; + state = new boolean[samples][8][3]; + + first = false; + } + else + { + pinChanged[event][0] = int(sublistate[0]); + pinChanged[event][1] = int(sublistate[1]); + pinChanged[event][2] = int(sublistate[2]); + usTime[event] = float(list[1]); + } + } + event++; + + if (event == samples) + { + getData(); + } +} + +void scaletime() // Poner una r indicara que la funcion solo va a rehacer los tiempos. +{ + if (milliseconds) + { + for (int i = 0; i < samples; i++) + { + xTime[i] = usTime[i] / (reducer * 1000); //better to reduce the lenght of the x + } + } + else + { + for (int i = 0; i < samples; i++) + { + xTime[i] = usTime[i] / reducer; //better to reduce the lenght of the x + } + } +} + +void getData() +{ + scaletime(); + //check data: + //println("event: "+event); + //print("initial: "+initialState[0]); + //print(","+initialState[1]); + //println(","+initialState[2]); + //println("samples: "+samples); + //println("time"+usTime[0]); + //printArray(pinChanged[0]); + //printArray(xTime); + //println("pin: "+binary(changed[0], 6)); + + int mask = 1; + + // initial state + for (int n = 0; n < 8; n++) + { + isLow[n][0] = !boolean(initialState[0] & mask); + isLow[n][1] = !boolean(initialState[1] & mask); + isLow[n][2] = !boolean(initialState[2] & mask); + isLowInit[n][0] = !boolean(initialState[0] & mask); // No se sí al simplemente hacer las asignaciones se pase el dato o todo el puntero asi que no me la quiero jugar + isLowInit[n][1] = !boolean(initialState[1] & mask); + isLowInit[n][2] = !boolean(initialState[2] & mask); + mask <<= 1; + //println("islow: "+isLow[n]); + } + + // changes + for (int i = 0; i < samples; i++) + { + mask = 1; + //println("i:"+i); + //println(binary(changed[i], 6)); + for (int n = 0; n < 8; n++) + { + state[i][n][0] = boolean(pinChanged[i][0] & mask); + state[i][n][1] = boolean(pinChanged[i][1] & mask); + state[i][n][2] = boolean(pinChanged[i][2] & mask); + mask <<= 1; + //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/processing.pde b/Computer_Interface/processing.pde deleted file mode 100644 index cc48223..0000000 --- a/Computer_Interface/processing.pde +++ /dev/null @@ -1,1064 +0,0 @@ -import processing.serial.*; -import java.util.Arrays; -Serial p; - -//////////////////////////////////////////////// -/*--------------------SETUP-------------------*/ - -//uncomment the line where your arduino/STM32 is connected -//String LA_port = "/dev/ttyACM0"; //linux DFU -//String LA_port = "/dev/ttyUSB0"; //linux Serial -String LA_port = "COM3"; //windows - -final int baudrate = 115200; //check if it is the same in arduino - -//Uncomment the board that you are using -//String board ="MEGA"; -String board ="UNO"; -//String board ="STM32F1"; -//String board ="ESP8266"; - -/*------------------END SETUP-----------------*/ -//////////////////////////////////////////////// - - -//colors: -int white = 255; -int black = 0; -int green = #00FF00; -int red = #FF0000; -int grey = 150; - - -// shift, reducer and millisecond view -float reducer = 1.0; -boolean milliseconds = true; -float xShift; - - -// start point in the processing window -float xEdge = 60; -float yEdge = 10; -float xEnd; -float oldxEnd; -float[] xPos = new float[16]; -float yBottom; -float yDiff; -float yPos = yEdge; -float ySave = yEdge; -boolean textCovered; -boolean drawTimes = true; - - -//Serial from mcu -//initial data -int samples; -int event; -int initialState[]= new int[3]; -boolean first = false; -boolean dataComplete = false; -//following data -boolean [][][] state; -boolean [][] isLow = new boolean[8][3]; -boolean [][] isLowinit = new boolean[8][3]; -float[] usTime; -float[] xTime; -int[][] pinChanged; -int[] PinAssignment = new int[16]; -int[] PinArduinoNames = new int[16]; -int index1; -int index2; -int index3; -boolean refresh= true; -int []cursora= new int[2]; -float cursoraf= 0; -boolean cursorplay=false; - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// .___ __ __ .__ -// | | ____ _______/ |________ __ __ _____/ |_|__| ____ ____ ______ -// | |/ \ / ___/\ __\_ __ \ | \_/ ___\ __\ |/ _ \ / \ / ___/ -// | | | \\___ \ | | | | \/ | /\ \___| | | ( <_> ) | \\___ \ -// |___|___| /____ > |__| |__| |____/ \___ >__| |__|\____/|___| /____ > -// \/ \/ \/ \/ \/ -///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -/* -ENGLISH -Operation of the pin assignment. -The entries will be depleted in the order they appear in the whole PinAssignment that goes from 0 to 15 for a total of 16, the value of the integer in each position will -reference the pin to be used. Then the value that must be entered in the integer will be shown to observe the desired pin. - -In case you do not want to show anything on that channel, just assign 00 so that the channel will not be written. -The pins that do not appear in the table can not be used because they were not considered in the arduino programming, to avoid overloading the -arduino and obtain more satisfactory response times. - -Notes: - -If you are using an Arduino MEGA you shoud know that, since the arduino MEGA2560 has enough pins more than the arduino one, and also its processor can reach 2MHz and I suppose it must also have a better IPC ratio (Instructions per cycle) -this code read 24 pins of which we will deplete 16 in the program, among the reasons to do this are, the location of the pins which are not always where one would like, -and the mapping of the digital pins in the arduino microcontroller, since I wanted to take advantage of the greater number of pins doing the fewer instructions to avoid -damaging the process. - -SPANISH -Funcionamiento de la asignacion de pines. - -Las entradas se deplegaran en el orden que aparezcan en el entero PinAssignment que va del 0 al 15 para un total de 16, el valor del entero en cada posicion referenciara -el pin a utilizar. A continuacion se mostrara el valor que se debe introducir en el entero para observar el pin deseado. - -En caso de no querer mostrar nada en ese canal basta con asignar 00 para que el canal no sea escrito. -Los pines que no aparecen en la tabla no podrán ser utilizados por que no fueron considerados en la programacion de arduino, esto para evitar sobrecargar al -arduino y obtener tiempos de respuesta más satisfactorios. - -Notas: - -Si utilizas el Arduino MEGA deberias saber, que dado que el arduino MEGA2560 tiene bastantes pines más que el arduino uno, y además su procesador puede llegar a los 2MHz y supongo también debe de tener un mejor ratio -IPC (Instrucciones por ciclo) el codigo hace lectura de 24 pines de los cuales deplegaremos 16 en el programa, entre las razones para hacer esto estan, la ubicacion de los -pines los cuales no siempre estan donde uno quisiera, y el mapeo de los pines digitales en el microcontrolador del arduino, ya que la intencion es aprovechar la mayor cantidad de -pines haciendo la menor cantidad de instrucciones para no perjudicar el proceso. - -Si utilizas un Arduino STM32 deberias saber, que este es mucho mas potente que un Arduino UNO o MEGA, por lo que puede ser utilizado para lecturas mas veloces, ademas en este caso -se disponen de todos los pines B ("PB") por lo que se tienen varios canales para trabajar. - - Number to enter in the Arduino Arduino Arduino Arduino - PinAssignment UNO MEGA STM32 ESP8266 - 10 -------> DigitalPIN 8 -------> DigitalPIN 22 -------> PB 0 -------> DigitalPIN1 - 11 -------> DigitalPIN 9 -------> DigitalPIN 23 -------> PB 1 -------> DigitalPIN2 - 12 -------> DigitalPIN 10 -------> DigitalPIN 24 -------> PB 2 -------> DigitalPIN5 - 13 -------> DigitalPIN 11 -------> DigitalPIN 25 -------> PB 3 -------> DigitalPIN6 - 14 -------> DigitalPIN 12 -------> DigitalPIN 26 -------> PB 4 -------> OFF - 15 -------> DigitalPIN 13 -------> DigitalPIN 27 -------> PB 5 -------> OFF - 16 -------> OFF -------> DigitalPIN 28 -------> PB 6 -------> OFF - 17 -------> OFF -------> DigitalPIN 29 -------> PB 7 -------> OFF - 20 -------> OFF -------> DigitalPIN 49 -------> PB 8 -------> OFF - 21 -------> OFF -------> DigitalPIN 48 -------> PB 9 -------> OFF - 22 -------> OFF -------> DigitalPIN 47 -------> PB 10 -------> OFF - 23 -------> OFF -------> DigitalPIN 46 -------> PB 11 -------> OFF - 24 -------> OFF -------> DigitalPIN 45 -------> PB 12 -------> OFF - 25 -------> OFF -------> DigitalPIN 44 -------> PB 13 -------> OFF - 26 -------> OFF -------> DigitalPIN 43 -------> PB 14 -------> OFF - 27 -------> OFF -------> DigitalPIN 42 -------> PB 15 -------> OFF - 30 -------> OFF -------> DigitalPIN 37 -------> OFF -------> OFF - 31 -------> OFF -------> DigitalPIN 36 -------> OFF -------> OFF - 32 -------> OFF -------> DigitalPIN 35 -------> OFF -------> OFF - 33 -------> OFF -------> DigitalPIN 34 -------> OFF -------> OFF - 34 -------> OFF -------> DigitalPIN 33 -------> OFF -------> OFF - 35 -------> OFF -------> DigitalPIN 32 -------> OFF -------> OFF - 36 -------> OFF -------> DigitalPIN 31 -------> OFF -------> OFF - 37 -------> OFF -------> DigitalPIN 30 -------> OFF -------> OFF - Any other -------> OFF -------> OFF -------> OFF -------> OFF - - -*/ - -//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; -String s; -boolean initial=true; - -// bar scroll -int handleFill = grey; -float handleX; -float handleY; -float handleW = 20; -float handleH = 15; -boolean isDraggable = false; - - - -void setup () { - //p = new Serial(this, Serial.list()[0], 115200); - p = new Serial(this, LA_port, baudrate); - p.bufferUntil('\n'); - - size(1300, 700); - 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. - //Aquí escoges los pines que quieres desplegar. - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // _____ _____ _ _ _ _ - // | __ \_ _| \ | | /\ (_) | | - // | |__) || | | \| | / \ ___ ___ _ __ _ _ __ _ __ ___ ___ _ __ | |_ - // | ___/ | | | . ` | / /\ \ / __/ __| |/ _` | '_ \| '_ ` _ \ / _ \ '_ \| __| - // | | _| |_| |\ |/ ____ \\__ \__ \ | (_| | | | | | | | | | __/ | | | |_ - // |_| |_____|_| \_/_/ \_\___/___/_|\__, |_| |_|_| |_| |_|\___|_| |_|\__| - // __/ | - // |___/ - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - PinAssignment[0] = 10; - PinAssignment[1] = 11; - PinAssignment[2] = 12; - PinAssignment[3] = 13; - PinAssignment[4] = 14; - PinAssignment[5] = 15; - PinAssignment[6] = 16; - PinAssignment[7] = 17; - PinAssignment[8] = 20; - PinAssignment[9] = 21; - PinAssignment[10]= 22; - PinAssignment[11]= 23; - PinAssignment[12]= 24; - PinAssignment[13]= 25; - PinAssignment[14]= 26; - PinAssignment[15]= 27; - - for (int i=0; i<16; i++) { - if (board == "MEGA"){ - switch (PinAssignment[i]) { - case (10): - PinArduinoNames[i]=22; - break; - case (11): - PinArduinoNames[i]=23; - break; - case (12): - PinArduinoNames[i]=24; - break; - case (13): - PinArduinoNames[i]=25; - break; - case (14): - PinArduinoNames[i]=26; - break; - case (15): - PinArduinoNames[i]=27; - break; - case (16): - PinArduinoNames[i]=28; - break; - case (17): - PinArduinoNames[i]=29; - break; - case (20): - PinArduinoNames[i]=49; - break; - case (21): - PinArduinoNames[i]=48; - break; - case (22): - PinArduinoNames[i]=47; - break; - case (23): - PinArduinoNames[i]=46; - break; - case (24): - PinArduinoNames[i]=45; - break; - case (25): - PinArduinoNames[i]=44; - break; - case (26): - PinArduinoNames[i]=43; - break; - case (27): - PinArduinoNames[i]=42; - break; - case (30): - PinArduinoNames[i]=37; - break; - case (31): - PinArduinoNames[i]=36; - break; - case (32): - PinArduinoNames[i]=35; - break; - case (33): - PinArduinoNames[i]=34; - break; - case (34): - PinArduinoNames[i]=33; - break; - case (35): - PinArduinoNames[i]=32; - break; - case (36): - PinArduinoNames[i]=31; - break; - case (37): - PinArduinoNames[i]=30; - break; - default: - PinArduinoNames[i]=00; - break; - - } - }else if (board=="UNO") { - switch (PinAssignment[i]) { - case (10): - PinArduinoNames[i]=8; - break; - case (11): - PinArduinoNames[i]=9; - break; - case (12): - PinArduinoNames[i]=10; - break; - case (13): - PinArduinoNames[i]=11; - break; - case (14): - PinArduinoNames[i]=12; - break; - case (15): - PinArduinoNames[i]=13; - break; - default: - PinArduinoNames[i]=00; - break; - - } - }else if (board=="STM32F1") { - switch (PinAssignment[i]) { - case (10): - PinArduinoNames[i]=100; - break; - case (11): - PinArduinoNames[i]=1; - break; - case (12): - PinArduinoNames[i]=2; - break; - case (13): - PinArduinoNames[i]=3; - break; - case (14): - PinArduinoNames[i]=4; - break; - case (15): - PinArduinoNames[i]=5; - break; - case (16): - PinArduinoNames[i]=6; - break; - case (17): - PinArduinoNames[i]=7; - break; - case (20): - PinArduinoNames[i]=8; - break; - case (21): - PinArduinoNames[i]=9; - break; - case (22): - PinArduinoNames[i]=10; - break; - case (23): - PinArduinoNames[i]=11; - break; - case (24): - PinArduinoNames[i]=12; - break; - case (25): - PinArduinoNames[i]=13; - break; - case (26): - PinArduinoNames[i]=14; - break; - case (27): - PinArduinoNames[i]=15; - break; - default: - PinArduinoNames[i]=00; - break; - - } - }else if (board=="ESP8266") { - switch (PinAssignment[i]) { - case (10): - PinArduinoNames[i]=1; - break; - case (11): - PinArduinoNames[i]=2; - break; - case (12): - PinArduinoNames[i]=5; - break; - case (13): - PinArduinoNames[i]=6; - break; - default: - PinArduinoNames[i]=00; - break; - - } - } - } - 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 draw() { - - if (dataComplete==true) { - cleanGraph(); - pushMatrix(); //move the coordinate reference - translate(xEdge, 0); - float firstchange; - boolean cares; - if (cursorplay){ - fill(50); - stroke(75); - if(cursora[1]==16){ //Esta variable la utilizamos para definir el canal sobre el cual estamos trabajando, en esta parte marcamos el rectangulo en el que trabajamos. - rect(0, yBottom-12, width-xEdge, 34); - } - else{ - rect(0, yEdge+36*cursora[1]-2, width-xEdge, 34); - } - stroke(green); - } - updatepos(); //Se encarga de decir que segmento de tiempos se va a escribir - for (int i=0; i// - yDiff=yPos; - yPos+=30; - - } else { - yDiff=yPos+30; - } - isLow[index1][index2]=isLowinit[index1][index2]; - //println(isLowinit[index1][index2]); - } - else { - if (isLow[index1][index2]) { //pin high else low - yDiff=yPos; - yPos+=30; - isLow[index1][index2]=false; - } else { - yDiff=yPos+30; - isLow[index1][index2]=true; - } - } - - - - // Graph 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 (cursora[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); - } - } - - yPos = yEdge; - for (int n = 0; n < 16; n++) { - if (PinAssignment[n]!=0){ - s= str(PinAssignment[n]); - index1 = s.charAt(1)-'0'; - index2 = s.charAt(0)-'1'; - if (xPos[n]==0) { - if (isLowinit[index1][index2]==true) line(xPos[n]+xShift, yPos+30, xEnd+xShift, yPos+30); - else line(xPos[n]+xShift, yPos, xEnd+xShift, yPos); - } - - } - yPos+=36; - } - dataComplete = false; - popMatrix(); - } - drawText(); -} - - -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); - - if (isDraggable) { - handleX = mouseX-handleW/2; - if (handleXwidth-handleW) handleX = width-handleW; - updatepos(); - dataComplete = true; - - - } - -} - - -void mousePressed() { - if (mouseX>xEdge && mouseXhandleY && mouseYxTime[samples-1]){ - if (cursoraf<=0){ - cursora[0]=0; - } - if (cursoraf>=xTime[samples-1]){ - cursora[0]=samples-1; - } - }else{ - for (int i=1; iabs(xTime[i+1]-cursoraf)&&state[i][index1][index2]){ - if (abs(xTime[i]-cursoraf)>abs(xTime[i+1]-cursoraf)){ - if(state[i][index1][index2]){ - cursora[0]=i; - } - }else { - break; - } - //println (abs(xTime[i]+xShift)); - //println ("wut"); - } - } - } - println( cursora[0]); - dataComplete=true; -} -void updatepos(){ - if (samples!=0) { - xEnd = (xTime[samples-1]); - // xEnd = xEnd - } else { - xEnd = 0; - } - xShift = -map(handleX, xEdge, width-handleW, 0, xEnd); - xShift = xShift + (width-handleW)/2; - -} - -void movepos(){ - xShift = xTime[cursora[0]]; - handleX = map(xShift, 0, xEnd, xEdge, width-handleW); - xShift = -xShift - (width-handleW)/2; -dataComplete=true; - -} - -void keyPressed() { - int number; - if (key == CODED) { - if (keyCode == UP && cursorplay) { - number=cursora[1]; - cursora[1]= cursora[1]-1; - for (int i=cursora[1]; i>=0; i--){ - if (PinAssignment[cursora[1]]==0){ - cursora[1]= cursora[1]-1; - }else { - break; - } - } - if (cursora[1]==-1){ - cursora[1]= number; - } - cursora[1]=constrain(cursora[1], 0, 16); - //println("cur1 "+cursora[1]+"cur0 "+cursora[0]); - dataComplete=true; - } else if (keyCode == DOWN && cursorplay) { - if(cursora[1]<16){ - cursora[1]= cursora[1]+1; - for (int i=cursora[1]; i<16; i++){ - if (PinAssignment[cursora[1]]==0){ - cursora[1]= cursora[1]+1; - }else { - break; - } - - cursora[1]=constrain(cursora[1], 0, 16); - } } - //println("cur1 "+cursora[1]+"cur0 "+cursora[0]); - dataComplete=true; - } else if (keyCode == RIGHT && cursorplay) { - if (cursora[1]==16){ - if (cursora[0]!=samples-1){ - cursora[0]+=1; - } - } - else{ - s = str(PinAssignment[cursora[1]]); - index1 = s.charAt(1)-'0'; - index2 = s.charAt(0)-'1'; - //println(cursora[0]); - for (int i=cursora[0]+1; i-1; i--){ - cursora[0]=i; - if (state[i][index1][index2]){ - break; - }else { - - } } - } - //println("cur1 "+cursora[1]+"cur0 "+cursora[0]); - //updatepos(); - movepos(); - }else if (keyCode == LEFT && !cursorplay) { - handleX-=1; - if (handleXwidth-handleW) handleX = width-handleW; - dataComplete=true; - }else if (keyCode == RIGHT && !cursorplay) { - handleX+=1; - if (handleXwidth-handleW) handleX = width-handleW; - dataComplete=true; - } - } -} - -void mouseClicked() { - - // bootons over signals - if(mouseX>xEdge && mouseX yBottom-15 && mouseY xEdge && mouseX yEdge && mouseY xEdge && mouseX yEdge+36 && mouseY xEdge && mouseX yEdge+36*2 && mouseY xEdge && mouseX yEdge+36*3 && mouseY xEdge && mouseX yEdge+36*4 && mouseY xEdge && mouseX yEdge+36*5 && mouseY xEdge && mouseX yEdge+36*6 && mouseY xEdge && mouseX yEdge+36*7 && mouseY xEdge && mouseX yEdge+36*8 && mouseY xEdge && mouseX yEdge+36*9 && mouseY xEdge && mouseX yEdge+36*10 && mouseY xEdge && mouseX yEdge+36*11 && mouseY xEdge && mouseX yEdge+36*12 && mouseY xEdge && mouseX yEdge+36*13 && mouseY xEdge && mouseX yEdge+36*14 && mouseY xEdge && mouseX yEdge+36*15 && mouseY yBottom-15 && mouseY button1X && mouseX buttonY && mouseY button2X && mouseX buttonY && mouseY button5X && mouseX buttonY && mouseY button4X && mouseX 90 && !milliseconds){ - reducer=0.1; - milliseconds = !milliseconds; - } - reducer = constrain(reducer, 0.1, 100); - } else { //move the graph - if (reducer<=1){ - reducer-= 0.1; - }else if (reducer<=10){ - reducer-=1; - }else { - reducer-=10; - } - if (reducer<0.1 && milliseconds){ - reducer=100; - milliseconds = !milliseconds; - } - reducer = constrain(reducer, 0.1, 90); - } - scaletime(); - updatepos(); - dataComplete=true; - } else - // micro or millis - if (mouseY>buttonY && mouseY button3X && mouseX width-handleW) handleX = width-handleW; - dataComplete=true; - -} - - -void mouseMoved() { - if (mouseY>buttonY && mouseY button2X && mouseX buttonY && mouseY button3X && mouseX buttonY && mouseY button5X && mouseX buttonY && mouseY button4X && mouseX yBottom-15 && mouseY button1X && mouseX handleX && mouseXhandleY && mouseYxEdge && mouseX yBottom-15 && mouseY xEdge && mouseX yEdge && mouseY xEdge && mouseX yEdge+36 && mouseY xEdge && mouseX yEdge+36*2 && mouseY xEdge && mouseX yEdge+36*3 && mouseY xEdge && mouseX yEdge+36*4 && mouseY xEdge && mouseX yEdge+36*5 && mouseY xEdge && mouseX yEdge+36*6 && mouseY xEdge && mouseX yEdge+36*7 && mouseY xEdge && mouseX yEdge+36*8 && mouseY xEdge && mouseX yEdge+36*9 && mouseY xEdge && mouseX yEdge+36*10 && mouseY xEdge && mouseX yEdge+36*11 && mouseY xEdge && mouseX yEdge+36*12 && mouseY xEdge && mouseX yEdge+36*13 && mouseY xEdge && mouseX yEdge+36*14 && mouseY xEdge && mouseX yEdge+36*15 && mouseY 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/tester/tester.ino b/Extras/tester/tester.ino similarity index 58% rename from tester/tester.ino rename to Extras/tester/tester.ino index 903af31..3188724 100644 --- a/tester/tester.ino +++ b/Extras/tester/tester.ino @@ -5,23 +5,23 @@ * Test your logic analyzer with another arduino */ -#define led A5 -#define led2 13 +#define pin1 A5 +#define pin2 13 void setup() { - pinMode(led, OUTPUT); - pinMode(led2, OUTPUT); + pinMode(pin1, OUTPUT); + pinMode(pin2, OUTPUT); } void loop() { - digitalWrite(led, HIGH); + digitalWrite(pin1, HIGH); delayMicroseconds(random(200)); - digitalWrite(led2, HIGH); + digitalWrite(pin2, HIGH); delayMicroseconds(random(200)); - digitalWrite(led2, LOW); + digitalWrite(pin2, LOW); delayMicroseconds(random(200)); - digitalWrite(led, LOW); + digitalWrite(pin1, LOW); delayMicroseconds(random(200)); } diff --git a/Microcontroller_Code/ESP8266/ESP8266.ino b/Microcontroller_Code/ESP8266/ESP8266.ino index 53d9b0a..7c0e883 100644 --- a/Microcontroller_Code/ESP8266/ESP8266.ino +++ b/Microcontroller_Code/ESP8266/ESP8266.ino @@ -2,7 +2,6 @@ * ESP8266.ino * * Author : yoursunny - * Led: LED_BUILTIN */ #include @@ -31,7 +30,7 @@ void setup() { Serial.begin(baudrate); pinMode(LED_BUILTIN, OUTPUT); - digitalWrite(LED_BUILTIN, HIGH); + digitalWrite(LED_BUILTIN, LOW); pinMode(PIN0, INPUT_PULLUP); pinMode(PIN1, INPUT_PULLUP); diff --git a/Microcontroller_Code/MEGA/MEGA.ino b/Microcontroller_Code/MEGA/MEGA.ino index 3983c7a..75f415e 100644 --- a/Microcontroller_Code/MEGA/MEGA.ino +++ b/Microcontroller_Code/MEGA/MEGA.ino @@ -1,6 +1,6 @@ /* * Created: 11/12/2016 19.35.51 - * Author : Vincenzo + * Author : sancho / Vincenzo */ #define baudrate 115200 //check if it is the same in processing @@ -24,20 +24,21 @@ uint16_t event = 0; uint8_t cambio=0; void init_board() { -// PORTC = (0 << 0); DDRC |= (1 << 0); // led A0 DDRB = 0x00; DDRC = 0x00; DDRL = 0x00; - if (PULLUP){ - PORTA = B11111111; // pull-up - PORTC = B11111111; // Activamos el pull-up para que de no conectarse nada a puerto lea un uno siempre - PORTL = B11111111; + if (PULLUP){ // Activamos el pull-up para que de no conectarse nada a puerto lea un uno siempre + for (uint8_t p = 22; p <= 49; p++){ + pinMode(p, INPUT_PULLUP); + } } else{ - PORTA = B00000000; - PORTC = B00000000; - PORTL = B00000000; - } + for (uint8_t p = 22; p <= 49; p++){ + pinMode(p, INPUT); + } + } + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, LOW); } void init_timer() { @@ -86,7 +87,7 @@ void start() { reset_timer1(); event = 0; - //PORTC = (1 << 0); + digitalWrite(LED_BUILTIN, HIGH); initial1 = PINA; initial2 = PINL; initial3 = PINC; @@ -100,12 +101,11 @@ void start() { //Serial.print(pinChanged1[i]); Serial.print(','); Serial.print(pinChanged2[i]); Serial.print(','); Serial.println(pinChanged3[i]); } - } void sendData() { - //PORTC = (0 << 0); //turn off led + digitalWrite(LED_BUILTIN, LOW); //initial data Serial.println("S"); Serial.print(initial1); Serial.print(','); Serial.print(initial2); Serial.print(','); Serial.print(initial3); Serial.print(":"); diff --git a/Microcontroller_Code/STM32F1/STM32F1.ino b/Microcontroller_Code/STM32F1/STM32F1.ino index de53ea9..df53363 100644 --- a/Microcontroller_Code/STM32F1/STM32F1.ino +++ b/Microcontroller_Code/STM32F1/STM32F1.ino @@ -3,15 +3,11 @@ * * Author : Vincenzo * this works using the unofficial STM32 core, more info: https://github.com/rogerclarkmelbourne/Arduino_STM32 - * Led: PB1 */ #define baudrate 115200 // check if it is the same in processing #define samples 200 // the number of samples you want to take -#define boardLed PA1 - - uint16_t initial, state, old_state; uint16_t pinChanged[samples]; @@ -26,8 +22,8 @@ void setup() { Serial.begin(baudrate); - pinMode (boardLed, OUTPUT); - digitalWrite(boardLed, LOW); + pinMode (LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, LOW); pinMode(PB0, INPUT_PULLUP); pinMode(PB1, INPUT_PULLUP); pinMode(PB2, INPUT_PULLUP); @@ -54,7 +50,7 @@ void startLA() { //delay(1000); event = 0; - digitalWrite(boardLed, HIGH); + digitalWrite(LED_BUILTIN, HIGH); reset_timer(); initial = GPIOB->regs->IDR; @@ -86,7 +82,7 @@ void loop() { } void sendData() { - digitalWrite(boardLed, LOW); + digitalWrite(LED_BUILTIN, LOW); //initial data initial1=initial;