Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control extra load #94

Open
wants to merge 3 commits into
base: DEV
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions Tonuino.ino
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ adminSettings mySettings;
nfcTagObject myCard;
folderSettings *myFolder;
unsigned long sleepAtMillis = 0;
unsigned long toggleLoadAtMillis = 0;
static uint16_t _lastTrackFinished;

static void nextTrack(uint16_t track);
Expand All @@ -79,6 +80,7 @@ void writeCard(nfcTagObject nfcTag);
void dump_byte_array(byte * buffer, byte bufferSize);
void adminMenu(bool fromCard = false);
bool knownCard = false;
void disableLoadTimer();

// implement a notification class,
// its member methods will get called
Expand Down Expand Up @@ -643,6 +645,7 @@ MFRC522::StatusCode status;
#define buttonDown A2
#define busyPin 4
#define shutdownPin 7
#define loadPin 6
#define openAnalogPin A7

#ifdef FIVEBUTTONS
Expand All @@ -652,6 +655,10 @@ MFRC522::StatusCode status;

#define LONG_PRESS 1000

// Set both to 0 to disable, set only LOAD_OFF to 0 for permanent ON
#define LOAD_ON 150
#define LOAD_OFF 4800

Button pauseButton(buttonPause);
Button upButton(buttonUp);
Button downButton(buttonDown);
Expand Down Expand Up @@ -688,6 +695,7 @@ void checkStandbyAtMillis() {
Serial.println(F("=== power off!"));
// enter sleep state
digitalWrite(shutdownPin, HIGH);
disableLoadTimer();
delay(500);

// http://discourse.voss.earth/t/intenso-s10000-powerbank-automatische-abschaltung-software-only/805
Expand All @@ -702,6 +710,36 @@ void checkStandbyAtMillis() {
}
}

void setLoadTimer() {
Serial.println(F("=== setLoadTimer()"));
if (LOAD_ON > 0 && LOAD_OFF > 0) {
toggleLoadAtMillis = millis() + LOAD_ON;
}
if (LOAD_ON > 0) {
digitalWrite(loadPin, HIGH);
}
Serial.println(toggleLoadAtMillis);
}

void disableLoadTimer() {
Serial.println(F("=== disableLoadTimer()"));
toggleLoadAtMillis = 0;
digitalWrite(loadPin, LOW);
}

void checkLoadTimer() {
if (toggleLoadAtMillis != 0 && millis() > toggleLoadAtMillis) {
if (digitalRead(loadPin) == HIGH) {
toggleLoadAtMillis = millis() + LOAD_OFF;
digitalWrite(loadPin, LOW);
}
else {
toggleLoadAtMillis = millis() + LOAD_ON;
digitalWrite(loadPin, HIGH);
}
}
}

bool isPlaying() {
return !digitalRead(busyPin);
}
Expand Down Expand Up @@ -778,6 +816,9 @@ void setup() {
pinMode(shutdownPin, OUTPUT);
digitalWrite(shutdownPin, LOW);

// Start load timer
pinMode(loadPin, OUTPUT);
setLoadTimer();

// RESET --- ALLE DREI KNÖPFE BEIM STARTEN GEDRÜCKT HALTEN -> alle EINSTELLUNGEN werden gelöscht
if (digitalRead(buttonPause) == LOW && digitalRead(buttonUp) == LOW &&
Expand Down Expand Up @@ -948,6 +989,7 @@ void playShortCut(uint8_t shortCut) {
void loop() {
do {
checkStandbyAtMillis();
checkLoadTimer();
mp3.loop();

// Modifier : WIP!
Expand Down