This repository was archived by the owner on Mar 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudio_status.pde
More file actions
executable file
·165 lines (144 loc) · 4.23 KB
/
studio_status.pde
File metadata and controls
executable file
·165 lines (144 loc) · 4.23 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
import java.util.PriorityQueue;
import java.util.Map;
import processing.io.*;
import processing.serial.*;
PShape logo; // 1920 x 203
final String fontPath = "Roadgeek 2005 Series 4B.ttf";
final HashMap<Integer, PFont> fonts = new HashMap<Integer, PFont>();
final String[][] names = {
{"", "", "Dominic G", "Olivia C", "Foard N"},
{"", "Juliana Soltys", "Jonah H.", "", "Jillian B"},
{"", "Eric N", "Lin Liu", "Sameer P", "Alex B"},
{"", "Lauren B", "Christina H", "Sophia Z", "Taylor P"},
{"", "Jeremy D", "Illiya", "Emily M", "Nicholcas B"},
{"Liam K", "Josh P"},
{}};
final color BLUE = color(0, 67, 123), GREEN = color(0, 95, 77),
PURPLE = color(157, 0, 113), BLACK = color(0, 0, 0),
BROWN = color(98, 51, 30), RED = color(199, 0, 43),
ORANGE = color(255, 104, 2), YELLOW = color(255, 178, 0);
final boolean isGPIOAvailable = true;
boolean isDoorDuinoAvailable = false;
SoftwareServo stripservo;
Serial doorDuino;
void setup() {
fullScreen();
logo = loadShape("logo.svg");
for (int i = 20; i <= 400; i += 20) {
fonts.put(i, createFont(fontPath, i));
}
if (isGPIOAvailable) {
GPIO.pinMode(17, GPIO.INPUT);
GPIO.pinMode(27, GPIO.INPUT);
stripservo = new SoftwareServo(this);
String[] serial = Serial.list();
if (serial.length > 0) {
doorDuino = new Serial(this, serial[0], 600);
println(serial[0]);
isDoorDuinoAvailable = true;
}
}
frameRate(10);
}
void draw() {
background(255, 255, 255);
drawDesignStudio();
drawOpen(isOpen());
drawMentorOnDuty();
flipOpenStripServo();
}
boolean servoOpen = false;
boolean firstSwitch = true;
void flipOpenStripServo() {
if (isGPIOAvailable) {
boolean shouldFlip = false;
if (firstSwitch) {
firstSwitch = false;
shouldFlip = true;
} else if (isOpen() && !servoOpen) { // TODO: self, xor this pls
shouldFlip = true;
} else if (!isOpen() && servoOpen) {
shouldFlip = true;
}
if (shouldFlip) {
if (isOpen()) {
// stripservo.write(140);
servoOpen = true;
} else {
// stripservo.write(65);
servoOpen = false;
}
}
}
}
boolean isDoorOpen() {
if (!isDoorDuinoAvailable) { return true; }
doorDuino.write((byte)0);
long timeout = System.currentTimeMillis();
while (doorDuino.available() == 0 && System.currentTimeMillis() - timeout < 700) {}
return System.currentTimeMillis() - timeout < 700 ? doorDuino.read() == 1 : true;
}
void drawDesignStudio() {
shape(logo, 0, 0, 200, 200);
fill(BLACK);
textFont(fonts.get(200));
textAlign(CENTER, TOP);
text("Design Studio", 960, 0);
}
boolean isOpen() {
int dayOfWeek = dow(day(), month(), year());
int currentHour = hour();
boolean isOpen = false;
if (currentHour >= 12 && dayOfWeek > -1 && dayOfWeek < 7) {
int EODhour = names[dayOfWeek].length * 2 + 12;
int idx = (currentHour - 12)/2;
if (currentHour < EODhour && names[dayOfWeek].length > idx && idx > -1 && !names[dayOfWeek][idx].isEmpty()) {
isOpen = true;
}
}
int switchValue = getSwitchValue();
if (switchValue == OPENONE) {
return isOpen && isDoorOpen();
} else if (switchValue == OPENTWO) {
return isDoorOpen();
} else {
return false;
}
}
// d = day in month
// m = month (January = 1 : December = 12)
// y = 4 digit year
// Returns 0 = Sunday .. 6 = Saturday
int dow(int d, int m, int y) {
if (m < 3) {
m += 12;
y--;
}
return (d + int((m + 1) * 2.6) + y + int(y / 4) + 6 * int(y / 100) +
int(y / 400) + 6) %
7;
}
void drawOpen(boolean open) {
fill(open ? GREEN : RED);
textFont(fonts.get(400));
textAlign(CENTER, TOP);
text(open ? "Open" : "Closed", 960, 203);
}
void drawMentorOnDuty() {
if (isOpen() && getSwitchValue() == OPENONE) {
fill(BLACK);
textFont(fonts.get(100));
textAlign(CENTER, BASELINE);
text("Mentor on Duty: " +
names[dow(day(), month(), year())][((hour() - 12) / 2)],
960, 1075);
}
}
final int OPENONE = 1, OPENTWO = 2, CLOSED = 0;
int getSwitchValue() {
return isGPIOAvailable
? (GPIO.digitalRead(17) == GPIO.HIGH
? OPENONE
: GPIO.digitalRead(27) == GPIO.HIGH ? OPENTWO : CLOSED)
: OPENONE;
}