-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInsightLT.java
More file actions
268 lines (238 loc) · 6.88 KB
/
Copy pathInsightLT.java
File metadata and controls
268 lines (238 loc) · 6.88 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package InsightLT;
import edu.wpi.first.wpilibj.I2C;
import edu.wpi.first.wpilibj.DigitalModule;
import edu.wpi.first.wpilibj.Timer;
import java.util.Vector;
/**
*
* @author Bit Built Tech
*/
public class InsightLT implements Runnable {
public final static int FOUR_ZONES = 0;
public final static int ONE_TWO_LINE_ZONE = 1;
public final static int TWO_ONE_LINE_ZONES = 2;
public final static int LINE_1 = 0;
public final static int LINE_2 = 1;
public InsightLT()
{
module = DigitalModule.getInstance(1);
setupHelper();
config(ONE_TWO_LINE_ZONE);
}
public InsightLT(int option)
{
module = DigitalModule.getInstance(1);
setupHelper();
config(option);
}
public InsightLT(int option, char moduleNumber)
{
module = DigitalModule.getInstance(moduleNumber);
setupHelper();
config(option);
}
private void setupHelper()
{
m_stopDisplayThread = false;
m_twiComm = module.getI2C(0x78);
m_displayConnected = false;
m_zones = new Vector();
}
public Zone getZone(int zoneNumber)
{
if(zoneNumber < 1 || zoneNumber > m_zones.size())
{
return null;
}
else
{
return (Zone)m_zones.elementAt(zoneNumber - 1);
}
}
public void startDisplay()
{
thread = new Thread(this);
m_stopDisplayThread = false;
thread.start();
}
public void stopDisplay()
{
m_stopDisplayThread = true;
}
public void writeMessage(String message, int line, int position)
{
byte[] buffer = new byte[6];
buffer[0] = 0x00;
buffer[1] = (byte)(((line * 0x40) + position) | 0x80);
m_twiComm.transaction(buffer, 2, buffer, 0);
boolean end = false;
buffer[0] = 0x40;
for(int x = 0; x < message.length();)
{
for(int y = 1; y < 6; y++)
{
buffer[y] = (byte)message.charAt(x);
x++;
if(x >= message.length())
{
m_twiComm.transaction(buffer, y+1, buffer, 0);
end = true;
break;
}
}
if(!end)
{
m_twiComm.transaction(buffer, 6, buffer, 0);
}
}
}
public boolean registerData(DisplayData dataItem, int zoneNumber)
{
if(zoneNumber < 1 || zoneNumber > m_zones.size())
{
return false;
}
((Zone)m_zones.elementAt(zoneNumber - 1)).registerData(dataItem);
return true;
}
public void setZoneScrollTime(int zoneNumber, int time)
{
if(zoneNumber > 0 && zoneNumber <= m_zones.size())
{
((Zone)m_zones.elementAt(zoneNumber - 1)).setTime(time);
}
}
public void manualScroll(int zoneNumber, byte direction)
{
if(zoneNumber > 0 && zoneNumber <= m_zones.size())
{
if(direction > 0)
{
((Zone)m_zones.elementAt(zoneNumber - 1)).advanceZoneUp();
}
else
{
((Zone)m_zones.elementAt(zoneNumber - 1)).advanceZoneDown();
}
}
}
public void clearScreen()
{
byte[] buffer = new byte[2];
buffer[0] = 0x00;
buffer[1] = 0x01;
m_twiComm.transaction(buffer, 2, buffer, 0);
}
private boolean getConnectionStatus()
{
return m_displayConnected;
}
private void setConnectionStatus(boolean status)
{
m_displayConnected = status;
}
public void run()
{
while(!m_stopDisplayThread)
{
if(!getConnectionStatus())
{
System.out.println("Connecting Display...");
while(m_twiComm.addressOnly())
{
Timer.delay(.5);
}
initializeDisplay();
clearScreen();
welcomeMessage();
setConnectionStatus(true);
Timer.delay(2);
clearScreen();
}
else
{
while(!m_stopDisplayThread)
{
if(m_twiComm.addressOnly())
{
setConnectionStatus(false);
break;
}
for(int x = 1; x < 5; x++)
{
Zone tmpZone = getZone(x);
if(tmpZone != null)
{
tmpZone.update();
writeMessage(tmpZone.getLineOne(), tmpZone.getLine(), tmpZone.getPosition());
if(tmpZone.isTwoLines())
{
writeMessage(tmpZone.getLineTwo(), tmpZone.getLine() + 1, tmpZone.getPosition());
}
}
}
Timer.delay(.05);
}
}
}
setConnectionStatus(false);
}
private void initializeDisplay()
{
byte[] buffer = new byte[6];
byte[] emptyArray = new byte[0];
buffer[0] = 0x00;
buffer[1] = 0x38;
buffer[2] = 0x39;
buffer[3] = 0x14;
buffer[4] = 0x78;
buffer[5] = 0x5E;
m_twiComm.transaction(buffer, 6, emptyArray, 0);
buffer[0] = 0x00;
buffer[1] = 0x6D;
m_twiComm.transaction(buffer, 2, emptyArray, 0);
Timer.delay(.01);
buffer[0] = 0x00;
buffer[1] = 0x0C;
buffer[2] = 0x01;
buffer[3] = 0x06;
m_twiComm.transaction(buffer, 4, emptyArray, 0);
Timer.delay(.01);
}
private void welcomeMessage()
{
writeMessage("Bit Built Tech", LINE_1, 0);
writeMessage("Robot Diagnostics", LINE_2, 3);
}
private void config(int option)
{
switch(option)
{
case FOUR_ZONES:
m_zones.addElement(new Zone(LINE_1, 0, 10, 1, 1500));
m_zones.addElement(new Zone(LINE_1, 10, 10, 1, 1500));
m_zones.addElement(new Zone(LINE_2, 0, 10, 1, 1500));
m_zones.addElement(new Zone(LINE_2, 10, 10, 1, 1500));
case TWO_ONE_LINE_ZONES:
m_zones.addElement(new Zone(LINE_1, 0, 20, 1, 1500));
m_zones.addElement(new Zone(LINE_2, 0, 20, 1, 1500));
break;
case ONE_TWO_LINE_ZONE:
default:
m_zones.addElement(new Zone(LINE_1, 0, 20, 2, 1500));
break;
}
}
private DigitalModule module;
private Thread thread;
private I2C m_twiComm;
private boolean m_wasPaused;
private boolean m_displayConnected;
private boolean m_started;
private boolean m_stopDisplayThread;
private Vector m_zones;
}