code clean
This commit is contained in:
parent
365a785217
commit
f412bc60da
@ -1,6 +1,6 @@
|
||||
#include "Color.h"
|
||||
|
||||
#define ___ 0
|
||||
#define ___ 0 // NOLINT(*-reserved-identifier)
|
||||
#define QQQ 64
|
||||
#define TTT 85
|
||||
#define HHH 127
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
#ifndef WS2812B_COLOR_H
|
||||
#define WS2812B_COLOR_H
|
||||
#ifndef SPORTTAFEL_COLOR_H
|
||||
#define SPORTTAFEL_COLOR_H
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
struct Color {
|
||||
uint8_t r, g, b;
|
||||
|
||||
Color(uint8_t r, uint8_t g, uint8_t b) : r(r), g(g), b(b) {
|
||||
Color(const uint8_t r, const uint8_t g, const uint8_t b) : r(r), g(g), b(b) {
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#ifndef WS2812B_BUTTON_H
|
||||
#define WS2812B_BUTTON_H
|
||||
#ifndef SPORTTAFEL_BUTTON_H
|
||||
#define SPORTTAFEL_BUTTON_H
|
||||
|
||||
void buttonSetup();
|
||||
|
||||
|
||||
@ -8,9 +8,9 @@ enum State {
|
||||
|
||||
State state = CONFIG;
|
||||
|
||||
long configMillis = 6 * 60 * 1000;
|
||||
long countdownConfig = 6 * 60 * 1000;
|
||||
|
||||
long rest = configMillis;
|
||||
long countdownRest = countdownConfig;
|
||||
|
||||
unsigned long last = 0;
|
||||
|
||||
@ -21,42 +21,18 @@ void updateTime() {
|
||||
const auto now = max(1UL, millis());
|
||||
if (last != 0) {
|
||||
const auto diff = now - last;
|
||||
rest -= (long) diff;
|
||||
if (rest < 0) {
|
||||
rest = 0;
|
||||
countdownRest -= static_cast<long>(diff);
|
||||
if (countdownRest < 0) {
|
||||
countdownRest = 0;
|
||||
}
|
||||
}
|
||||
last = now;
|
||||
}
|
||||
|
||||
void drawDashes() {
|
||||
displayClear();
|
||||
drawChar(0, '-', true, RED);
|
||||
drawChar(1, '-', true, RED);
|
||||
drawChar(2, '-', true, RED);
|
||||
drawChar(3, '-', true, RED);
|
||||
displayShow();
|
||||
}
|
||||
|
||||
void drawWhite() {
|
||||
displayClear();
|
||||
drawChar(0, '8', true, WHITE);
|
||||
drawChar(1, '8', true, WHITE);
|
||||
drawDots(WHITE, WHITE, WHITE, WHITE);
|
||||
drawChar(2, '8', true, WHITE);
|
||||
drawChar(3, '8', true, WHITE);
|
||||
displayShow();
|
||||
}
|
||||
|
||||
void drawBlack() {
|
||||
displayClear();
|
||||
displayShow();
|
||||
}
|
||||
|
||||
void drawSequence() {
|
||||
for (int x = 0; x < 3; ++x) {
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
drawWhite();
|
||||
drawAll(WHITE);
|
||||
delay(100);
|
||||
drawBlack();
|
||||
delay(100);
|
||||
@ -66,20 +42,20 @@ void drawSequence() {
|
||||
}
|
||||
}
|
||||
|
||||
void setState(State newState) {
|
||||
void setState(const State newState) {
|
||||
if (state == newState) {
|
||||
return;
|
||||
}
|
||||
|
||||
state = newState;
|
||||
const char *name;
|
||||
const char* name;
|
||||
switch (state) {
|
||||
case CONFIG:
|
||||
rest = configMillis;
|
||||
countdownRest = countdownConfig;
|
||||
name = "CONFIG";
|
||||
break;
|
||||
case READY:
|
||||
rest = configMillis;
|
||||
countdownRest = countdownConfig;
|
||||
name = "READY";
|
||||
break;
|
||||
case RUNNING:
|
||||
@ -103,15 +79,15 @@ void setState(State newState) {
|
||||
void countdownUpdate() {
|
||||
switch (state) {
|
||||
case CONFIG:
|
||||
drawMillis(rest, MAGENTA);
|
||||
drawMillis(countdownRest, MAGENTA);
|
||||
break;
|
||||
case READY:
|
||||
drawMillis(rest, GREEN);
|
||||
drawMillis(countdownRest, GREEN);
|
||||
break;
|
||||
case RUNNING: {
|
||||
if (rest > 0) {
|
||||
const auto color = rest >= 60000 ? WHITE : (rest >= 10000 ? YELLOW : RED);
|
||||
drawMillis(rest, color);
|
||||
if (countdownRest > 0) {
|
||||
const auto color = countdownRest >= 60000 ? WHITE : (countdownRest >= 10000 ? YELLOW : RED);
|
||||
drawMillis(countdownRest, color);
|
||||
} else {
|
||||
setState(END);
|
||||
setState(READY);
|
||||
@ -119,7 +95,7 @@ void countdownUpdate() {
|
||||
break;
|
||||
}
|
||||
case PAUSED:
|
||||
drawMillis(rest, BLUE);
|
||||
drawMillis(countdownRest, BLUE);
|
||||
break;
|
||||
case END:
|
||||
drawDashes();
|
||||
@ -155,9 +131,9 @@ void buttonShortPressed() {
|
||||
void buttonLongPressed() {
|
||||
switch (state) {
|
||||
case CONFIG: {
|
||||
const auto seconds = (configMillis / 30000) * 30 % (15 * 60) + 30;
|
||||
configMillis = seconds * 1000;
|
||||
rest = configMillis;
|
||||
const auto seconds = (countdownConfig / 30000) * 30 % (15 * 60) + 30;
|
||||
countdownConfig = seconds * 1000;
|
||||
countdownRest = countdownConfig;
|
||||
break;
|
||||
}
|
||||
case RUNNING:
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#ifndef WS2812B_COUNTDOWN_H
|
||||
#define WS2812B_COUNTDOWN_H
|
||||
#ifndef SPORTTAFEL_COUNTDOWN_H
|
||||
#define SPORTTAFEL_COUNTDOWN_H
|
||||
|
||||
void countdownSetup();
|
||||
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
#include "display.h"
|
||||
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
|
||||
#define DIGIT_COUNT 4
|
||||
#define SEGMENTS_PER_DIGIT 7
|
||||
#define LEDS_PER_SEGMENT 6
|
||||
@ -30,7 +32,7 @@ uint8_t CHARS[] = {
|
||||
0b00000010, // -
|
||||
};
|
||||
|
||||
int toIndex(char c) {
|
||||
int toIndex(const char c) {
|
||||
if (c >= '0' && c <= '9') {
|
||||
return c - '0';
|
||||
}
|
||||
@ -45,11 +47,12 @@ int toIndex(char c) {
|
||||
return 5;
|
||||
case '-':
|
||||
return 13;
|
||||
}
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t mapChar(char c) {
|
||||
uint8_t mapChar(const char c) {
|
||||
const int index = toIndex(c);
|
||||
if (index >= 0) {
|
||||
return CHARS[index];
|
||||
@ -72,11 +75,11 @@ void displayShow() {
|
||||
pixels.show();
|
||||
}
|
||||
|
||||
void drawChar(int digit, char c, const Color& color) {
|
||||
void drawChar(const int digit, const char c, const Color& color) {
|
||||
drawChar(digit, c, true, color);
|
||||
}
|
||||
|
||||
void drawChar(int digit, char c, bool showIfZero, const Color& color) {
|
||||
void drawChar(const int digit, const char c, const bool showIfZero, const Color& color) {
|
||||
if (c == '0' && !showIfZero) {
|
||||
return;
|
||||
}
|
||||
@ -97,14 +100,14 @@ void drawChar(int digit, char c, bool showIfZero, const Color& color) {
|
||||
}
|
||||
}
|
||||
|
||||
void drawNumber(int digit, int number, bool zero, const Color& color) {
|
||||
void drawNumber(const int digit, const int number, const bool zero, const Color& color) {
|
||||
const char ten = '0' + (number / 10 % 10);
|
||||
const char one = '0' + (number % 10);
|
||||
drawChar(digit + 0, ten, zero, color);
|
||||
drawChar(digit + 1, one, true, color);
|
||||
}
|
||||
|
||||
void drawDot(int dot, const Color& c) {
|
||||
void drawDot(const int dot, const Color& c) {
|
||||
int index = 2 * SEGMENTS_PER_DIGIT * LEDS_PER_SEGMENT + dot * LEDS_PER_DOT;
|
||||
pixels.setPixelColor(index + 0, c.r, c.g, c.b);
|
||||
pixels.setPixelColor(index + 1, c.r, c.g, c.b);
|
||||
@ -117,11 +120,11 @@ void drawDots(const Color& bottom, const Color& middleBottom, const Color& middl
|
||||
drawDot(3, top);
|
||||
}
|
||||
|
||||
void drawMillisDeci(unsigned long millisTotal, const Color& color) {
|
||||
void drawMillisDeci(const unsigned long millisTotal, const Color& color) {
|
||||
const auto secondsTotal = millisTotal / 1000;
|
||||
const auto minutes = (int) secondsTotal / 60;
|
||||
const auto seconds = (int) secondsTotal % 60;
|
||||
const auto deci = (int) millisTotal / 100 % 10;
|
||||
const auto minutes = (int)secondsTotal / 60;
|
||||
const auto seconds = (int)secondsTotal % 60;
|
||||
const auto deci = (int)millisTotal / 100 % 10;
|
||||
|
||||
pixels.clear();
|
||||
if (minutes > 0) {
|
||||
@ -138,10 +141,10 @@ void drawMillisDeci(unsigned long millisTotal, const Color& color) {
|
||||
pixels.show();
|
||||
}
|
||||
|
||||
void drawMillis(unsigned long millisTotal, const Color& color) {
|
||||
const auto secondsTotal = (unsigned long) ceil(millisTotal / 1000.0);
|
||||
const auto minutes = (int) secondsTotal / 60;
|
||||
const auto seconds = (int) secondsTotal % 60;
|
||||
void drawMillis(const unsigned long millisTotal, const Color& color) {
|
||||
const auto secondsTotal = (unsigned long)ceil(millisTotal / 1000.0);
|
||||
const auto minutes = (int)secondsTotal / 60;
|
||||
const auto seconds = (int)secondsTotal % 60;
|
||||
|
||||
pixels.clear();
|
||||
if (minutes > 0) {
|
||||
@ -151,3 +154,27 @@ void drawMillis(unsigned long millisTotal, const Color& color) {
|
||||
drawNumber(2, seconds, minutes > 0, color);
|
||||
pixels.show();
|
||||
}
|
||||
|
||||
void drawDashes() {
|
||||
displayClear();
|
||||
drawChar(0, '-', true, RED);
|
||||
drawChar(1, '-', true, RED);
|
||||
drawChar(2, '-', true, RED);
|
||||
drawChar(3, '-', true, RED);
|
||||
displayShow();
|
||||
}
|
||||
|
||||
void drawAll(const Color& color) {
|
||||
displayClear();
|
||||
drawChar(0, '8', true, color);
|
||||
drawChar(1, '8', true, color);
|
||||
drawDots(color, color, color, color);
|
||||
drawChar(2, '8', true, color);
|
||||
drawChar(3, '8', true, color);
|
||||
displayShow();
|
||||
}
|
||||
|
||||
void drawBlack() {
|
||||
displayClear();
|
||||
displayShow();
|
||||
}
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
#ifndef WS2812B_DISPLAY_H
|
||||
#define WS2812B_DISPLAY_H
|
||||
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
#ifndef SPORTTAFEL_DISPLAY_H
|
||||
#define SPORTTAFEL_DISPLAY_H
|
||||
|
||||
#include "Color.h"
|
||||
|
||||
@ -23,4 +21,10 @@ void drawMillisDeci(unsigned long millisTotal, const Color& color);
|
||||
|
||||
void drawMillis(unsigned long millisTotal, const Color& color);
|
||||
|
||||
void drawDashes();
|
||||
|
||||
void drawAll(const Color&);
|
||||
|
||||
void drawBlack();
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#include "display.h"
|
||||
#include "button.h"
|
||||
#include "countdown.h"
|
||||
#include "display.h"
|
||||
|
||||
void setup() {
|
||||
delay(500);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user