forked from TKJElectronics/BalanduinoProcessingApp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DropdownList.pde
57 lines (45 loc) · 2.57 KB
/
DropdownList.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* Copyright (C) 2012-2014 Kristian Lauszus, TKJ Electronics. All rights reserved.
This software may be distributed and modified under the terms of the GNU
General Public License version 2 (GPL2) as published by the Free Software
Foundation and appearing in the file GPL2.TXT included in the packaging of
this file. Please note that GPL2 Section 2[b] requires that all works based
on this software must also be made publicly available under the terms of
the GPL2 ("Copyleft").
Contact information
-------------------
Kristian Lauszus, TKJ Electronics
Web : http://www.tkjelectronics.com
e-mail : [email protected]
*/
void initDropdownlist() {
dropdownList = controlP5.addDropdownList("SerialPort"); // Make a dropdown list with all serial ports
dropdownList.setPosition(10, 20);
dropdownList.setSize(210, 200);
dropdownList.setCaptionLabel("Select serial port"); // Set the lable of the bar when nothing is selected
dropdownList.setBackgroundColor(color(200)); // Set the background color of the line between values
dropdownList.setItemHeight(20); // Set the height of each item when the list is opened
dropdownList.setBarHeight(15); // Set the height of the bar itself
dropdownList.getCaptionLabel().getStyle().marginTop = 3; // Set the top margin of the lable
dropdownList.getCaptionLabel().getStyle().marginLeft = 3; // Set the left margin of the lable
dropdownList.setColorBackground(color(60));
dropdownList.setColorActive(color(255, 128));
// Now add the ports to the list, we use a for loop for that
for (int i = 0; i < Serial.list().length; i++) {
if (Serial.list()[i].indexOf("/dev/cu.") != -1)
continue; // Do not display /dev/cu.* devices
dropdownList.addItem(Serial.list()[i], i); // This is the line doing the actual adding of items, we use the current loop we are in to determine what place in the char array to access and what item number to add it as
if (Serial.list()[i].indexOf("Balanduino") != -1) // Check for the "Balanduino" substring
dropdownList.setValue(i); // Automaticly select the Balanduino balancing robot on Mac OS X and Linux
}
addMouseWheelListener(new MouseWheelListener() { // Add a mousewheel listener to scroll the dropdown list
public void mouseWheelMoved(MouseWheelEvent mwe) {
dropdownList.scroll(mwe.getWheelRotation() > 0 ? 1 : 0); // Scroll the dropdownlist using the mousewheel
}
});
controlP5.addButton("connect")
.setPosition(225, 3)
.setSize(45, 15);
controlP5.addButton("disconnect")
.setPosition(275, 3)
.setSize(52, 15);
}