doorstatus/source/arduino/arduino.ino
2020-12-28 21:56:24 +01:00

70 lines
1.7 KiB
C++

/*
Copyright (c):
Philipp Matthias Schäfer (philipp.matthias.schaefer@posteo.de), 2020
This file is part of the KrautStatus' Arduino code.
The Clean CommonMark library is free software: you can redistribute it and/or
modify it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
The Clean CommonMark library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
for more details.
You should have received a copy of the GNU Affero General Public License along
with the Clean CommonMark library. If not, see <https://www.gnu.org/licenses/>.
*/
#include <SPI.h>
#include <uTimerLib.h>
#include "config.h"
#include "matrix.h"
#include "sensor.h"
#include "serial.h"
#include "wifi.h"
const unsigned long int MATRIX_UPDATE_FREQUENCY = 1;
void setup() {
serial_setup();
matrix_setup();
boolean wifi_result = matrix_show_scan_and_run(wifi_setup);
if (!wifi_result) {
matrix_show_failure();
while(true);
}
sensor_setup();
start_matrix_update();
}
void loop() {
int packetSize = Udp.parsePacket();
if (packetSize) {
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(uint8_t(sensor_get_door_state()));
Udp.endPacket();
}
}
void start_matrix_update() {
TimerLib.setInterval_us(matrix_update, 1000000 / MATRIX_UPDATE_FREQUENCY);
}
void matrix_update() {
switch (sensor_get_door_state()) {
OPEN:
matrix_fill(GREEN);
break;
CLOSED:
matrix_fill(BLACK);
break;
}
}