This repository has been archived by the owner on Nov 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathConfigMgr.java
206 lines (167 loc) · 5.92 KB
/
ConfigMgr.java
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
import java.io.*;
/**
* @author Angelo DiNardi ([email protected])
*/
class ConfigMgr {
private static ConfigMgr instance = null;
/**
* The connected state of the client to the server
*/
private boolean connected = false;
/**
* 1 based int for the number of slots in the system
*/
private int numSlots = 5;
/**
* Contains the 1-Wire IDs of the Motor Switches
*/
private String[] switches = new String[numSlots + 1]; //add one to make it a 1-based array
/**
* Contains the 1-Wire IDs of the Light Switches
*/
private String[] lights = null;//new String[numSlots + 1]; //add one to make it a 1-based array
/**
* Contains the 1-Wire IDs of the Temp Monitors
*/
private String[] temps = null; //new String[1];
private String doorID = null;
private String motorSwitchID = null;
/**
* Contains the timings for motor on time for drops
* Default is 1500 ms (1.5 seconds)
*/
private int dropTime = 1500;
/**
* Contains the password for the machine to authenticate with the server
*/
private String password = "";
private ConfigMgr() {
readConfig();
}
public synchronized static ConfigMgr getInstance() {
if( instance == null ) {
instance = new ConfigMgr();
}
return instance;
}
public boolean getConnected() {
return connected;
}
public void setConnected( boolean s ) {
connected = s;
}
public int getNumSlots() {
return numSlots;
}
public String[] getSwitches() {
return switches;
}
public String[] getLights() {
return lights;
}
public String getMotorSwitchID() {
return motorSwitchID;
}
public String getDoorID() {
return doorID;
}
/**
* Returns true if the machine has lights we should operate
*/
public boolean runLights() {
if( lights == null ) {
return false;
}else{
return true;
}
}
public String[] getTemps() {
return temps;
}
/**
* Return true if tempterature sensors exist in the system
*/
public boolean runTemps() {
if (temps == null) {
return false;
} else {
return true;
}
}
public int getDropTime() {
return dropTime;
}
public String getPassword() {
return password;
}
private void readConfig() {
try {
BufferedReader in = new BufferedReader( new FileReader("config") );
String temp = null;
int num = 0;
String id = null;
while( (temp = in.readLine()) != null ) {
if( temp.charAt(0) == 's' ) { //switch id
System.out.println( "Got Switch Row" );
if( temp.charAt(1) == 't' ) { //total #
this.numSlots = Integer.parseInt(temp.substring(2));
this.switches = new String[this.numSlots + 1];
System.out.println( "Got Switch Total: " + this.switches.length );
continue;
}
num = Integer.parseInt(temp.substring(1,3));
id = temp.substring(4);
System.out.println( "" + num + " : " + id );
this.switches[num] = id;
}else if( temp.charAt(0) == 'l' ) { //light id
System.out.println( "Got Light Row" );
if( temp.charAt(1) == 't' ) { //total #
if( Integer.parseInt(temp.substring(2)) != 0 ) {
this.lights = new String[Integer.parseInt( temp.substring(2) ) + 1 ];
System.out.println( "Got Light Total: " + this.lights.length );
}else{
System.out.println( "Lights Disabled" );
}
continue;
}
num = Integer.parseInt(temp.substring(1,3));
id = temp.substring(4);
System.out.println( "" + num + " : " + id );
this.lights[num] = id;
}else if( temp.charAt(0) == 't' ) { //temp id
System.out.println( "Got Temp Row" );
if( temp.charAt(1) == 't' ) { //total #
if (Integer.parseInt(temp.substring(2)) != 0) {
this.temps = new String[Integer.parseInt( temp.substring(2) ) ];
System.out.println( "Got Temps Total: " + this.temps.length );
} else {
System.out.println("Temp Disabled");
}
continue;
}
num = Integer.parseInt(temp.substring(1,3));
id = temp.substring(4);
System.out.println( "" + num + " : " + id );
this.temps[num] = id;
}else if( temp.charAt(0) == 'd' ) { //drink timing
System.out.println( "Got Drink Timing Row" );
dropTime = Integer.parseInt(temp.substring(1));
}else if( temp.charAt(0) == 'p' ) { //password row
System.out.println( "Got Drink Server Password" );
password = temp.substring(1);
}else if( temp.charAt(0) == 'i' ) { // Scott: i stands for interlock!
if (temp.charAt(1) == 'd' ) {
doorID = temp.substring(3);
System.out.println( "Got door sensor ibutton id: " + doorID );
} else if (temp.charAt(1) == 'm') {
motorSwitchID = temp.substring(3);
System.out.println( "Got motor sensor ibutton id: " + motorSwitchID );
}
}
}
}catch( Exception e ) {
//There was a prolem loading the config. Lets print a message.
System.out.println("Error loading config.");
}
}
}