public void InitSerial(float portValue) { // initialize the serial port selected in the listBox println( "initializing serial " + PApplet.parseInt(portValue) + " in serial.list()"); // for debugging // grab the name of the serial port String portPos = Serial.list()[PApplet.parseInt(portValue)]; // initialize the port serial = new Serial(this, portPos, 115200); // read bytes into a buffer until you get a linefeed (ASCII 10): serial.bufferUntil('\n'); println("done init serial"); // initialized com port flag init_com = 1; }
public void InitComDropdown() { // Initialize portCommList int posX = 20; int posY = 70; PortsList = controlP5.addDropdownList("portComList", posX, posY, 100, 84); // Set the background color of the list (you wont see this though). PortsList.setBackgroundColor(color(200)); // Set the height of each item when the list is opened. PortsList.setItemHeight(20); // Set the height of the bar itself. PortsList.setBarHeight(15); // Set the lable of the bar when nothing is selected. PortsList.captionLabel().set("Select COM port"); // Set the top margin of the lable. PortsList.captionLabel().style().marginTop = 3; // Set the left margin of the lable. PortsList.captionLabel().style().marginLeft = 3; // Set the top margin of the value selected. PortsList.valueLabel().style().marginTop = 3; // Store the Serial ports in the string comList (char array). comList = serial.list(); // We need to know how many ports there are, to know how many items to add to the list, so we // will convert it to a String object (part of a class). String comlist = join(comList, ","); // We also need how many characters there is in a single port name, we\u00b4ll store the chars // here for counting later. String COMlist = comList[0]; // Here we count the length of each port name. int size2 = COMlist.length(); // Now we can count how many ports there are, well that is count how many chars there are, so we // will divide by the amount of chars per port name. int size1 = comlist.length() / size2; // Now well add the ports to the list, we use a for loop for that. How many items is determined // by the value of size1. for (int i = 0; i < size1; i++) { // This is the line doing the actual adding of items, we use the current loop we are in to // determin what place in the char array to access and what item number to add it as. PortsList.addItem(comList[i], i); } // Set the color of the background of the items and the bar. PortsList.setColorBackground(color(60)); // Set the color of the item your mouse is hovering over. PortsList.setColorActive(color(255, 128)); }