Initial commit.
This commit is contained in:
46
src/buttons.cpp
Normal file
46
src/buttons.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include <Arduino.h>
|
||||
#include "buttons.h"
|
||||
#include "config.h"
|
||||
|
||||
void Buttons::setup() {
|
||||
pinMode(PIN_BTN_VOL_UP, INPUT);
|
||||
pinMode(PIN_BTN_VOL_DOWN, INPUT);
|
||||
pinMode(PIN_BTN_TRACK_NEXT, INPUT);
|
||||
pinMode(PIN_BTN_TRACK_PREV, INPUT);
|
||||
}
|
||||
|
||||
void Buttons::_debounce() {
|
||||
unsigned long now = millis();
|
||||
_debounce_until = now + DEBOUNCE_MILLIS;
|
||||
if (_debounce_until < now) _debounce_until = now;
|
||||
}
|
||||
|
||||
void Buttons::loop() {
|
||||
bool vol_up = digitalRead(PIN_BTN_VOL_UP);
|
||||
bool vol_down = digitalRead(PIN_BTN_VOL_DOWN);
|
||||
bool track_next = digitalRead(PIN_BTN_TRACK_NEXT);
|
||||
bool track_prev = digitalRead(PIN_BTN_TRACK_PREV);
|
||||
|
||||
if (_debounce_until > millis()) {
|
||||
if (vol_up || vol_down || track_next || track_prev) {
|
||||
_debounce();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (vol_up) {
|
||||
_controller->vol_up();
|
||||
} else if (vol_down) {
|
||||
_controller->vol_down();
|
||||
} else if (track_next) {
|
||||
_controller->track_next();
|
||||
} else if (track_prev) {
|
||||
_controller->track_prev();
|
||||
} else {
|
||||
// If we reach this, no button was pressed and we are not debouncing -> do nothing.
|
||||
return;
|
||||
}
|
||||
|
||||
// If we reach this, some button was pressed. So enable debouncing.
|
||||
_debounce();
|
||||
}
|
17
src/controller.cpp
Normal file
17
src/controller.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include "controller.h"
|
||||
|
||||
void Controller::vol_up() {
|
||||
_player->vol_up();
|
||||
}
|
||||
|
||||
void Controller::vol_down() {
|
||||
_player->vol_down();
|
||||
}
|
||||
|
||||
void Controller::track_next() {
|
||||
_player->track_next();
|
||||
}
|
||||
|
||||
void Controller::track_prev() {
|
||||
_player->track_prev();
|
||||
}
|
19
src/main.cpp
Normal file
19
src/main.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#include <Arduino.h>
|
||||
#include "config.h"
|
||||
#include "buttons.h"
|
||||
#include "controller.h"
|
||||
#include "player.h"
|
||||
|
||||
Buttons* buttons;
|
||||
Controller* controller;
|
||||
Player* player;
|
||||
|
||||
void setup() {
|
||||
player = new Player();
|
||||
controller = new Controller(player);
|
||||
buttons = new Buttons(controller);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
Reference in New Issue
Block a user