Compare commits

..

No commits in common. "a09710fa4b13077fd961f742dab533e1b45f864b" and "241dc3c2b55d80a90d323c3980a21c13e8f45916" have entirely different histories.

6 changed files with 4 additions and 112 deletions

View File

@ -1,33 +0,0 @@
#include "beeper.h"
#include <Arduino.h>
#define BEEPER_GPIO 22
#define BEEPER_INVERT true
unsigned long beeperDuration = 0;
unsigned long beeperLast = 0;
void beeperEnable(const bool enabled) {
digitalWrite(BEEPER_GPIO, (enabled ^ BEEPER_INVERT) ? HIGH : LOW);
}
void beeperSetup() {
pinMode(BEEPER_GPIO, OUTPUT);
beeperEnable(false);
}
void beeperLoop() {
const auto now = millis();
if (beeperDuration != 0 && now - beeperLast >= beeperDuration) {
beeperEnable(false);
beeperDuration = 0;
}
}
void beep(const unsigned long duration) {
beeperDuration = duration;
beeperLast = millis();
beeperEnable(beeperDuration > 0);
}

View File

@ -1,10 +0,0 @@
#ifndef BEEPER_H
#define BEEPER_H
void beeperSetup();
void beeperLoop();
void beep(unsigned long duration);
#endif

View File

@ -1,15 +0,0 @@
#include "buzzer.h"
#include <Arduino.h>
#define BUZZER_GPIO 23
#define BUZZER_INVERT true
void buzzerSetup() {
pinMode(BUZZER_GPIO, OUTPUT);
buzzerEnable(false);
}
void buzzerEnable(const bool enabled) {
digitalWrite(BUZZER_GPIO, (enabled ^ BUZZER_INVERT) ? HIGH : LOW);
}

View File

@ -1,8 +0,0 @@
#ifndef BUZZER_H
#define BUZZER_H
void buzzerSetup();
void buzzerEnable(bool enabled);
#endif

View File

@ -1,15 +1,8 @@
#include <LittleFS.h>
#include "countdown.h"
#include "beeper.h"
#include "buzzer.h"
#include <LittleFS.h>
#include "display.h"
#define COUNTDOWN_END_SEQUENCE_STEPS 5
#define COUNTDOWN_END_SEQUENCE_REPEAT 3
#define HALF_BEEP_DURATION 1000
#define LAST_10_BEEP_DURATION 100
#define COUNTDOWN_END_SEQUENCE_REPEAT 2
enum CountdownState {
CONFIG, READY, RUNNING, PAUSED, END
@ -31,10 +24,6 @@ unsigned long countdownEndSequenceDelay = 0;
unsigned long countdownEndSequenceLast = 0;
bool countdownHalfTimeBeep = false;
long countdownBeepSeconds = -1;
void setState(const CountdownState newState) {
if (countdownState == newState) {
return;
@ -42,7 +31,6 @@ void setState(const CountdownState newState) {
countdownState = newState;
const char* name;
bool buzzer = false;
switch (countdownState) {
case CONFIG:
countdownRest = countdownMillis;
@ -50,8 +38,6 @@ void setState(const CountdownState newState) {
break;
case READY:
countdownRest = countdownMillis;
countdownHalfTimeBeep = false;
countdownBeepSeconds = -1;
name = "READY";
break;
case RUNNING:
@ -62,7 +48,6 @@ void setState(const CountdownState newState) {
name = "PAUSED";
break;
case END:
buzzer = true;
countdownEndSequenceDelay = 0;
countdownEndSequenceStep = 0;
name = "END";
@ -71,7 +56,6 @@ void setState(const CountdownState newState) {
name = "[???]";
break;
}
buzzerEnable(buzzer);
Serial.printf("Mode: %s\n", name);
}
@ -80,14 +64,12 @@ void drawSequence() {
if (countdownEndSequenceLast != 0 && now - countdownEndSequenceLast < countdownEndSequenceDelay) {
return;
}
switch (countdownEndSequenceStep % COUNTDOWN_END_SEQUENCE_STEPS) {
switch (countdownEndSequenceStep % 3) {
case 0:
case 2:
drawAll(WHITE);
countdownEndSequenceDelay = 100;
break;
case 1:
case 3:
drawBlack();
countdownEndSequenceDelay = 100;
break;
@ -98,7 +80,7 @@ void drawSequence() {
}
countdownEndSequenceStep++;
countdownEndSequenceLast = now;
if (countdownEndSequenceStep >= COUNTDOWN_END_SEQUENCE_STEPS * COUNTDOWN_END_SEQUENCE_REPEAT) {
if (countdownEndSequenceStep >= 3 * COUNTDOWN_END_SEQUENCE_REPEAT) {
setState(READY);
}
}
@ -180,22 +162,6 @@ void updateTime() {
if (countdownLast != 0) {
const auto diff = now - countdownLast;
countdownRest -= static_cast<long>(diff);
if (countdownRest <= countdownMillis / 2) {
if (!countdownHalfTimeBeep) {
beep(HALF_BEEP_DURATION);
countdownHalfTimeBeep = true;
}
}
const auto seconds = static_cast<long>(ceil(countdownRest / 1000.0));
if (seconds <= 10 && seconds > 0) {
if (countdownBeepSeconds != seconds) {
beep(LAST_10_BEEP_DURATION);
countdownBeepSeconds = seconds;
}
}
if (countdownRest <= 0) {
countdownRest = 0;
setState(END);

View File

@ -1,6 +1,4 @@
#include "beeper.h"
#include "button.h"
#include "buzzer.h"
#include "countdown.h"
#include "display.h"
@ -8,18 +6,12 @@ void setup() {
delay(500);
Serial.begin(115200);
Serial.println("\n\n\nstartup");
beeperSetup();
buttonSetup();
buzzerSetup();
displaySetup();
countdownSetup();
}
void loop() {
beeperLoop();
buttonLoop();
countdownLoop();
}