├── README.md ├── misc ├── lolin_s3_pinout.jpeg ├── TODO.txt ├── device-initialize.txt ├── c1101-sample.txt ├── pitches.h └── willy.ino.bak ├── .vscode ├── settings.json ├── extensions.json └── arduino.json ├── include ├── core │ ├── gui │ │ ├── menu.cpp │ │ ├── screen.h │ │ └── menu.h │ ├── hardware │ │ ├── sdcard.h │ │ ├── joystick_state.h │ │ ├── transceiver_24.h │ │ ├── display.h │ │ ├── joystick.h │ │ ├── buzzer.h │ │ ├── irda.h │ │ ├── transceiver_433.h │ │ ├── pinout.h │ │ └── device.h │ └── application │ │ ├── application.h │ │ └── manager.h └── apps │ ├── mainmenu.h │ └── homescreen.h ├── .gitignore ├── src ├── core │ ├── hardware │ │ ├── joystick_state.cpp │ │ ├── buzzer.cpp │ │ ├── irda.cpp │ │ ├── transceiver_24.cpp │ │ ├── joystick.cpp │ │ ├── display.cpp │ │ ├── transceiver_433.cpp │ │ ├── sdcard.cpp │ │ └── device.cpp │ └── application │ │ ├── application.cpp │ │ └── manager.cpp ├── apps │ ├── mainmenu.cpp │ └── homescreen.cpp └── main.cpp ├── test └── README ├── platformio.ini ├── lib └── README └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # willy 2 | Flipper Zero alternative built for ESP32-S3 3 | -------------------------------------------------------------------------------- /misc/lolin_s3_pinout.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtojek/willy/HEAD/misc/lolin_s3_pinout.jpeg -------------------------------------------------------------------------------- /misc/TODO.txt: -------------------------------------------------------------------------------- 1 | * Re-arrange pins to order modules 2 | * New module: irda (transmitter, receiver) 3 | * New module: buzzer -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cmake.configureOnOpen": true, 3 | "files.associations": { 4 | "system_error": "cpp" 5 | } 6 | } -------------------------------------------------------------------------------- /include/core/gui/menu.cpp: -------------------------------------------------------------------------------- 1 | #include "menu.h" 2 | 3 | void ListMenu::draw() {} 4 | 5 | void ListMenu::go() {} 6 | 7 | void TabMenu::draw() {} 8 | 9 | void TabMenu::go() {} -------------------------------------------------------------------------------- /include/core/gui/screen.h: -------------------------------------------------------------------------------- 1 | class Screen { 2 | public: 3 | virtual void draw() = 0; 4 | }; 5 | 6 | class ActionScreen : Screen { 7 | public: 8 | virtual void draw() = 0; 9 | virtual void go() = 0; 10 | }; -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .pioenvs 2 | .piolibdeps 3 | .clang_complete 4 | .gcc-flags.json 5 | .pio 6 | 7 | .vscode/.browse.c_cpp.db* 8 | .vscode/c_cpp_properties.json 9 | .vscode/launch.json 10 | .vscode/ipch 11 | 12 | ./0 # zero file? 13 | -------------------------------------------------------------------------------- /include/core/hardware/sdcard.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "esp32-hal-log.h" 4 | 5 | #include 6 | 7 | class SDCard { 8 | private: 9 | int csPin; 10 | 11 | public: 12 | SDCard(int csPin); 13 | 14 | bool initialize(); 15 | }; -------------------------------------------------------------------------------- /include/core/hardware/joystick_state.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class JoystickState { 4 | private: 5 | int vrx, vry; 6 | bool sw; 7 | 8 | public: 9 | JoystickState(int vrx, int vry, bool sw); 10 | 11 | int getVRx(); 12 | int getVRy(); 13 | bool getSW(); 14 | }; -------------------------------------------------------------------------------- /include/core/hardware/transceiver_24.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "esp32-hal-log.h" 4 | 5 | #include 6 | 7 | class Transceiver24 { 8 | private: 9 | RF24 rf; 10 | 11 | public: 12 | Transceiver24(int cePin, int csnPin); 13 | 14 | bool initialize(); 15 | RF24 *getDriver(); 16 | }; -------------------------------------------------------------------------------- /misc/device-initialize.txt: -------------------------------------------------------------------------------- 1 | if (!transceiver24.initialize()) { 2 | ESP_LOGE(TAG, "Initialization of transceiver 2.4Ghz failed"); 3 | return false; 4 | } 5 | if (!transceiver433.initialize()) { 6 | ESP_LOGE(TAG, "Initialization of transceiver 433Mhz failed"); 7 | return false; 8 | } 9 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "platformio.platformio-ide" 6 | ], 7 | "unwantedRecommendations": [ 8 | "ms-vscode.cpptools-extension-pack" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /include/core/gui/menu.h: -------------------------------------------------------------------------------- 1 | #include "screen.h" 2 | 3 | class Menu : ActionScreen { 4 | public: 5 | virtual void draw() = 0; 6 | virtual void go() = 0; 7 | }; 8 | 9 | class ListMenu : Menu { 10 | public: 11 | void draw(); 12 | void go(); 13 | }; 14 | 15 | class TabMenu : Menu { 16 | public: 17 | void draw(); 18 | void go(); 19 | }; -------------------------------------------------------------------------------- /src/core/hardware/joystick_state.cpp: -------------------------------------------------------------------------------- 1 | #include "core/hardware/joystick_state.h" 2 | 3 | JoystickState::JoystickState(int vrx, int vry, bool sw) 4 | : vrx(vrx), vry(vry), sw(sw) {} 5 | 6 | int JoystickState::getVRx() { return vrx; } 7 | 8 | int JoystickState::getVRy() { return vry; } 9 | 10 | bool JoystickState::getSW() { return sw; } -------------------------------------------------------------------------------- /include/apps/mainmenu.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../core/application/application.h" 6 | #include "../core/hardware/device.h" 7 | 8 | class MainMenu : public Application { 9 | private: 10 | Device &device; 11 | 12 | public: 13 | MainMenu(Device &device); 14 | 15 | void onStart(); 16 | void onUpdate(); 17 | }; -------------------------------------------------------------------------------- /include/core/hardware/display.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class Display { 6 | private: 7 | int contrast; 8 | int bias; 9 | Adafruit_PCD8544 display; 10 | 11 | public: 12 | Display(int dcPin, int csPin, int rstPin, int contrast, int bias); 13 | 14 | bool initialize(); 15 | Adafruit_PCD8544 *getDriver(); 16 | }; -------------------------------------------------------------------------------- /.vscode/arduino.json: -------------------------------------------------------------------------------- 1 | { 2 | "configuration": "FlashMode=qio,LoopCore=1,EventsCore=1,USBMode=hwcdc,CDCOnBoot=default,MSCOnBoot=default,DFUOnBoot=default,UploadMode=default,PartitionScheme=fatflash,CPUFreq=240,UploadSpeed=921600,DebugLevel=none,EraseFlash=none", 3 | "board": "esp32:esp32:lolin_s3", 4 | "programmer": "esptool", 5 | "port": "/dev/tty.usbserial-110" 6 | } -------------------------------------------------------------------------------- /include/core/hardware/joystick.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "joystick_state.h" 6 | 7 | class Joystick { 8 | private: 9 | int vrxPin, vryPin; 10 | ezButton sw; 11 | 12 | JoystickState state; 13 | 14 | public: 15 | Joystick(int vrxPin, int vryPin, int swPin); 16 | 17 | void sync(); 18 | JoystickState *getState(); 19 | }; -------------------------------------------------------------------------------- /include/apps/homescreen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../core/application/application.h" 6 | #include "../core/hardware/device.h" 7 | 8 | class HomeScreen : public Application { 9 | private: 10 | Device &device; 11 | 12 | bool rendered; 13 | 14 | public: 15 | HomeScreen(Device &device); 16 | 17 | void onStart(); 18 | void onUpdate(); 19 | void onRender(); 20 | }; -------------------------------------------------------------------------------- /src/core/hardware/buzzer.cpp: -------------------------------------------------------------------------------- 1 | #include "core/hardware/buzzer.h" 2 | 3 | const char *BUZZER_TAG = "buzzer"; 4 | 5 | Buzzer::Buzzer(int buzzerPin) : buzzer(ezBuzzer(buzzerPin)) { 6 | ledcSetup(BUZZER_CHANNEL, BUZZER_FREQUENCY, BUZZER_RESOLUTION); 7 | ledcAttachPin(buzzerPin, BUZZER_CHANNEL); 8 | } 9 | 10 | ezBuzzer *Buzzer ::getDriver() { return &buzzer; } 11 | 12 | void Buzzer::sync() { buzzer.loop(); } -------------------------------------------------------------------------------- /src/core/hardware/irda.cpp: -------------------------------------------------------------------------------- 1 | #include "core/hardware/irda.h" 2 | 3 | const char *IRDA_TAG = "irda"; 4 | 5 | IrDA::IrDA(int receiverPin, int senderPin) 6 | : irrecv(IRrecv(receiverPin)), irsend(IRsend(senderPin)) {} 7 | 8 | void IrDA::initialize() { 9 | irrecv.enableIRIn(); 10 | irsend.begin(); 11 | } 12 | 13 | IRrecv *IrDA ::getReceiverDriver() { return &irrecv; } 14 | 15 | IRsend *IrDA ::getSenderDriver() { return &irsend; } -------------------------------------------------------------------------------- /include/core/hardware/buzzer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "esp32-hal-ledc.h" 4 | #include "esp32-hal-log.h" 5 | 6 | #include 7 | 8 | #define BUZZER_FREQUENCY 2000 9 | #define BUZZER_CHANNEL 0 10 | #define BUZZER_RESOLUTION 8 11 | 12 | class Buzzer { 13 | private: 14 | ezBuzzer buzzer; 15 | 16 | public: 17 | Buzzer(int buzzerPin); 18 | 19 | void initialize(); 20 | void sync(); 21 | 22 | ezBuzzer *getDriver(); 23 | }; -------------------------------------------------------------------------------- /src/core/application/application.cpp: -------------------------------------------------------------------------------- 1 | #include "application.h" 2 | 3 | Application::Application(const char *name) : name(name) {} 4 | 5 | void Application::onInstall(ApplicationManager *am) { appManager = am; } 6 | 7 | void Application::onStart() { ESP_LOGD(name, "onStart() is not implemented"); } 8 | 9 | void Application::onRender() { 10 | // ESP_LOGI(name, "onRender() is not implemented"); 11 | } 12 | 13 | const char *Application::getName() { return name; } -------------------------------------------------------------------------------- /include/core/application/application.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "manager.h" 4 | 5 | class ApplicationManager; 6 | 7 | class Application { 8 | protected: 9 | const char *name; 10 | ApplicationManager *appManager; 11 | 12 | Application(const char *name); 13 | 14 | public: 15 | void onInstall(ApplicationManager *am); 16 | 17 | virtual void onStart(); 18 | virtual void onUpdate() = 0; 19 | virtual void onRender(); 20 | 21 | const char *getName(); 22 | }; -------------------------------------------------------------------------------- /src/apps/mainmenu.cpp: -------------------------------------------------------------------------------- 1 | #include "apps/mainmenu.h" 2 | 3 | MainMenu::MainMenu(Device &device) : Application("main_menu"), device(device) {} 4 | 5 | void MainMenu::onStart() { 6 | ESP_LOGD(name, "MainMenu::onStart"); 7 | 8 | Display *display = device.getDisplay(); 9 | Adafruit_PCD8544 *d = display->getDriver(); 10 | 11 | d->clearDisplay(); 12 | d->display(); 13 | } 14 | 15 | void MainMenu::onUpdate() { 16 | if (!appManager->isDisplayed(getName())) { 17 | return; 18 | } 19 | } -------------------------------------------------------------------------------- /include/core/hardware/irda.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "esp32-hal-log.h" 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #define BUZZER_FREQUENCY 2000 11 | #define BUZZER_CHANNEL 0 12 | #define BUZZER_RESOLUTION 8 13 | 14 | class IrDA { 15 | private: 16 | IRrecv irrecv; 17 | IRsend irsend; 18 | 19 | public: 20 | IrDA(int receiverPin, int senderPin); 21 | 22 | void initialize(); 23 | 24 | IRrecv *getReceiverDriver(); 25 | IRsend *getSenderDriver(); 26 | }; -------------------------------------------------------------------------------- /src/core/hardware/transceiver_24.cpp: -------------------------------------------------------------------------------- 1 | #include "core/hardware/transceiver_24.h" 2 | 3 | const char *TRANSCEIVER_24_TAG = "transceiver_24"; 4 | 5 | Transceiver24::Transceiver24(int cePin, int csnPin) : rf(RF24(cePin, csnPin)) {} 6 | 7 | bool Transceiver24::initialize() { 8 | if (!rf.begin()) { 9 | ESP_LOGE(TRANSCEIVER_24_TAG, "Radio hardware is not responding."); 10 | return false; 11 | } 12 | 13 | rf.setPALevel(RF24_PA_HIGH); 14 | // rf.printDetails(); 15 | return true; 16 | } 17 | 18 | RF24 *Transceiver24 ::getDriver() { return &rf; } -------------------------------------------------------------------------------- /test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PlatformIO Test Runner and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PlatformIO Unit Testing: 11 | - https://docs.platformio.org/en/latest/advanced/unit-testing/index.html 12 | -------------------------------------------------------------------------------- /include/core/application/manager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "application.h" 6 | 7 | class Application; 8 | 9 | const int RUNNING_APPS_COUNT_MAX = 10; 10 | typedef Array Apps; 11 | 12 | class ApplicationManager { 13 | private: 14 | Apps installed; 15 | Apps running; 16 | 17 | public: 18 | void install(Application &app); 19 | void start(const char *name); 20 | void stop(const char *name); 21 | boolean isDisplayed(const char *name); 22 | 23 | void onUpdate(); 24 | void onRender(); 25 | }; -------------------------------------------------------------------------------- /src/core/hardware/joystick.cpp: -------------------------------------------------------------------------------- 1 | #include "core/hardware/joystick.h" 2 | 3 | Joystick::Joystick(int vrxPin, int vryPin, int swPin) 4 | : vrxPin(vrxPin), vryPin(vryPin), sw(ezButton(swPin)), 5 | state(JoystickState(0, 0, false)) { 6 | sw.setDebounceTime(50); 7 | } 8 | 9 | void Joystick::sync() { 10 | sw.loop(); 11 | 12 | const int vrx = analogRead(vrxPin); 13 | const int vry = analogRead(vryPin); 14 | JoystickState newState(vrx, vry, sw.isPressed()); 15 | 16 | // free(&state); 17 | state = newState; 18 | } 19 | 20 | JoystickState *Joystick::getState() { return &state; } -------------------------------------------------------------------------------- /include/core/hardware/transceiver_433.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "esp32-hal-log.h" 4 | 5 | #include "pinout.h" 6 | 7 | #include 8 | 9 | class Transceiver433 { 10 | private: 11 | int csPin; 12 | int gdo0Pin; 13 | int gdo1Pin; 14 | int gdo2Pin; 15 | 16 | int sckPin; 17 | int mosiPin; 18 | 19 | CC1101 radio; 20 | 21 | public: 22 | Transceiver433(int csPin, int gdo0Pin, int gdo2Pin, 23 | int gdo1Pin = SPI_MISO_PIN, int sckPin = SPI_SCK_PIN, 24 | int mosiPin = SPI_MOSI_PIN); 25 | 26 | bool initialize(); 27 | CC1101 *getDriver(); 28 | }; -------------------------------------------------------------------------------- /src/core/hardware/display.cpp: -------------------------------------------------------------------------------- 1 | #include "core/hardware/display.h" 2 | 3 | const char *DISPLAY_TAG = "display"; 4 | 5 | Display::Display(int dcPin, int csPin, int rstPin, int contrast, int bias) 6 | : contrast(contrast), bias(bias), 7 | display(Adafruit_PCD8544(dcPin, csPin, rstPin)) {} 8 | 9 | bool Display::initialize() { 10 | if (!display.begin()) { 11 | ESP_LOGE(DISPLAY_TAG, "display.begin() failed"); 12 | return false; 13 | } 14 | 15 | display.setRotation(2); 16 | display.setContrast(contrast); 17 | display.setBias(bias); 18 | display.clearDisplay(); 19 | display.display(); 20 | return true; 21 | } 22 | 23 | Adafruit_PCD8544 *Display::getDriver() { return &display; } -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "esp32-hal-log.h" 2 | 3 | #include "core/application/manager.h" 4 | 5 | #include "apps/homescreen.h" 6 | #include "apps/mainmenu.h" 7 | 8 | #define TAG "main" 9 | 10 | Device willy; 11 | ApplicationManager appManager; 12 | 13 | HomeScreen homeScreen(willy); 14 | MainMenu mainMenu(willy); 15 | 16 | void setup() { 17 | if (!willy.initialize()) { 18 | ESP_LOGE(TAG, "Willy initialization failed"); 19 | exit(0); 20 | } 21 | ESP_LOGI(TAG, "Initialization done"); 22 | 23 | appManager.install(homeScreen); 24 | appManager.install(mainMenu); 25 | 26 | appManager.start(homeScreen.getName()); 27 | } 28 | 29 | void loop() { 30 | willy.sync(); 31 | 32 | appManager.onUpdate(); 33 | appManager.onRender(); 34 | } -------------------------------------------------------------------------------- /src/core/hardware/transceiver_433.cpp: -------------------------------------------------------------------------------- 1 | #include "core/hardware/transceiver_433.h" 2 | 3 | const char *TRANSCEIVER_433_TAG = "transceiver_433"; 4 | 5 | Transceiver433::Transceiver433(int csPin, int gdo0Pin, int gdo2Pin, int gdo1Pin, 6 | int sckPin, int mosiPin) 7 | : csPin(csPin), gdo0Pin(gdo0Pin), gdo2Pin(gdo2Pin), gdo1Pin(gdo1Pin), 8 | sckPin(sckPin), mosiPin(mosiPin), 9 | radio(CC1101(sckPin, gdo1Pin, mosiPin, csPin, gdo0Pin, gdo2Pin)) {} 10 | 11 | bool Transceiver433::initialize() { 12 | radio.init(); 13 | ESP_LOGI(TRANSCEIVER_433_TAG, "CC1101: 0x%02x, version: 0x%02x", 14 | radio.getPartnum(), radio.getVersion()); 15 | return true; 16 | } 17 | 18 | CC1101 *Transceiver433::getDriver() { return &radio; } -------------------------------------------------------------------------------- /include/core/hardware/pinout.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // LOLIN S3 4 | // 5 | #define SPI_SS_PIN 10 6 | #define SPI_MOSI_PIN 11 7 | #define SPI_SCK_PIN 12 8 | #define SPI_MISO_PIN 13 9 | 10 | #define PCD8544_DC_PIN 21 11 | #define PCD8544_CS_PIN 9 12 | #define PCD8544_RST_PIN 14 13 | #define PCD8544_BIAS 4 14 | #define PCD8544_CONTRAST 55 15 | 16 | #define LED_PIN LED_BUILTIN 17 | #define LED_BRIGHTNESS 10 18 | 19 | #define JOYSTICK1_VRX_PIN 1 20 | #define JOYSTICK1_VRY_PIN 2 21 | #define JOYSTICK1_SW_PIN 40 22 | 23 | #define JOYSTICK2_VRX_PIN 4 24 | #define JOYSTICK2_VRY_PIN 5 25 | #define JOYSTICK2_SW_PIN 39 26 | 27 | #define TRANSCEIVER_24_CE_PIN 46 28 | #define TRANSCEIVER_24_CSN_PIN 3 29 | #define TRANSCEIVER_24_IRQ_PIN 8 30 | 31 | #define TRANSCEIVER_433_CSN_PIN 15 32 | #define TRANSCEIVER_433_GDO0_PIN 16 33 | #define TRANSCEIVER_433_GDO1_PIN SPI_MISO_PIN // MISO 34 | #define TRANSCEIVER_433_GDO2_PIN 17 // IRQ 35 | 36 | #define BUZZER_PIN 45 37 | 38 | #define IRDA_RECEIVER_PIN 3 39 | #define IRDA_SENDER_PIN 8 -------------------------------------------------------------------------------- /src/core/hardware/sdcard.cpp: -------------------------------------------------------------------------------- 1 | #include "core/hardware/sdcard.h" 2 | 3 | const char *SDCARD_TAG = "sdcard"; 4 | 5 | SDCard::SDCard(int csPin) : csPin(csPin) {} 6 | 7 | bool SDCard::initialize() { 8 | pinMode(csPin, OUTPUT); 9 | if (!SD.begin(csPin)) { 10 | ESP_LOGE(SDCARD_TAG, "SD card failed initialization."); 11 | return false; 12 | } 13 | 14 | uint8_t cardType = SD.cardType(); 15 | 16 | if (cardType == CARD_NONE) { 17 | ESP_LOGE(SDCARD_TAG, "SD card is not attached."); 18 | return false; 19 | } 20 | 21 | if (cardType == CARD_MMC) { 22 | ESP_LOGI(SDCARD_TAG, "SD card type: MMC"); 23 | } else if (cardType == CARD_SD) { 24 | ESP_LOGI(SDCARD_TAG, "SD card type: SDSC"); 25 | } else if (cardType == CARD_SDHC) { 26 | ESP_LOGI(SDCARD_TAG, "SD card type: SDHC"); 27 | } else { 28 | ESP_LOGI(SDCARD_TAG, "SD card type: UNKNOWN"); 29 | } 30 | 31 | uint64_t cardSize = SD.cardSize() / (1024 * 1024); 32 | ESP_LOGI(SDCARD_TAG, "SD card size: %lluMB", cardSize); 33 | 34 | return true; 35 | } -------------------------------------------------------------------------------- /include/core/hardware/device.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "esp32-hal-log.h" 4 | #include 5 | 6 | #include "pinout.h" 7 | 8 | #include "buzzer.h" 9 | #include "display.h" 10 | #include "irda.h" 11 | #include "joystick.h" 12 | #include "sdcard.h" 13 | #include "transceiver_24.h" 14 | #include "transceiver_433.h" 15 | 16 | #include 17 | #include 18 | 19 | #include 20 | #include 21 | 22 | class Device { 23 | private: 24 | Display display; 25 | Adafruit_NeoPixel led; 26 | Joystick joystick; 27 | Transceiver24 transceiver24; 28 | Transceiver433 transceiver433; 29 | Buzzer buzzer; 30 | SDCard sdCard; 31 | IrDA irDA; 32 | 33 | static void printHardwareInfo(); 34 | void boot(); 35 | 36 | public: 37 | Device(); 38 | bool initialize(); 39 | void sync(); 40 | 41 | Display *getDisplay(); 42 | Joystick *getJoystick(); 43 | Transceiver24 *getTransceiver24(); 44 | Transceiver433 *getTransceiver433(); 45 | Buzzer *getBuzzer(); 46 | SDCard *getSDCard(); 47 | IrDA *getIrDA(); 48 | }; -------------------------------------------------------------------------------- /misc/c1101-sample.txt: -------------------------------------------------------------------------------- 1 | CC1101 *radio = transceiver433.getDriver(); 2 | radio->setMHZ(433.92); 3 | radio->setTXPwr(TX_0_DBM); 4 | radio->setRxBW(RX_BW_58_KHZ); 5 | radio->setDataRate(10000); 6 | radio->setModulation(ASK_OOK); 7 | radio->setRx(); 8 | 9 | int interruptPin = digitalPinToInterrupt(TRANSCEIVER_433_GDO2_PIN); 10 | attachInterrupt(interruptPin, radioHandlerOnChange, CHANGE); 11 | 12 | while (true) { 13 | if (millis() > (last_millis + 5000)) { 14 | radio->setIdle(); 15 | 16 | Serial.printf("Received: %d\n", t); 17 | for (int i = 0; i < t; i++) { 18 | Serial.print(timings[i]); 19 | Serial.print(", "); 20 | } 21 | Serial.println(); 22 | 23 | t = 0; 24 | radio->setRx(); 25 | 26 | last_millis = millis(); 27 | } 28 | } 29 | 30 | 31 | 32 | volatile long last_micros; 33 | volatile long last_millis; 34 | 35 | int timings[1024] = {0}; 36 | int t = 0; 37 | 38 | void radioHandlerOnChange() { 39 | int now = micros(); 40 | int delta_micros = now - last_micros; 41 | timings[t++] = delta_micros; 42 | last_micros = now; 43 | } -------------------------------------------------------------------------------- /platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [env:lolin_s3] 12 | platform = espressif32 13 | board = lolin_s3 14 | framework = arduino 15 | monitor_speed = 115200 16 | build_flags = 17 | -D CORE_DEBUG_LEVEL=5 18 | -D ARDUINO_USB_MODE=1 19 | -D ARDUINO_USB_CDC_ON_BOOT=0 20 | -I include/apps 21 | -I include/core/application 22 | -I include/core/hardware 23 | -I src/apps 24 | -I src/core/application 25 | -I src/core/hardware 26 | 27 | lib_deps = 28 | adafruit/Adafruit PCD8544 Nokia 5110 LCD library@^2.0.1 29 | adafruit/Adafruit NeoPixel@^1.11.0 30 | janelia-arduino/Array@^1.2.1 31 | arduinogetstarted/ezButton@^1.0.4 32 | nrf24/RF24@^1.4.7 33 | https://github.com/mtojek/CC1101-ESP-Arduino.git 34 | arduinogetstarted/ezBuzzer@^1.0.0 35 | crankyoldgit/IRremoteESP8266@^2.8.6 -------------------------------------------------------------------------------- /lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in a an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /src/apps/homescreen.cpp: -------------------------------------------------------------------------------- 1 | #include "apps/homescreen.h" 2 | 3 | HomeScreen::HomeScreen(Device &device) 4 | : Application("home_screen"), device(device) {} 5 | 6 | void HomeScreen::onStart() { 7 | ESP_LOGD(name, "HomeScreen::onStart"); 8 | 9 | Display *display = device.getDisplay(); 10 | Adafruit_PCD8544 *d = display->getDriver(); 11 | d->clearDisplay(); 12 | 13 | rendered = false; 14 | } 15 | 16 | void HomeScreen::onUpdate() { 17 | if (!appManager->isDisplayed(getName())) { 18 | return; 19 | } 20 | 21 | Joystick *joystick = device.getJoystick(); 22 | JoystickState *joystickState = joystick->getState(); 23 | bool sw = joystickState->getSW(); 24 | 25 | if (sw) { 26 | appManager->start("main_menu"); 27 | } 28 | } 29 | 30 | void HomeScreen::onRender() { 31 | if (rendered) { 32 | return; 33 | } 34 | 35 | ESP_LOGD(name, "HomeScreen::onRender (once)"); 36 | 37 | Display *display = device.getDisplay(); 38 | Adafruit_PCD8544 *d = display->getDriver(); 39 | 40 | int i = 0; 41 | File root = SD.open("/"); 42 | while (true) { 43 | File entry = root.openNextFile(); 44 | if (!entry) { 45 | // no more files 46 | break; 47 | } 48 | 49 | ESP_LOGD(name, "/%s", entry.name(), entry); 50 | 51 | d->setCursor(0, i * 8); 52 | d->print("/"); 53 | d->print(entry.name()); 54 | d->display(); 55 | 56 | entry.close(); 57 | i++; 58 | } 59 | 60 | d->setCursor(30, 40); 61 | d->print("Menu"); 62 | d->display(); 63 | 64 | rendered = true; 65 | } -------------------------------------------------------------------------------- /src/core/application/manager.cpp: -------------------------------------------------------------------------------- 1 | #include "manager.h" 2 | 3 | #define TAG "application_manager" 4 | 5 | void ApplicationManager::install(Application &app) { 6 | installed.push_back(&app); 7 | app.onInstall(this); 8 | } 9 | 10 | void ApplicationManager::start(const char *appName) { 11 | ESP_LOGD(TAG, "Start application: %s", appName); 12 | 13 | // If the application has been already started, 14 | // then let's move it to the last position (= displayed); 15 | for (int i = 0; i < running.size(); i++) { 16 | if (strcmp(running[i]->getName(), appName) != 0) { 17 | continue; 18 | } 19 | 20 | if (i == (running.size() - 1)) { 21 | return; // application is already running and it's displayed 22 | } 23 | 24 | running.push_back(running[i]); 25 | running.remove(i); 26 | return; 27 | } 28 | 29 | for (Application *app : installed) { 30 | if (strcmp(app->getName(), appName) == 0) { 31 | running.push_back(app); 32 | 33 | app->onStart(); 34 | return; 35 | } 36 | } 37 | } 38 | 39 | void ApplicationManager::stop(const char *appName) { 40 | ESP_LOGD(TAG, "Stop application: %s", appName); 41 | 42 | for (int i = 0; i < running.size(); i++) { 43 | if (strcmp(running[i]->getName(), appName) == 0) { 44 | running.remove(i); 45 | return; 46 | } 47 | } 48 | } 49 | 50 | void ApplicationManager::onUpdate() { 51 | for (Application *app : running) { 52 | app->onUpdate(); 53 | } 54 | } 55 | 56 | void ApplicationManager::onRender() { 57 | for (Application *app : running) { 58 | if (isDisplayed(app->getName())) { 59 | app->onRender(); 60 | } 61 | } 62 | } 63 | 64 | boolean ApplicationManager::isDisplayed(const char *appName) { 65 | if (running.size() == 0) { 66 | return false; 67 | } 68 | 69 | if (strcmp(running.back()->getName(), appName) != 0) { 70 | return false; 71 | } 72 | return true; 73 | } 74 | -------------------------------------------------------------------------------- /misc/pitches.h: -------------------------------------------------------------------------------- 1 | /************************************************* 2 | 3 | * Public Constants 4 | 5 | *************************************************/ 6 | 7 | #define NOTE_B0 31 8 | #define NOTE_C1 33 9 | #define NOTE_CS1 35 10 | #define NOTE_D1 37 11 | #define NOTE_DS1 39 12 | #define NOTE_E1 41 13 | #define NOTE_F1 44 14 | #define NOTE_FS1 46 15 | #define NOTE_G1 49 16 | #define NOTE_GS1 52 17 | #define NOTE_A1 55 18 | #define NOTE_AS1 58 19 | #define NOTE_B1 62 20 | #define NOTE_C2 65 21 | #define NOTE_CS2 69 22 | #define NOTE_D2 73 23 | #define NOTE_DS2 78 24 | #define NOTE_E2 82 25 | #define NOTE_F2 87 26 | #define NOTE_FS2 93 27 | #define NOTE_G2 98 28 | #define NOTE_GS2 104 29 | #define NOTE_A2 110 30 | #define NOTE_AS2 117 31 | #define NOTE_B2 123 32 | #define NOTE_C3 131 33 | #define NOTE_CS3 139 34 | #define NOTE_D3 147 35 | #define NOTE_DS3 156 36 | #define NOTE_E3 165 37 | #define NOTE_F3 175 38 | #define NOTE_FS3 185 39 | #define NOTE_G3 196 40 | #define NOTE_GS3 208 41 | #define NOTE_A3 220 42 | #define NOTE_AS3 233 43 | #define NOTE_B3 247 44 | #define NOTE_C4 262 45 | #define NOTE_CS4 277 46 | #define NOTE_D4 294 47 | #define NOTE_DS4 311 48 | #define NOTE_E4 330 49 | #define NOTE_F4 349 50 | #define NOTE_FS4 370 51 | #define NOTE_G4 392 52 | #define NOTE_GS4 415 53 | #define NOTE_A4 440 54 | #define NOTE_AS4 466 55 | #define NOTE_B4 494 56 | #define NOTE_C5 523 57 | #define NOTE_CS5 554 58 | #define NOTE_D5 587 59 | #define NOTE_DS5 622 60 | #define NOTE_E5 659 61 | #define NOTE_F5 698 62 | #define NOTE_FS5 740 63 | #define NOTE_G5 784 64 | #define NOTE_GS5 831 65 | #define NOTE_A5 880 66 | #define NOTE_AS5 932 67 | #define NOTE_B5 988 68 | #define NOTE_C6 1047 69 | #define NOTE_CS6 1109 70 | #define NOTE_D6 1175 71 | #define NOTE_DS6 1245 72 | #define NOTE_E6 1319 73 | #define NOTE_F6 1397 74 | #define NOTE_FS6 1480 75 | #define NOTE_G6 1568 76 | #define NOTE_GS6 1661 77 | #define NOTE_A6 1760 78 | #define NOTE_AS6 1865 79 | #define NOTE_B6 1976 80 | #define NOTE_C7 2093 81 | #define NOTE_CS7 2217 82 | #define NOTE_D7 2349 83 | #define NOTE_DS7 2489 84 | #define NOTE_E7 2637 85 | #define NOTE_F7 2794 86 | #define NOTE_FS7 2960 87 | #define NOTE_G7 3136 88 | #define NOTE_GS7 3322 89 | #define NOTE_A7 3520 90 | #define NOTE_AS7 3729 91 | #define NOTE_B7 3951 92 | #define NOTE_C8 4186 93 | #define NOTE_CS8 4435 94 | #define NOTE_D8 4699 95 | #define NOTE_DS8 4978 96 | #define REST 0 97 | -------------------------------------------------------------------------------- /src/core/hardware/device.cpp: -------------------------------------------------------------------------------- 1 | #include "core/hardware/device.h" 2 | 3 | #define TAG "device" 4 | 5 | int melody[] = {NOTE_E5, NOTE_D5, NOTE_FS4, NOTE_GS4, NOTE_CS5, 6 | NOTE_B4, NOTE_D4, NOTE_E4, NOTE_B4, NOTE_A4, 7 | NOTE_CS4, NOTE_E4, NOTE_A4}; 8 | 9 | // note durations: 4 = quarter note, 8 = eighth note, etc, also called tempo: 10 | int noteDurations[] = {8, 8, 4, 4, 8, 8, 4, 4, 8, 8, 4, 4, 2}; 11 | 12 | Device::Device() 13 | : display(Display(PCD8544_DC_PIN, PCD8544_CS_PIN, PCD8544_RST_PIN, 14 | PCD8544_CONTRAST, PCD8544_BIAS)), 15 | led(Adafruit_NeoPixel(1, LED_PIN, NEO_GRB + NEO_KHZ800)), 16 | joystick( 17 | Joystick(JOYSTICK1_VRX_PIN, JOYSTICK1_VRY_PIN, JOYSTICK1_SW_PIN)), 18 | transceiver24( 19 | Transceiver24(TRANSCEIVER_24_CE_PIN, TRANSCEIVER_24_CSN_PIN)), 20 | transceiver433(Transceiver433(TRANSCEIVER_433_CSN_PIN, 21 | TRANSCEIVER_433_GDO0_PIN, 22 | TRANSCEIVER_433_GDO2_PIN)), 23 | buzzer(Buzzer(BUZZER_PIN)), sdCard(SDCard(46)), 24 | irDA(IrDA(IRDA_RECEIVER_PIN, IRDA_SENDER_PIN)) {} 25 | 26 | bool Device::initialize() { 27 | Serial.begin(115200); 28 | while (!Serial) 29 | ; 30 | 31 | ESP_LOGI(TAG, "Willy is starting..."); 32 | printHardwareInfo(); 33 | 34 | if (!display.initialize()) { 35 | return false; 36 | } 37 | 38 | irDA.initialize(); 39 | 40 | boot(); 41 | 42 | decode_results results; 43 | 44 | while (true) { 45 | if (irDA.getReceiverDriver()->decode(&results)) { 46 | if (results.bits > 0) { 47 | ESP_LOGI(TAG, "IrDA: %s", resultToHumanReadableBasic(&results).c_str()); 48 | } 49 | irDA.getReceiverDriver()->resume(); 50 | } 51 | } 52 | 53 | /*ESP_LOGI(TAG, "On"), irDA.getSenderDriver()->sendNEC(0xFFB04F); 54 | delay(3000); 55 | 56 | while (true) { 57 | ESP_LOGI(TAG, "Red!"), irDA.getSenderDriver()->sendNEC(0xFFE817); 58 | delay(1000); 59 | 60 | ESP_LOGI(TAG, "Green!"), irDA.getSenderDriver()->sendNEC(0xFF48B7); 61 | delay(1000); 62 | 63 | ESP_LOGI(TAG, "Blue!"), irDA.getSenderDriver()->sendNEC(0xFF6897); 64 | delay(1000); 65 | }*/ 66 | 67 | return true; 68 | } 69 | 70 | void Device::printHardwareInfo() { 71 | ESP_LOGI(TAG, "Chip model: %s rev. %d", ESP.getChipModel(), 72 | ESP.getChipRevision()); 73 | ESP_LOGI(TAG, "CPU cores: %d", ESP.getChipCores()); 74 | 75 | esp_chip_info_t chip_info; 76 | esp_chip_info(&chip_info); 77 | 78 | ESP_LOGI(TAG, "Flash: %dMB %s", spi_flash_get_chip_size() / (1024 * 1024), 79 | (chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" 80 | : "external"); 81 | ESP_LOGI(TAG, "Flash memory embedded: %s", 82 | (chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "yes" : "no"); 83 | ESP_LOGI(TAG, "2.4GHz WiFi: %s", 84 | (chip_info.features & CHIP_FEATURE_WIFI_BGN) ? "yes" : "no"); 85 | ESP_LOGI(TAG, "Bluetooth LE: %s", 86 | (chip_info.features & CHIP_FEATURE_BLE) ? "yes" : "no"); 87 | ESP_LOGI(TAG, "Bluetooth Classic: %s", 88 | (chip_info.features & CHIP_FEATURE_BT) ? "yes" : "no"); 89 | ESP_LOGI(TAG, "IEEE 802.15.4: %s", 90 | (chip_info.features & CHIP_FEATURE_IEEE802154) ? "yes" : "no"); 91 | ESP_LOGI(TAG, "PSRAM embedded: %s", 92 | (chip_info.features & CHIP_FEATURE_EMB_PSRAM) ? "yes" : "no"); 93 | ESP_LOGI(TAG, "Silicon revision: %d", chip_info.revision); 94 | 95 | uint64_t chipID = ESP.getEfuseMac(); 96 | ESP_LOGI(TAG, "Chip ID: %04X", (uint16_t)(chipID >> 32)); 97 | ESP_LOGI(TAG, "MAC address: %08X", (uint32_t)chipID); 98 | 99 | ESP_LOGI(TAG, "CPU temperature: %.2f C", temperatureRead()); 100 | } 101 | 102 | void Device::boot() { 103 | Adafruit_PCD8544 *d = display.getDriver(); 104 | d->fillScreen(1); 105 | d->display(); 106 | 107 | led.setPixelColor(0, 255, 0, 0); // red pixel 108 | for (int i = 1; i <= LED_BRIGHTNESS; i++) { 109 | led.setBrightness(i); 110 | led.show(); 111 | delay(100); 112 | } 113 | 114 | d->clearDisplay(); 115 | d->display(); 116 | } 117 | 118 | void Device::sync() { 119 | joystick.sync(); 120 | buzzer.sync(); 121 | } 122 | 123 | Display *Device::getDisplay() { return &display; } 124 | 125 | Joystick *Device::getJoystick() { return &joystick; } 126 | 127 | Transceiver24 *Device::getTransceiver24() { return &transceiver24; } 128 | 129 | Transceiver433 *Device::getTransceiver433() { return &transceiver433; } 130 | 131 | Buzzer *Device::getBuzzer() { return &buzzer; } 132 | 133 | SDCard *Device::getSDCard() { return &sdCard; } 134 | 135 | IrDA *Device::getIrDA() { return &irDA; } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /misc/willy.ino.bak: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | This is an example sketch for our Monochrome Nokia 5110 LCD Displays 3 | Pick one up today in the adafruit shop! 4 | ------> http://www.adafruit.com/products/338 5 | These displays use SPI to communicate, 4 or 5 pins are required to 6 | interface 7 | Adafruit invests time and resources providing this open source code, 8 | please support Adafruit and open-source hardware by purchasing 9 | products from Adafruit! 10 | Written by Limor Fried/Ladyada for Adafruit Industries. 11 | BSD license, check license.txt for more information 12 | All text above, and the splash screen must be included in any redistribution 13 | *********************************************************************/ 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include "pitches.h" 20 | 21 | // change this to make the song slower or faster 22 | int tempo = 180; 23 | 24 | int buzzer = 47; 25 | 26 | // notes in the melody: 27 | int melody[] = { 28 | // Nokia Ringtone 29 | // Score available at https://musescore.com/user/29944637/scores/5266155 30 | 31 | NOTE_E5, 32 | 8, 33 | NOTE_D5, 34 | 8, 35 | NOTE_FS4, 36 | 4, 37 | NOTE_GS4, 38 | 4, 39 | NOTE_CS5, 40 | 8, 41 | NOTE_B4, 42 | 8, 43 | NOTE_D4, 44 | 4, 45 | NOTE_E4, 46 | 4, 47 | NOTE_B4, 48 | 8, 49 | NOTE_A4, 50 | 8, 51 | NOTE_CS4, 52 | 4, 53 | NOTE_E4, 54 | 4, 55 | NOTE_A4, 56 | 2, 57 | }; 58 | 59 | // sizeof gives the number of bytes, each int value is composed of two bytes (16 bits) 60 | // there are two values per note (pitch and duration), so for each note there are four bytes 61 | int notes = sizeof(melody) / sizeof(melody[0]) / 2; 62 | 63 | // this calculates the duration of a whole note in ms 64 | int wholenote = (60000 * 4) / tempo; 65 | 66 | int divider = 0, noteDuration = 0; 67 | 68 | // note durations: 4 = quarter note, 8 = eighth note, etc.: 69 | int noteDurations[] = { 70 | 4, 8, 8, 4, 4, 4, 4, 4 71 | }; 72 | 73 | // Software SPI (slower updates, more flexible pin options): 74 | // pin 7 - Serial clock out (SCLK) 75 | // pin 6 - Serial data out (DIN) 76 | // pin 5 - Data/Command select (D/C) 77 | // pin 4 - LCD chip select (CS) 78 | // pin 3 - LCD reset (RST) 79 | //Adafruit_PCD8544 display = Adafruit_PCD8544(12, 11, 13, 10, 14); 80 | 81 | // Hardware SPI (faster, but must use certain hardware pins): 82 | // SCK is LCD serial clock (SCLK) - this is pin 13 on Arduino Uno 83 | // MOSI is LCD DIN - this is pin 11 on an Arduino Uno 84 | // pin 5 - Data/Command select (D/C) 85 | // pin 4 - LCD chip select (CS) 86 | // pin 3 - LCD reset (RST) 87 | // Adafruit_PCD8544 display = Adafruit_PCD8544(5, 4, 3); 88 | Adafruit_PCD8544 display = Adafruit_PCD8544(21, 9, 14); 89 | // Note with hardware SPI MISO and SS pins aren't used but will still be read 90 | // and written to during SPI transfer. Be careful sharing these pins! 91 | 92 | #define NUMFLAKES 10 93 | #define XPOS 0 94 | #define YPOS 1 95 | #define DELTAY 2 96 | 97 | 98 | #define LOGO16_GLCD_HEIGHT 16 99 | #define LOGO16_GLCD_WIDTH 16 100 | 101 | static const unsigned char PROGMEM logo16_glcd_bmp[] = { 0B00000000, 0B11000000, 102 | 0B00000001, 0B11000000, 103 | 0B00000001, 0B11000000, 104 | 0B00000011, 0B11100000, 105 | 0B11110011, 0B11100000, 106 | 0B11111110, 0B11111000, 107 | 0B01111110, 0B11111111, 108 | 0B00110011, 0B10011111, 109 | 0B00011111, 0B11111100, 110 | 0B00001101, 0B01110000, 111 | 0B00011011, 0B10100000, 112 | 0B00111111, 0B11100000, 113 | 0B00111111, 0B11110000, 114 | 0B01111100, 0B11110000, 115 | 0B01110000, 0B01110000, 116 | 0B00000000, 0B00110000 }; 117 | 118 | void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) { 119 | uint8_t icons[NUMFLAKES][3]; 120 | randomSeed(666); // whatever seed 121 | 122 | // initialize 123 | for (uint8_t f = 0; f < NUMFLAKES; f++) { 124 | icons[f][XPOS] = random(display.width()); 125 | icons[f][YPOS] = 0; 126 | icons[f][DELTAY] = random(5) + 1; 127 | 128 | Serial.print("x: "); 129 | Serial.print(icons[f][XPOS], DEC); 130 | Serial.print(" y: "); 131 | Serial.print(icons[f][YPOS], DEC); 132 | Serial.print(" dy: "); 133 | Serial.println(icons[f][DELTAY], DEC); 134 | } 135 | 136 | while (1) { 137 | // draw each icon 138 | for (uint8_t f = 0; f < NUMFLAKES; f++) { 139 | display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, BLACK); 140 | } 141 | display.display(); 142 | delay(200); 143 | 144 | while (Serial.available()) { 145 | switch (Serial.read()) { 146 | case 'w': 147 | display.setContrast(display.getContrast() + 1); 148 | break; 149 | case 's': 150 | if (display.getContrast()) display.setContrast(display.getContrast() - 1); 151 | break; 152 | case 'e': 153 | display.setBias(display.getBias() + 1); 154 | break; 155 | case 'd': 156 | if (display.getBias()) display.setBias(display.getBias() - 1); 157 | break; 158 | case 'R': 159 | display.setReinitInterval(10); 160 | break; 161 | case 'r': 162 | display.initDisplay(); 163 | display.setReinitInterval(0); 164 | break; 165 | } 166 | } 167 | Serial.print("contrast (w/s): 0x"); 168 | Serial.print(display.getContrast(), HEX); 169 | Serial.print(" bias (e/d): 0x"); 170 | Serial.print(display.getBias(), HEX); 171 | Serial.print(" reinitialize display (r/R): 0x"); 172 | Serial.print(display.getReinitInterval(), HEX); 173 | Serial.print(" \r"); 174 | 175 | // then erase it + move it 176 | for (uint8_t f = 0; f < NUMFLAKES; f++) { 177 | display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, WHITE); 178 | // move it 179 | icons[f][YPOS] += icons[f][DELTAY]; 180 | // if its gone, reinit 181 | if (icons[f][YPOS] > display.height()) { 182 | icons[f][XPOS] = random(display.width()); 183 | icons[f][YPOS] = 0; 184 | icons[f][DELTAY] = random(5) + 1; 185 | } 186 | } 187 | } 188 | } 189 | 190 | 191 | void testdrawchar(void) { 192 | display.setTextSize(1); 193 | display.setTextColor(BLACK); 194 | display.setCursor(0, 0); 195 | 196 | for (uint8_t i = 0; i < 168; i++) { 197 | if (i == '\n') continue; 198 | display.write(i); 199 | //if ((i > 0) && (i % 14 == 0)) 200 | //display.println(); 201 | } 202 | display.display(); 203 | } 204 | 205 | void testdrawcircle(void) { 206 | for (int16_t i = 0; i < display.height(); i += 2) { 207 | display.drawCircle(display.width() / 2, display.height() / 2, i, BLACK); 208 | display.display(); 209 | } 210 | } 211 | 212 | void testfillrect(void) { 213 | uint8_t color = 1; 214 | for (int16_t i = 0; i < display.height() / 2; i += 3) { 215 | // alternate colors 216 | display.fillRect(i, i, display.width() - i * 2, display.height() - i * 2, color % 2); 217 | display.display(); 218 | color++; 219 | } 220 | } 221 | 222 | void testdrawtriangle(void) { 223 | for (int16_t i = 0; i < min(display.width(), display.height()) / 2; i += 5) { 224 | display.drawTriangle(display.width() / 2, display.height() / 2 - i, 225 | display.width() / 2 - i, display.height() / 2 + i, 226 | display.width() / 2 + i, display.height() / 2 + i, BLACK); 227 | display.display(); 228 | } 229 | } 230 | 231 | void testfilltriangle(void) { 232 | uint8_t color = BLACK; 233 | for (int16_t i = min(display.width(), display.height()) / 2; i > 0; i -= 5) { 234 | display.fillTriangle(display.width() / 2, display.height() / 2 - i, 235 | display.width() / 2 - i, display.height() / 2 + i, 236 | display.width() / 2 + i, display.height() / 2 + i, color); 237 | if (color == WHITE) color = BLACK; 238 | else color = WHITE; 239 | display.display(); 240 | } 241 | } 242 | 243 | void testdrawroundrect(void) { 244 | for (int16_t i = 0; i < display.height() / 2 - 2; i += 2) { 245 | display.drawRoundRect(i, i, display.width() - 2 * i, display.height() - 2 * i, display.height() / 4, BLACK); 246 | display.display(); 247 | } 248 | } 249 | 250 | void testfillroundrect(void) { 251 | uint8_t color = BLACK; 252 | for (int16_t i = 0; i < display.height() / 2 - 2; i += 2) { 253 | display.fillRoundRect(i, i, display.width() - 2 * i, display.height() - 2 * i, display.height() / 4, color); 254 | if (color == WHITE) color = BLACK; 255 | else color = WHITE; 256 | display.display(); 257 | } 258 | } 259 | 260 | void testdrawrect(void) { 261 | for (int16_t i = 0; i < display.height() / 2; i += 2) { 262 | display.drawRect(i, i, display.width() - 2 * i, display.height() - 2 * i, BLACK); 263 | display.display(); 264 | } 265 | } 266 | 267 | void testdrawline() { 268 | for (int16_t i = 0; i < display.width(); i += 4) { 269 | display.drawLine(0, 0, i, display.height() - 1, BLACK); 270 | display.display(); 271 | } 272 | for (int16_t i = 0; i < display.height(); i += 4) { 273 | display.drawLine(0, 0, display.width() - 1, i, BLACK); 274 | display.display(); 275 | } 276 | delay(250); 277 | 278 | display.clearDisplay(); 279 | for (int16_t i = 0; i < display.width(); i += 4) { 280 | display.drawLine(0, display.height() - 1, i, 0, BLACK); 281 | display.display(); 282 | } 283 | for (int8_t i = display.height() - 1; i >= 0; i -= 4) { 284 | display.drawLine(0, display.height() - 1, display.width() - 1, i, BLACK); 285 | display.display(); 286 | } 287 | delay(250); 288 | 289 | display.clearDisplay(); 290 | for (int16_t i = display.width() - 1; i >= 0; i -= 4) { 291 | display.drawLine(display.width() - 1, display.height() - 1, i, 0, BLACK); 292 | display.display(); 293 | } 294 | for (int16_t i = display.height() - 1; i >= 0; i -= 4) { 295 | display.drawLine(display.width() - 1, display.height() - 1, 0, i, BLACK); 296 | display.display(); 297 | } 298 | delay(250); 299 | 300 | display.clearDisplay(); 301 | for (int16_t i = 0; i < display.height(); i += 4) { 302 | display.drawLine(display.width() - 1, 0, 0, i, BLACK); 303 | display.display(); 304 | } 305 | for (int16_t i = 0; i < display.width(); i += 4) { 306 | display.drawLine(display.width() - 1, 0, i, display.height() - 1, BLACK); 307 | display.display(); 308 | } 309 | delay(250); 310 | } 311 | 312 | void playSound() { 313 | // iterate over the notes of the melody. 314 | // Remember, the array is twice the number of notes (notes + durations) 315 | for (int thisNote = 0; thisNote < notes * 2; thisNote = thisNote + 2) { 316 | 317 | // calculates the duration of each note 318 | divider = melody[thisNote + 1]; 319 | if (divider > 0) { 320 | // regular note, just proceed 321 | noteDuration = (wholenote) / divider; 322 | } else if (divider < 0) { 323 | // dotted notes are represented with negative durations!! 324 | noteDuration = (wholenote) / abs(divider); 325 | noteDuration *= 1.5; // increases the duration in half for dotted notes 326 | } 327 | 328 | // we only play the note for 90% of the duration, leaving 10% as a pause 329 | tone(buzzer, melody[thisNote], noteDuration * 0.9); 330 | 331 | // Wait for the specief duration before playing the next note. 332 | delay(noteDuration); 333 | 334 | // stop the waveform generation before the next note. 335 | noTone(buzzer); 336 | } 337 | } 338 | 339 | void setup() { 340 | Serial.begin(115200); 341 | Serial.println("PCD test"); 342 | 343 | display.begin(); 344 | // init done 345 | 346 | //playSound(); 347 | 348 | // you can change the contrast around to adapt the display 349 | // for the best viewing! 350 | display.setContrast(90); 351 | 352 | display.display(); // show splashscreen 353 | delay(2000); 354 | display.clearDisplay(); // clears the screen and buffer 355 | 356 | // draw a single pixel 357 | display.drawPixel(10, 10, BLACK); 358 | display.display(); 359 | delay(2000); 360 | display.clearDisplay(); 361 | 362 | // draw many lines 363 | testdrawline(); 364 | display.display(); 365 | delay(2000); 366 | display.clearDisplay(); 367 | 368 | // draw rectangles 369 | testdrawrect(); 370 | display.display(); 371 | delay(2000); 372 | display.clearDisplay(); 373 | 374 | // draw multiple rectangles 375 | testfillrect(); 376 | display.display(); 377 | delay(2000); 378 | display.clearDisplay(); 379 | 380 | // draw mulitple circles 381 | testdrawcircle(); 382 | display.display(); 383 | delay(2000); 384 | display.clearDisplay(); 385 | 386 | // draw a circle, 10 pixel radius 387 | display.fillCircle(display.width() / 2, display.height() / 2, 10, BLACK); 388 | display.display(); 389 | delay(2000); 390 | display.clearDisplay(); 391 | 392 | testdrawroundrect(); 393 | delay(2000); 394 | display.clearDisplay(); 395 | 396 | testfillroundrect(); 397 | delay(2000); 398 | display.clearDisplay(); 399 | 400 | testdrawtriangle(); 401 | delay(2000); 402 | display.clearDisplay(); 403 | 404 | testfilltriangle(); 405 | delay(2000); 406 | display.clearDisplay(); 407 | 408 | // draw the first ~12 characters in the font 409 | testdrawchar(); 410 | display.display(); 411 | delay(2000); 412 | display.clearDisplay(); 413 | 414 | // text display tests 415 | display.setTextSize(1); 416 | display.setTextColor(BLACK); 417 | display.setCursor(0, 0); 418 | display.println("Hello, world!"); 419 | display.setTextColor(WHITE, BLACK); // 'inverted' text 420 | display.println(3.141592); 421 | display.setTextSize(2); 422 | display.setTextColor(BLACK); 423 | display.print("0x"); 424 | display.println(0xDEADBEEF, HEX); 425 | display.display(); 426 | delay(2000); 427 | 428 | // rotation example 429 | display.clearDisplay(); 430 | display.setRotation(1); // rotate 90 degrees counter clockwise, can also use values of 2 and 3 to go further. 431 | display.setTextSize(1); 432 | display.setTextColor(BLACK); 433 | display.setCursor(0, 0); 434 | display.println("Rotation"); 435 | display.setTextSize(2); 436 | display.println("Example!"); 437 | display.display(); 438 | delay(2000); 439 | 440 | // revert back to no rotation 441 | display.setRotation(0); 442 | 443 | // miniature bitmap display 444 | display.clearDisplay(); 445 | display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, 1); 446 | display.display(); 447 | 448 | // invert the display 449 | display.invertDisplay(true); 450 | delay(1000); 451 | display.invertDisplay(false); 452 | delay(1000); 453 | 454 | // draw a bitmap icon and 'animate' movement 455 | // testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_WIDTH, LOGO16_GLCD_HEIGHT); 456 | } 457 | 458 | void loop() { 459 | } --------------------------------------------------------------------------------