diff --git a/LICENSE b/LICENSE index eff10bd..5336070 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2024 Kai Nakamura +Copyright (c) 2024 EAMIR Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 0ee1f71..40c8256 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,63 @@ # Squidbox -Squidbox is a low-cost Bluetooth MIDI controller. It provides an intuitive and interactive way to learn about scales and chords while having fun making music. It runs on an ESP32 and features a 2-axis joystick, a small OLED screen, a knob, and multiple buttons. +The EAMIR Squidbox is a low-cost Bluetooth MIDI controller. It provides an intuitive and interactive way to learn about scales and chords while having fun making music. It runs on an ESP32 and features a 2-axis joystick, a small OLED screen, a knob, and multiple buttons. + +## Python + PlatformIO setup (macOS) + +In Terminal on MacOS: +- Verify Python 3 is available by running: `python3 --version` + - If not installed, install from `https://www.python.org/downloads/` (or through Homebrew: `brew install python`) +- Install PlatformIO via pip (preferred): `python3 -m pip install --user platformio` (or `pip3 install --user platformio`) (or through Homebrew: `brew install platformio`) +- Confirm install: `python3 -m platformio --version` +- If `platformio`/`pio` is not found, add your Python user bin to PATH: + - Find the user base: `python3 -m site --user-base` (expect something like `/Users//Library/Python/3.xx`) + - Add run: `echo 'export PATH="/Users//Library/Python/3.xx/bin:$PATH"' >> ~/.zshrc && source ~/.zshrc` + +In VSCode: +- Restart VSCode +- Open the Terminal and test by running: `platformio --version` (or `pio --version`),`which platformio` (or `which pio`) +- If it still cannot find `pio`, set the same PATH in VS Code settings (`terminal.integrated.env.osx`) or select the `python3` interpreter in the Command Palette by Opening VS Code settings (Command Palette → “Preferences: Open User Settings (JSON)”). Add or update this: "terminal.integrated.env.osx": { + "PATH": "/Users//Library/Python/3.xx/bin:${env:PATH}" +} + (replace with your actual user bin path from python3 -m site --user-base): + + +## Flashing Quickstart (PlatformIO CLI) + +Assumes you have the board connected (USB) and PlatformIO CLI installed (`pip install platformio` and make sure `pio` is on your PATH). + +Replace `/dev/cu.usbserial-XXXX` with your serial port (check with `pio device list`). + +Copying and entering this two-line command below should get the firmware built and pushed to the Squidbox: + +# Build + upload main firmware +pio run -e adafruit_feather_esp32_v2 -t upload --upload-port /dev/cu.usbserial-59690893931 + +# Upload the LittleFS data (presets in data/config.json) +pio run -e adafruit_feather_esp32_v2 -t uploadfs --upload-port /dev/cu.usbserial-59690893931 + + +Here are the general commands we use: + +- Build + upload Squidbox firmware (Feather ESP32 V2 target): + `pio run -e adafruit_feather_esp32_v2 -t upload --upload-port /dev/cu.usbserial-XXXX` +- Upload LittleFS data (presets in `data/`): + `pio run -e adafruit_feather_esp32_v2 -t uploadfs --upload-port /dev/cu.usbserial-XXXX` +- Serial monitor at project baud: + `pio device monitor -b 115200 --port /dev/cu.usbserial-XXXX --echo` +- If you are using the DevKit simulation target instead: + `pio run -e esp32dev -t buildfs -t upload --upload-port /dev/cu.usbserial-XXXX` + +If upload hangs on “Connecting…”, hold BOOT during that phase and release after the dots start. Press EN/reset to reboot after flashing. + + +## Related + +- The Squidbox Configuration Editor is available at https://eamirorg.github.io/Squidbox-web-editor/ + +- The Squidbox Configuration Editor source is available at https://github.com/EAMIRorg/Squidbox-web-editor + + ## Contributing diff --git a/scripts/merge_firmware.py b/scripts/merge_firmware.py index aca85aa..f4a3047 100644 --- a/scripts/merge_firmware.py +++ b/scripts/merge_firmware.py @@ -39,8 +39,23 @@ def merge_bin(source, target, env): # Add a post action that runs esptoolpy to merge available flash images env.AddPostAction(APP_BIN, merge_bin) +# Also ensure the merged binary exists before upload even if the program binary +# wasn't rebuilt in this invocation (e.g., when only uploading an unchanged build). +env.AddPreAction("upload", merge_bin) + # Patch the upload command to flash the merged binary at address 0x0 -env.Replace( - UPLOADERFLAGS=[] + ["0x0", MERGED_BIN], - UPLOADCMD='"$PYTHONEXE" "$UPLOADER" $UPLOADERFLAGS', +# Keep PlatformIO's default uploader flags (chip/port/baud/reset/write_flash options), +# but replace the individual address/file pairs with our single merged image. +original_upload_flags = list(env.get("UPLOADERFLAGS", [])) +first_addr_idx = next( + (i for i, flag in enumerate(original_upload_flags) if str(flag).startswith("0x")), + None, ) + +if first_addr_idx is None: + # Unexpected shape; fall back to appending. + new_upload_flags = original_upload_flags + ["0x0", MERGED_BIN] +else: + new_upload_flags = original_upload_flags[:first_addr_idx] + ["0x0", MERGED_BIN] + +env.Replace(UPLOADERFLAGS=new_upload_flags, UPLOADCMD='"$PYTHONEXE" "$UPLOADER" $UPLOADERFLAGS') diff --git a/src/components/joystick/Joystick.cpp b/src/components/joystick/Joystick.cpp index 90dc9d3..52531c4 100644 --- a/src/components/joystick/Joystick.cpp +++ b/src/components/joystick/Joystick.cpp @@ -56,7 +56,12 @@ float Joystick::getX() { float Joystick::getY() { // Convert the raw Y value to a value in the range -1 to 1 and return it. + // Invert on hardware so pushing the stick up yields positive (UP) values. +#ifdef SIMULATION return convertRawValue(getRawY(), Y_CENTER, Y_MIN, Y_MAX); +#else + return -convertRawValue(getRawY(), Y_CENTER, Y_MIN, Y_MAX); +#endif } bool Joystick::isPressed() { @@ -142,4 +147,4 @@ bool Joystick::wasDownJustInputted() { wasDown = downInputted; // Return whether the joystick was just moved down. return downJustInputted; -} \ No newline at end of file +}