anpassungen für nutzung von Makefile
This commit is contained in:
parent
a495c47591
commit
33bce81a42
2 changed files with 42 additions and 28 deletions
26
Makefile
26
Makefile
|
@ -1,22 +1,26 @@
|
||||||
SRC:=$(shell find src -regex '.*\.c')
|
SRC:=$(shell find status -regex '.*\.cpp')
|
||||||
OBJ:=$(patsubst %,%.o,$(SRC))
|
OBJ:=$(patsubst %,%.o,$(SRC))
|
||||||
DEP:=$(patsubst %,%.d,$(SRC))
|
DEP:=$(patsubst %,%.d,$(SRC))
|
||||||
|
|
||||||
CC?=avr-gcc
|
CC?=avr-gcc
|
||||||
|
|
||||||
CFLAGS?= -O2 -ggdb -std=gnu11 -fomit-frame-pointer -fmerge-all-constants\
|
CFLAGS?= -O2 -ggdb -std=gnu++11 -fomit-frame-pointer -fmerge-all-constants\
|
||||||
-faggressive-loop-optimizations -finline-functions -funsafe-loop-optimizations\
|
-faggressive-loop-optimizations -finline-functions -funsafe-loop-optimizations\
|
||||||
-ffreestanding -Wlogical-op -Wdouble-promotion -Wformat -Winit-self -Wnormalized\
|
-ffreestanding -Wlogical-op -Wdouble-promotion -Wformat -Winit-self\
|
||||||
-Wmissing-include-dirs -Wswitch-default -Wpadded -Wswitch-enum -Wall\
|
-Wmissing-include-dirs -Wswitch-default -Wpadded -Wswitch-enum -Wall\
|
||||||
-Wunused -Winline -Wuninitialized -Wstrict-overflow -Wpointer-sign\
|
-Wunused -Winline -Wuninitialized -Wstrict-overflow\
|
||||||
-Wfloat-equal -Wstack-protector -Wtraditional-conversion -Wundef -Wvla\
|
-Wfloat-equal -Wstack-protector -Wundef -Wvla\
|
||||||
-Wdeclaration-after-statement -Wshadow -Wcast-align -Wpedantic -Wextra\
|
-Wshadow -Wcast-align -Wpedantic -Wextra\
|
||||||
-Wpointer-arith -Wbad-function-cast -Wwrite-strings -Wtrampolines -Wpacked\
|
-Wpointer-arith -Wwrite-strings -Wtrampolines -Wpacked\
|
||||||
-Wconversion -Wdate-time -Waggregate-return -Wstrict-prototypes\
|
-Wconversion -Wdate-time -Waggregate-return\
|
||||||
-Wold-style-definition -Wmissing-prototypes -Wvector-operation-performance\
|
-Wvector-operation-performance\
|
||||||
-Wredundant-decls -Wnested-externs -Wlong-long -Wvariadic-macros\
|
-Wredundant-decls -Wlong-long -Wvariadic-macros\
|
||||||
-Wdisabled-optimization -Wmissing-declarations -Wunsafe-loop-optimizations\
|
-Wdisabled-optimization -Wmissing-declarations -Wunsafe-loop-optimizations\
|
||||||
-Wunsuffixed-float-constants -pipe -Werror
|
-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?=
|
ARDUINO?=
|
||||||
PROGRAMMER?=
|
PROGRAMMER?=
|
||||||
|
|
|
@ -1,13 +1,23 @@
|
||||||
#include <limits.h>
|
#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:
|
* es gibt folgende Zustände:
|
||||||
* 0 - Aus
|
* 0 - Aus
|
||||||
* 1 - An, aber auf dem weg zu aus
|
* 1 - An, aber auf dem weg zu aus
|
||||||
* 2 - An
|
* 2 - An
|
||||||
*/
|
*/
|
||||||
#define STATE_OFF 3
|
constexpr char STATE_OFF = 3;
|
||||||
#define STATE_HALF 1
|
constexpr char STATE_HALF = 1;
|
||||||
#define STATE_ON 2
|
constexpr char STATE_ON = 2;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Zeit wie lange in einem Zustände verharrt werden soll
|
* Zeit wie lange in einem Zustände verharrt werden soll
|
||||||
|
@ -15,19 +25,19 @@
|
||||||
* TIME_HALF - Zeitspanne von Zustand 2 bis Wechsel zu Zustand 1
|
* TIME_HALF - Zeitspanne von Zustand 2 bis Wechsel zu Zustand 1
|
||||||
* TIME_OFF - Zeitspanne von Zustand 2 bis Wechsel zu Zustand 0
|
* TIME_OFF - Zeitspanne von Zustand 2 bis Wechsel zu Zustand 0
|
||||||
*/
|
*/
|
||||||
#define TIME_HALF 5400000 // 1,5h
|
constexpr int TIME_HALF = 5400000; // 1,5h
|
||||||
#define TIME_OFF 7200000 // 2h
|
constexpr int TIME_OFF = 7200000; // 2h
|
||||||
|
|
||||||
// Ein-/Ausgänge Bezeichnen
|
// Ein-/Ausgänge Bezeichnen
|
||||||
const int BTN_ON = 2; // Einschalter
|
constexpr int BTN_ON = 2; // Einschalter
|
||||||
const int BTN_OFF = 3; // Ausschalter
|
constexpr int BTN_OFF = 3; // Ausschalter
|
||||||
const int LED_G = 9; // grüne LED
|
constexpr int LED_G = 9; // grüne LED
|
||||||
const int LED_Y = 8; // gelbe LED
|
constexpr int LED_Y = 8; // gelbe LED
|
||||||
const int LED_R = 7; // rote LED
|
constexpr int LED_R = 7; // rote LED
|
||||||
|
|
||||||
// hier wird der aktuelle und vorherige Zustand gespeichert
|
// hier wird der aktuelle und vorherige Zustand gespeichert
|
||||||
byte state_current = NULL;
|
char state_current = STATE_OFF;
|
||||||
byte state_previous = NULL;
|
char state_previous = STATE_OFF;
|
||||||
|
|
||||||
// hier wird der Beginn des aktuellen Zustand gespeichert in Millisekunden nach Uptime.
|
// hier wird der Beginn des aktuellen Zustand gespeichert in Millisekunden nach Uptime.
|
||||||
unsigned long stateBegan;
|
unsigned long stateBegan;
|
||||||
|
@ -37,7 +47,7 @@ class Debounce
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Debounce(int pin);
|
Debounce(int pin);
|
||||||
boolean update();
|
bool update();
|
||||||
int read();
|
int read();
|
||||||
private:
|
private:
|
||||||
int _pin;
|
int _pin;
|
||||||
|
@ -70,14 +80,14 @@ void testLeds() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// wechselt zu neuen Zustand
|
// wechselt zu neuen Zustand
|
||||||
void changeStateTo(byte state_new) {
|
void changeStateTo(char state_new) {
|
||||||
state_previous = state_current;
|
state_previous = state_current;
|
||||||
state_current = state_new;
|
state_current = state_new;
|
||||||
transition();
|
transition();
|
||||||
}
|
}
|
||||||
|
|
||||||
// behandelt die Zustandübergänge
|
// behandelt die Zustandübergänge
|
||||||
boolean transition() {
|
bool transition() {
|
||||||
if (state_previous == STATE_OFF && state_current == STATE_ON) {
|
if (state_previous == STATE_OFF && state_current == STATE_ON) {
|
||||||
digitalWrite(LED_R, LOW);
|
digitalWrite(LED_R, LOW);
|
||||||
digitalWrite(LED_G, HIGH);
|
digitalWrite(LED_G, HIGH);
|
||||||
|
@ -172,7 +182,7 @@ Debounce::Debounce(int pin)
|
||||||
this->_state = LOW;
|
this->_state = LOW;
|
||||||
this->_delay = 50;
|
this->_delay = 50;
|
||||||
}
|
}
|
||||||
boolean Debounce::update()
|
bool Debounce::update()
|
||||||
{
|
{
|
||||||
if (millis() - this->_time >= this->_delay) {
|
if (millis() - this->_time >= this->_delay) {
|
||||||
int reading = digitalRead(this->_pin);
|
int reading = digitalRead(this->_pin);
|
Reference in a new issue