Skip to content

Commit

Permalink
Add build option for phone - not functional yet
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidSchinazi committed Aug 26, 2024
1 parent 66e29cb commit 4a46ba1
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 3 deletions.
37 changes: 34 additions & 3 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ build_flags =
'-UBOOT_NAME -DBOOT_NAME=DEBUG-S3'
-DCORE_DEBUG_LEVEL=5
-DARDUINO_USB_MODE=1
-DJL_DEBUG=1

# ATOM Matrix production clouds build.
[env:clouds]
Expand All @@ -246,7 +247,7 @@ build_flags =
'-UBOOT_NAME -DBOOT_NAME=CLOUDS-DEV'
-DJL_DEV=1

# ATOM Matrix production clouds build.
# ATOM S3 production clouds build.
[env:clouds_s3]
extends = env:_atom_s3
build_flags =
Expand All @@ -258,15 +259,15 @@ lib_deps =
# Normally we'd include this by adding "ESP Async WebServer" but that version fails to link due to missing SHA1 dependencies.
https://github.com/me-no-dev/ESPAsyncWebServer.git

# ATOM Matrix development clouds build.
# ATOM S3 development clouds build.
[env:clouds_s3_dev]
extends = env:clouds_s3
build_flags =
${env:clouds_s3.build_flags}
'-UBOOT_NAME -DBOOT_NAME=CLOUDS3-DEV'
-DJL_DEV=1

# ATOM Matrix development debug build.
# ATOM S3 development debug build.
[env:clouds_s3_debug]
extends = env:clouds_s3_dev
debug_tool = esp-builtin
Expand All @@ -277,6 +278,36 @@ build_flags =
'-UBOOT_NAME -DBOOT_NAME=CLOUDS3-DBG'
-DCORE_DEBUG_LEVEL=5
-DARDUINO_USB_MODE=1
-DJL_DEBUG=1

# ATOM Matrix production rotary phone build.
[env:phone]
extends = env:_atom_matrix
build_flags =
${env:_atom_matrix.build_flags}
-DJL_CONFIG=PHONE
-DBOOT_NAME=PHONE

# ATOM S3 production rotary phone build.
[env:phone_s3]
extends = env:_atom_s3
build_flags =
${env:_atom_s3.build_flags}
-DJL_CONFIG=PHONE
-DBOOT_NAME=PHONES3

# ATOM S3 development debug build.
[env:phone_s3_debug]
extends = env:phone_s3
debug_tool = esp-builtin
debug_speed = 12000
build_type = debug
build_flags =
${env:phone_s3.build_flags}
'-UBOOT_NAME -DBOOT_NAME=PHONES3-DBG'
-DCORE_DEBUG_LEVEL=5
-DARDUINO_USB_MODE=1
-DJL_DEBUG=1

# Core2AWS production build parameters. Will not build on its own.
[env:_core2aws]
Expand Down
5 changes: 5 additions & 0 deletions src/jazzlights/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define JL_CONFIG_FAIRY_WAND 7
#define JL_CONFIG_CLOUDS 8
#define JL_CONFIG_SHOE 9
#define JL_CONFIG_PHONE 10

#define JL_IS_CONFIG(config_) (JL_MERGE_TOKENS(JL_CONFIG_, JL_CONFIG) == JL_MERGE_TOKENS(JL_CONFIG_, config_))

Expand Down Expand Up @@ -56,6 +57,10 @@
#define JL_DEV 0
#endif // JL_DEV

#ifndef JL_DEBUG
#define JL_DEBUG 0
#endif // JL_DEBUG

#ifndef BOOT_NAME
#define BOOT_NAME X
#endif // BOOT_NAME
Expand Down
4 changes: 4 additions & 0 deletions src/jazzlights/layout_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ void AddLedsToRunner(FastLedRunner* runner) {

} // namespace jazzlights

#elif JL_IS_CONFIG(PHONE)
namespace jazzlights {
void AddLedsToRunner(FastLedRunner* runner) {}
} // namespace jazzlights
#endif
2 changes: 2 additions & 0 deletions src/jazzlights/layout_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "jazzlights/fastled_runner.h"

