Skip to content

Commit

Permalink
Merge pull request #17 from KaiNakamura/sleep-mode
Browse files Browse the repository at this point in the history
Add sleep mode
  • Loading branch information
KaiNakamura authored Apr 24, 2024
2 parents 3207aac + 6ef6307 commit d390326
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/Squidbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Squidbox::Squidbox() {
buttons[5] = new Button(PIN_BUTTON_5);
buttons[6] = new Button(PIN_BUTTON_6);
buttons[7] = new Button(PIN_BUTTON_7);

esp_sleep_enable_ext0_wakeup(static_cast<gpio_num_t>(PIN_BUTTON_0), 0);
}

void Squidbox::init() {
Expand Down Expand Up @@ -50,6 +52,12 @@ void Squidbox::switchTo(SceneType scene) {
}
}

void Squidbox::sleep() {
screen->clear();
screen->update();
esp_deep_sleep_start();
}

Screen *Squidbox::getScreen() { return screen; }

Joystick *Squidbox::getJoystick() { return joystick; }
Expand Down
1 change: 1 addition & 0 deletions src/Squidbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Squidbox {
void init();
void update();
void switchTo(SceneType scene);
void sleep();
Screen *getScreen();
Joystick *getJoystick();
Knob *getKnob();
Expand Down
1 change: 1 addition & 0 deletions src/components/button/Button.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "esp_sleep.h"
#include <Arduino.h>

class Button {
Expand Down
11 changes: 11 additions & 0 deletions src/gui/menu-item/quit/QuitMenuItem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "QuitMenuItem.h"

QuitMenuItem::QuitMenuItem(Squidbox *squidbox)
: MenuItem("Quit"), squidbox(squidbox) {
setOnSelectCallback(onSelect, this);
}

void QuitMenuItem::onSelect(void *arg) {
QuitMenuItem *self = static_cast<QuitMenuItem *>(arg);
self->squidbox->sleep();
}
13 changes: 13 additions & 0 deletions src/gui/menu-item/quit/QuitMenuItem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include "Squidbox.h"
#include "gui/menu-item/MenuItem.h"

class QuitMenuItem : public MenuItem {
private:
Squidbox *squidbox;
static void onSelect(void *arg);

public:
QuitMenuItem(Squidbox *squidbox);
};
6 changes: 4 additions & 2 deletions src/scene/main/MainScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ MainScene::MainScene(Squidbox *squidbox) : Scene(squidbox, nullptr) {
new SwitchSceneMenuItem("Notes", squidbox, NOTE_SCENE);
MenuItem *drumMenuItem =
new SwitchSceneMenuItem("Drums", squidbox, DRUM_SCENE);
MenuItem *quitMenuItem = new QuitMenuItem(squidbox);

MenuItem **menuItems = new MenuItem *[3];
MenuItem **menuItems = new MenuItem *[4];
menuItems[0] = chordMenuItem;
menuItems[1] = noteMenuItem;
menuItems[2] = drumMenuItem;
menuItems[3] = quitMenuItem;

menu = new Menu("Squidbox", 3, menuItems);
menu = new Menu("Squidbox", 4, menuItems);
}

void MainScene::init() { Scene::init(); }
Expand Down
2 changes: 1 addition & 1 deletion src/scene/main/MainScene.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#pragma once

#include "gui/menu-item/quit/QuitMenuItem.h"
#include "gui/menu-item/switch-scene/SwitchSceneMenuItem.h"
#include "gui/menu/Menu.h"
#include "scene/Scene.h"
#include "util/Ascii.h"


class MainScene : public Scene {
public:
MainScene(Squidbox *squidbox);
Expand Down

0 comments on commit d390326

Please sign in to comment.