Compare commits
14 commits
Author | SHA1 | Date | |
---|---|---|---|
|
a90280ff97 | ||
|
c7c3152108 | ||
|
8efaf7df01 | ||
|
18d0aa878a | ||
|
d77264ba9e | ||
|
573e1ec66f | ||
|
096bb37f05 | ||
|
f8e447a4b8 | ||
|
e92963e932 | ||
|
aab9eb3700 | ||
|
e813711ad8 | ||
|
cddc1d675a | ||
|
41cec53d48 | ||
|
9d34f7e60b |
5 changed files with 92 additions and 88 deletions
45
Makefile
45
Makefile
|
@ -1,45 +0,0 @@
|
|||
SRC:=$(shell find status -regex '.*\.cpp')
|
||||
OBJ:=$(patsubst %,%.o,$(SRC))
|
||||
DEP:=$(patsubst %,%.d,$(SRC))
|
||||
|
||||
CC?=avr-gcc
|
||||
|
||||
CFLAGS?= -O2 -ggdb -std=gnu++11 -fomit-frame-pointer -fmerge-all-constants\
|
||||
-faggressive-loop-optimizations -finline-functions -funsafe-loop-optimizations\
|
||||
-ffreestanding -Wlogical-op -Wdouble-promotion -Wformat -Winit-self\
|
||||
-Wmissing-include-dirs -Wswitch-default -Wpadded -Wswitch-enum -Wall\
|
||||
-Wunused -Winline -Wuninitialized -Wstrict-overflow\
|
||||
-Wfloat-equal -Wstack-protector -Wundef -Wvla\
|
||||
-Wshadow -Wcast-align -Wpedantic -Wextra\
|
||||
-Wpointer-arith -Wwrite-strings -Wtrampolines -Wpacked\
|
||||
-Wconversion -Wdate-time -Waggregate-return\
|
||||
-Wvector-operation-performance\
|
||||
-Wredundant-decls -Wlong-long -Wvariadic-macros\
|
||||
-Wdisabled-optimization -Wmissing-declarations -Wunsafe-loop-optimizations\
|
||||
-pipe -Werror -fno-exceptions -fno-rtti\
|
||||
-I/usr/share/arduino/hardware/arduino/cores/arduino\
|
||||
-I/usr/share/arduino/hardware/arduino/variants/micro\
|
||||
-I/usr/lib/avr/include/\
|
||||
-DF_CPU=16000000L -MMD -DUSB_VID=0x2341 -DUSB_PID=0x8037 -DARDUINO=105 -D__PROG_TYPES_COMPAT__ -mmcu=atmega32u4
|
||||
|
||||
ARDUINO?=
|
||||
PROGRAMMER?=
|
||||
|
||||
.PHONY: all clean check install build
|
||||
|
||||
all: build
|
||||
|
||||
# TODO : find a install commandline
|
||||
#install: build
|
||||
# avrdude
|
||||
|
||||
clean:
|
||||
rm $(OBJ) $(DEP)
|
||||
|
||||
check:
|
||||
$(CC) $(CFLAGS) -fsyntax-only $(SRC)
|
||||
|
||||
build: $(SRC)
|
||||
$(CC) $(CFLAGS) $(SRC) -MMD -MP -o hackspace-status.sys
|
||||
|
||||
-include $(sort $(DEP))
|
|
@ -1,4 +1,4 @@
|
|||
hackerspace-status-arduino
|
||||
==========================
|
||||
|
||||
see https://kraut.space/hswiki:projekte:2014:raumstatus_anzeige
|
||||
see https://www.krautspace.de/hswiki:projekte:elektronikrunde:status_anzeige
|
||||
|
|
13
push.d/skeleton
Normal file
13
push.d/skeleton
Normal file
|
@ -0,0 +1,13 @@
|
|||
#!/bin/sh
|
||||
|
||||
case "$1" in
|
||||
ON)
|
||||
echo 'ON'
|
||||
;;
|
||||
HALF)
|
||||
echo 'HALF'
|
||||
;;
|
||||
OFF)
|
||||
echo 'OFF'
|
||||
;;
|
||||
esac
|
28
push.sh
Executable file
28
push.sh
Executable file
|
@ -0,0 +1,28 @@
|
|||
#!/bin/sh -e
|
||||
|
||||
DEV='/dev/ttyUSB0'
|
||||
DIR='push.d'
|
||||
stty -F "$DEV" 9600 -brkint -icrnl -imaxbel -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke
|
||||
|
||||
# Warte bis Device $DEV vorhanden ist
|
||||
while [ ! -c "$DEV" ]; do
|
||||
sleep 2
|
||||
done
|
||||
# sende beliebiges Zeichen an $DEV
|
||||
echo '?' >> "$DEV" &
|
||||
|
||||
while true; do
|
||||
# wenn $DEV vorhanden
|
||||
if [ -c "$DEV" ]; then
|
||||
# dann lese zustand
|
||||
read -r state < "$DEV"
|
||||
case "$state" in
|
||||
ON|HALF|OFF)
|
||||
run-parts --arg="$state" "$DIR"
|
||||
;;
|
||||
esac
|
||||
else
|
||||
# sonst warte
|
||||
sleep 10
|
||||
fi
|
||||
done
|
|
@ -1,23 +1,12 @@
|
|||
#include <cstddef>
|
||||
#include <climits>
|
||||
#include "Arduino.h"
|
||||
|
||||
void setup();
|
||||
void testLeds();
|
||||
void loop();
|
||||
void changeStateTo(char state_new);
|
||||
bool transition();
|
||||
void sendState();
|
||||
unsigned long calcStateTime();
|
||||
/*
|
||||
* es gibt folgende Zustände:
|
||||
* 0 - Aus
|
||||
* 1 - An, aber auf dem weg zu aus
|
||||
* 2 - An
|
||||
*/
|
||||
constexpr char STATE_OFF = 3;
|
||||
constexpr char STATE_HALF = 1;
|
||||
constexpr char STATE_ON = 2;
|
||||
#define STATE_OFF 3
|
||||
#define STATE_HALF 1
|
||||
#define STATE_ON 2
|
||||
|
||||
/*
|
||||
* Zeit wie lange in einem Zustände verharrt werden soll
|
||||
|
@ -25,19 +14,22 @@ constexpr char STATE_ON = 2;
|
|||
* TIME_HALF - Zeitspanne von Zustand 2 bis Wechsel zu Zustand 1
|
||||
* TIME_OFF - Zeitspanne von Zustand 2 bis Wechsel zu Zustand 0
|
||||
*/
|
||||
constexpr int TIME_HALF = 5400000; // 1,5h
|
||||
constexpr int TIME_OFF = 7200000; // 2h
|
||||
#define TIME_HALF 5400000 // 1,5h
|
||||
#define TIME_OFF 7200000 // 2h
|
||||
|
||||
// für Variablen Überlauf in calcStateTime
|
||||
#define MAX_LONG 4294967295
|
||||
|
||||
// Ein-/Ausgänge Bezeichnen
|
||||
constexpr int BTN_ON = 2; // Einschalter
|
||||
constexpr int BTN_OFF = 3; // Ausschalter
|
||||
constexpr int LED_G = 9; // grüne LED
|
||||
constexpr int LED_Y = 8; // gelbe LED
|
||||
constexpr int LED_R = 7; // rote LED
|
||||
const int BTN_ON = 2; // Einschalter
|
||||
const int BTN_OFF = 3; // Ausschalter
|
||||
const int LED_G = 9; // grüne LED
|
||||
const int LED_Y = 8; // gelbe LED
|
||||
const int LED_R = 7; // rote LED
|
||||
|
||||
// hier wird der aktuelle und vorherige Zustand gespeichert
|
||||
char state_current = STATE_OFF;
|
||||
char state_previous = STATE_OFF;
|
||||
byte state_current = NULL;
|
||||
byte state_previous = NULL;
|
||||
|
||||
// hier wird der Beginn des aktuellen Zustand gespeichert in Millisekunden nach Uptime.
|
||||
unsigned long stateBegan;
|
||||
|
@ -47,7 +39,7 @@ class Debounce
|
|||
{
|
||||
public:
|
||||
Debounce(int pin);
|
||||
bool update();
|
||||
boolean update();
|
||||
int read();
|
||||
private:
|
||||
int _pin;
|
||||
|
@ -80,17 +72,18 @@ void testLeds() {
|
|||
}
|
||||
|
||||
// wechselt zu neuen Zustand
|
||||
void changeStateTo(char state_new) {
|
||||
void changeStateTo(byte state_new) {
|
||||
state_previous = state_current;
|
||||
state_current = state_new;
|
||||
transition();
|
||||
}
|
||||
|
||||
// behandelt die Zustandübergänge
|
||||
bool transition() {
|
||||
boolean transition() {
|
||||
if (state_previous == STATE_OFF && state_current == STATE_ON) {
|
||||
digitalWrite(LED_R, LOW);
|
||||
digitalWrite(LED_G, HIGH);
|
||||
printState(state_current);
|
||||
stateBegan = millis();
|
||||
return true;
|
||||
}
|
||||
|
@ -101,16 +94,19 @@ bool transition() {
|
|||
if (state_previous == STATE_ON && state_current == STATE_HALF) {
|
||||
digitalWrite(LED_G, LOW);
|
||||
digitalWrite(LED_Y, HIGH);
|
||||
printState(state_current);
|
||||
return true;
|
||||
}
|
||||
if (state_previous == STATE_ON && state_current == STATE_OFF) {
|
||||
digitalWrite(LED_G, LOW);
|
||||
digitalWrite(LED_R, HIGH);
|
||||
printState(state_current);
|
||||
return true;
|
||||
}
|
||||
if (state_previous == STATE_HALF && state_current == STATE_OFF) {
|
||||
digitalWrite(LED_Y, LOW);
|
||||
digitalWrite(LED_R, HIGH);
|
||||
printState(state_current);
|
||||
return true;
|
||||
}
|
||||
if (state_previous == STATE_HALF && state_current == STATE_ON) {
|
||||
|
@ -123,28 +119,42 @@ bool transition() {
|
|||
digitalWrite(LED_G, LOW);
|
||||
digitalWrite(LED_Y, LOW);
|
||||
digitalWrite(LED_R, HIGH);
|
||||
printState(state_current);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// information über aktuellen Zustand auf die Serielle Verbindung schreiben
|
||||
void sendState() {
|
||||
if (state_current == STATE_ON || state_current == STATE_HALF) {
|
||||
Serial.print("1");
|
||||
} else {
|
||||
Serial.print("0");
|
||||
// schreibt den aktuellen Zustand auf die Serialeverbindung
|
||||
void printState(byte state) {
|
||||
switch (state) {
|
||||
case STATE_OFF:
|
||||
Serial.print("OFF\n");
|
||||
break;
|
||||
case STATE_HALF:
|
||||
Serial.print("HALF\n");
|
||||
break;
|
||||
case STATE_ON:
|
||||
Serial.print("ON\n");
|
||||
}
|
||||
}
|
||||
|
||||
void handleSerial() {
|
||||
if (Serial.read() != -1) {
|
||||
printState(state_current);
|
||||
do {
|
||||
delay(10);
|
||||
} while (Serial.read() != -1);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long calcStateTime() {
|
||||
// Variablen überlauf von millis erkennen
|
||||
unsigned long current_uptime = millis();
|
||||
// kein überlauf
|
||||
if (current_uptime > stateBegan) {
|
||||
return current_uptime - stateBegan;
|
||||
if (millis() - stateBegan >= 0) {
|
||||
return millis() - stateBegan;
|
||||
} else {
|
||||
return millis() + (MAX_LONG - stateBegan);
|
||||
}
|
||||
return current_uptime + (ULONG_MAX - stateBegan);
|
||||
}
|
||||
|
||||
// wird nach dem Starten dauerhaft ausgeführt
|
||||
|
@ -167,10 +177,8 @@ void loop() {
|
|||
} else if (state_current == STATE_HALF && calcStateTime() >= TIME_OFF) {
|
||||
changeStateTo(STATE_OFF);
|
||||
}
|
||||
|
||||
// kommunizieren
|
||||
sendState();
|
||||
delay(10);
|
||||
// auf Eingaben auf der Serialenverbindung reagieren
|
||||
handleSerial();
|
||||
}
|
||||
|
||||
// Debouncer Klasse
|
||||
|
@ -182,7 +190,7 @@ Debounce::Debounce(int pin)
|
|||
this->_state = LOW;
|
||||
this->_delay = 50;
|
||||
}
|
||||
bool Debounce::update()
|
||||
boolean Debounce::update()
|
||||
{
|
||||
if (millis() - this->_time >= this->_delay) {
|
||||
int reading = digitalRead(this->_pin);
|
Reference in a new issue