#if !JL_IS_CONFIG(PHONE)
#if JL_IS_CONTROLLER(CORE2AWS) || JL_IS_CONTROLLER(M5STAMP_PICO)
#define LED_PIN 32
#elif JL_IS_CONTROLLER(M5STAMP_C3U)
Expand All @@ -22,6 +23,7 @@
#else
#error "Unexpected controller"
#endif
#endif // PHONE

namespace jazzlights {

Expand Down
54 changes: 54 additions & 0 deletions src/jazzlights/primary_runloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,60 @@ static Esp32UiImpl* GetUi() {
return &ui;
}

#if JL_IS_CONFIG(PHONE)
class PhoneButtonHandler : public GpioButton::Interface {
public:
PhoneButtonHandler() = default;
~PhoneButtonHandler() = default;
void ShortPress(uint8_t pin, Milliseconds currentTime) override {}
void LongPress(uint8_t pin, Milliseconds currentTime) override {}
void HeldDown(uint8_t pin, Milliseconds currentTime) override {}
};
static PhoneButtonHandler* GetPhoneButtonHandler() {
static PhoneButtonHandler buttonHandler;
return &buttonHandler;
}
#if JL_IS_CONTROLLER(ATOM_MATRIX)
static constexpr uint8_t kPhonePin1 = 32;
static constexpr uint8_t kPhonePin2 = 26;
#elif JL_IS_CONTROLLER(ATOM_S3)
static constexpr uint8_t kPhonePin1 = 1;
static constexpr uint8_t kPhonePin2 = 2;
#else
#error "unsupported controller for phone"
#endif
static GpioButton* GetPhoneButton1() {
static GpioButton button(kPhonePin1, *GetPhoneButtonHandler(), timeMillis());
return &button;
}
static GpioButton* GetPhoneButton2() {
static GpioButton button(kPhonePin2, *GetPhoneButtonHandler(), timeMillis());
return &button;
}
#endif // PHONE

#if JL_WEBSOCKET_SERVER
WebSocketServer websocket_server(80, player);
#endif // JL_WEBSOCKET_SERVER

void SetupPrimaryRunLoop() {
#if JL_DEBUG
// Sometimes the UART monitor takes a couple seconds to connect when JTAG is involved.
// Sleep here to ensure we don't miss any logs.
for (size_t i = 0; i < 20; i++) {
if ((i % 10) == 0) { ets_printf("%02u ", i / 10); }
ets_printf(".");
if ((i % 10) == 9) { ets_printf("\n"); }
vTaskDelay(100 / portTICK_PERIOD_MS);
}
#endif // JL_DEBUG
Milliseconds currentTime = timeMillis();
GetUi()->set_fastled_runner(&runner);
GetUi()->InitialSetup(currentTime);
#if JL_IS_CONFIG(PHONE)
(void)GetPhoneButton1();
(void)GetPhoneButton2();
#endif // PHONE

AddLedsToRunner(&runner);

Expand Down Expand Up @@ -87,11 +133,19 @@ void RunPrimaryRunLoop() {
SAVE_TIME_POINT(PrimaryRunLoop, LoopStart);
Milliseconds currentTime = timeMillis();
GetUi()->RunLoop(currentTime);
#if JL_IS_CONFIG(PHONE)
GetPhoneButton1()->RunLoop(currentTime);
GetPhoneButton2()->RunLoop(currentTime);
#endif // PHONE
SAVE_TIME_POINT(PrimaryRunLoop, UserInterface);
Esp32BleNetwork::get()->runLoop(currentTime);
SAVE_TIME_POINT(PrimaryRunLoop, Bluetooth);

#if !JL_IS_CONFIG(PHONE)
const bool shouldRender = player.render(currentTime);
#else // PHONE
const bool shouldRender = true;
#endif // !PHONE
SAVE_TIME_POINT(PrimaryRunLoop, PlayerCompute);
if (shouldRender) { runner.Render(); }
#if JL_WEBSOCKET_SERVER
Expand Down

0 comments on commit 4a46ba1

Please sign in to comment.