-
Notifications
You must be signed in to change notification settings - Fork 0
/
tuerschlossV2_0_1.ino
205 lines (173 loc) · 5.13 KB
/
tuerschlossV2_0_1.ino
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
#include <Arduino.h>
/* Türschloß V2
* by elektronik133| Jonas Giesecke
* on 15.4.2018
* for Schaffenburg e.V.
* https://wiki.schaffenburg.org/Projekt:TuerschlossV2
*/
#include "config.h"
#include <EEPROM.h>
//#include "stepstick.h"
#include "spacedoor.h"
//#include "spacedoor.cpp"
Spacedoor door;
int incomingByteArray[30];
int bytecounter = 0;
byte data_received[30];
int lock_timer = 0;
String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete
uint8_t eestart_h = 1;
uint8_t eestart_l = 2;
uint8_t eemiddle_h = 3;
uint8_t eemiddle_l = 4;
uint8_t eehalfstop_h = 5;
uint8_t eehalfstop_l = 6;
uint8_t eestop_h = 7;
uint8_t eestop_l = 8;
void setup()
{
Serial.begin(9600);
door.initdoor();
if (door.readButton() == LOW){
calibrate();
}
inputString.reserve(30); // reserve 30 bytes for the inputString:
// Kalibrier werte aus eeprom laden
door.unlocked_pos = (EEPROM.read(eestart_h))<<8;
door.unlocked_pos |= (EEPROM.read(eestart_l));
door.middle_pos = (EEPROM.read(eemiddle_h))<<8;
door.middle_pos |= (EEPROM.read(eemiddle_l));
door.half_locked_pos = (EEPROM.read(eehalfstop_h))<<8;
door.half_locked_pos |= (EEPROM.read(eehalfstop_l));
door.locked_pos = (EEPROM.read(eestop_h))<<8;
door.locked_pos |= (EEPROM.read(eestop_l));
Serial.println("Arduino Tuer Steuerung V0.1");
}
void loop()
{
serialEvent(); //call the function
door.getDoorStatus();
door.checkButton();
// test_fct();
delay(10);
}
void test_fct(){
static int testcounter = 0;
door.lock_door();
delay(1000);
door.unlock_door();
delay(1000);
testcounter ++;
Serial.println(testcounter);
}
void decode_comand(){
if(inputString == "lock"){
Serial.println(door.lock_door(),HEX);
}
if (inputString == "unlock") {
Serial.println(door.unlock_door(),HEX);
}
if(inputString == "info"){
Serial.println("Arduino Tuer Steuerung");
}
if(inputString == "version"){
Serial.println("Arduino Tuer Steuerung V0.1");
}
if(inputString == "status"){
door.getDoorStatus();
Serial.println(door.blatt_status,HEX);
Serial.println(door.riegel_status,HEX);
//Debug:
Serial.println(analogRead(door_poti),DEC);
Serial.println(door.unlocked_pos,DEC);
Serial.println(door.middle_pos,DEC);
Serial.println(door.half_locked_pos,DEC);
Serial.println(door.locked_pos,DEC);
}
}
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
//Serial.print(inChar);
// add it to the inputString:
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
if (inChar == '\n') {
stringComplete = true;
// leds[0] = CRGB::Black;
// FastLED.show();
}else{
inputString += inChar;
}
}
if (stringComplete) {
//door.getstatus();
decode_comand();
inputString = "";
stringComplete = false;
}
}
void calibrate(){
int val = 0;
door.setLED('b');
Serial.println("konfiguration gestartet");
//wait til the button is released
door.waitForButtonRelease();
// Unlock_pos einspeichern
Serial.println("Knauf gegen den Uhrzeigersinn drehen, bis Türfalle geöffnet. Dann Taster drücken.");
door.setLED('r');
delay(100);
while (door.readButton() == HIGH) {
val = door.readRefPoti(); //einlesen der Start Position
}
Serial.print("wert fuer --unlocked_pos-- ist: ");
Serial.println(val,DEC);
EEPROM.update(eestart_h, val>>8); //Abspeichern im EEPROM
EEPROM.update(eestart_l, val);
delay(50);
door.waitForButtonRelease();
//middle_pos einspeichern
Serial.println("Knauf im Uhrzeigersinn drehen, bis zur 12 Uhr stellung. Dann Taster drücken.");
door.setLED('r');
delay(100);
while (door.readButton() == HIGH) {
val = door.readRefPoti(); //einlesen der Position
}
Serial.print("wert fuer --middle_pos-- ist: ");
Serial.println(val,DEC);
EEPROM.update(eemiddle_h, val>>8); //Abspeichern im EEPROM
EEPROM.update(eemiddle_l, val);
delay(50);
door.waitForButtonRelease();
//half_locked_pos einspeichern
Serial.println("Knauf im Uhrzeigersinn drehen, bis zur naechsten 12 Uhr Stellung. Dann Taster drücken.");
door.setLED('r');
delay(100);
while (door.readButton() == HIGH) {
val = door.readRefPoti(); //einlesen der Position
}
Serial.print("wert fuer --half_locked_pos-- ist: ");
Serial.println(val,DEC);
EEPROM.update(eehalfstop_h, val>>8); //Abspeichern im EEPROM
EEPROM.update(eehalfstop_l, val);
delay(50);
door.waitForButtonRelease();
//locked_pos einspeichern
Serial.println("Knauf im Uhrzeigersinn drehen, bis zur naechsten 12 Uhr stellung. Dann Taster drücken.");
door.setLED('r');
delay(100);
while (door.readButton() == HIGH) {
val = door.readRefPoti(); //einlesen der Position
}
Serial.print("wert fuer --locked_pos-- ist: ");
Serial.println(val,DEC);
EEPROM.update(eestop_h, val>>8); //Abspeichern im EEPROM
EEPROM.update(eestop_l, val);
delay(50);
door.setLED('b');
Serial.println("Kalibrierung abgeschlossen");
delay(1000);
door.setLED('0');
}