├── .github └── workflows │ ├── LibraryBuild.yml │ └── PlatformIoPublish.yml ├── LICENSE.txt ├── README.md ├── examples ├── BTModuleProgrammer │ ├── BTModuleProgrammer.ino │ ├── BTModuleProgrammer_empty.log │ ├── BTModuleProgrammer_master.log │ └── BTModuleProgrammer_setName.log ├── BlueDisplayBlink │ └── BlueDisplayBlink.ino ├── BlueDisplayExample │ ├── BlueDisplayExample.ino │ ├── PinDefinitionsAndMore.h │ ├── Time.cpp │ └── TimeLib.h ├── ChartForMHZ19_CO2 │ ├── CO2LoggerAndChart.h │ ├── CO2LoggerAndChart.hpp │ ├── ChartForMHZ19_CO2.ino │ ├── LCDBigNumbers.hpp │ ├── LiquidCrystal_I2C.h │ ├── LiquidCrystal_I2C.hpp │ ├── MHZ19.h │ ├── MHZ19.hpp │ ├── SoftI2CMaster.h │ ├── SoftI2CMasterConfig.h │ ├── Time.cpp │ └── TimeLib.h ├── ManySlidersAndButtons │ ├── ManySlidersAndButtons.ino │ ├── ManySlidersAndButtonsHelper.h │ └── ManySlidersAndButtonsHelper.hpp ├── RcCarControl │ ├── HCSR04.h │ ├── HCSR04.hpp │ ├── RcCarControl.ino │ ├── RcCarControlBD.cpp │ ├── RcCarControlBD.h │ └── digitalWriteFast.h ├── ServoExample │ ├── ServoEasing.h │ ├── ServoEasing.hpp │ └── ServoExample.ino ├── ShowSensorValues │ └── ShowSensorValues.ino ├── SimpleDSO_BlueDisplay │ ├── FrequencyGeneratorPage.h │ ├── FrequencyGeneratorPage.hpp │ ├── README.md │ ├── SimpleDSO_BlueDisplay.h │ ├── SimpleDSO_BlueDisplay.ino │ ├── TouchDSOCommon.h │ ├── TouchDSOGui.hpp │ ├── Waveforms.cpp │ ├── Waveforms.h │ └── digitalWriteFast.h ├── SimpleTouchScreenDSO │ ├── README.md │ ├── SimpleTouchScreenDSO.ino │ └── digitalWriteFast.h ├── TouchGuiDemo │ ├── GameOfLife.h │ ├── GameOfLife.hpp │ ├── GuiDemo.h │ ├── GuiDemo.hpp │ ├── LocalDisplayGUI.hpp │ ├── PageDraw.hpp │ └── TouchGuiDemo.ino ├── TwoButtonsOnLocalDisplay │ └── TwoButtonsOnLocalDisplay.ino └── US_Distance │ ├── HCSR04.h │ ├── HCSR04.hpp │ ├── PinDefinitionsAndMore.h │ ├── US_Distance.ino │ └── digitalWriteFast.h ├── extras ├── Arduino_Nano_DSO_Schaltplan.png ├── Arduino_Nano_DSO_Simple_Schaltplan.png ├── Arduino_Nano_DSO_Simple_Steckplatine.png ├── Arduino_Nano_DSO_Steckplatine.png ├── BlueDisplayBlink.fzz ├── BlueDisplayBlink_Schaltplan.png └── BlueDisplayBlink_Steckplatine.png ├── keywords.txt ├── library.json ├── library.properties ├── pictures ├── AccelerometerOnPlotter.png ├── ArduinoDSO_Simple.jpg ├── BTModuleProgrammer.jpg ├── Blink.jpg ├── BlueDisplayBlink_off.jpg ├── BlueDisplayBlink_on.jpg ├── BlueDisplayExample.jpg ├── BlueDisplayExample_Test.jpg ├── ChartForMHZ19_CO2.png ├── ChartPage.bmp ├── Distance+Smartphone.jpg ├── DrawPage.bmp ├── GameOfLife.bmp ├── GameOfLifeStartPage.bmp ├── ManySlidersAndButtons.png ├── RCCar+Tablet.jpg ├── RCCarControl.png ├── Screenshot_20201015-145931.jpg ├── ServoExample.png ├── ServoExample_Bias.png ├── SettingsPage.bmp └── TouchGuiDemoMainPage.bmp └── src ├── ADCUtils.h ├── ADCUtils.hpp ├── BDButton.h ├── BDButton.hpp ├── BDSlider.h ├── BDSlider.hpp ├── BlueDisplay.h ├── BlueDisplay.hpp ├── BlueDisplayProtocol.h ├── BlueDisplayUtils.h ├── BlueDisplayUtils.hpp ├── BlueSerial.h ├── BlueSerial.hpp ├── Chart.h ├── Chart.hpp ├── Colors.h ├── EventHandler.h ├── EventHandler.hpp ├── GUIHelper.h ├── GUIHelper.hpp ├── LayoutHelper.h ├── LocalDisplay ├── ADS7846.h ├── ADS7846.hpp ├── HX8347D.h ├── HX8347D.hpp ├── LocalDisplayInterface.h ├── LocalDisplayInterface.hpp ├── LocalEventHelper.h ├── LocalEventHelper.hpp ├── SSD1289.h ├── SSD1289.hpp ├── STM32TouchScreenDriver.cpp ├── STM32TouchScreenDriver.h ├── digitalWriteFast.h ├── font_10x16.hpp ├── font_12x16.hpp ├── font_12x20.hpp ├── font_16x26.hpp ├── font_4x6.hpp ├── font_5x12.hpp ├── font_5x8.hpp ├── font_6x10.hpp ├── font_6x8.hpp ├── font_7x12.hpp ├── font_8x12.hpp ├── font_8x14.hpp ├── font_8x8.hpp ├── fonts.hpp └── keywords.txt ├── LocalGUI.hpp ├── LocalGUI ├── LocalTinyPrint.h ├── LocalTinyPrint.hpp ├── LocalTouchButton.h ├── LocalTouchButton.hpp ├── LocalTouchButtonAutorepeat.h ├── LocalTouchButtonAutorepeat.hpp ├── LocalTouchSlider.h ├── LocalTouchSlider.hpp ├── ThickLine.h ├── ThickLine.hpp └── keywords.txt ├── LocalHX8347DDisplay.hpp ├── LocalSSD1289Display.hpp └── TTS-ListOfAllVoices.txt /.github/workflows/LibraryBuild.yml: -------------------------------------------------------------------------------- 1 | # LibraryBuild.yml 2 | # Github workflow script to test compile all examples of an Arduino library repository. 3 | # 4 | # Copyright (C) 2020-2024 Armin Joachimsmeyer 5 | # https://github.com/ArminJo/Github-Actions 6 | # 7 | 8 | # This is the name of the workflow, visible on GitHub UI. 9 | name: LibraryBuild 10 | on: 11 | workflow_dispatch: # To run it manually 12 | description: 'manual build check' 13 | push: # see: https://help.github.com/en/actions/reference/events-that-trigger-workflows#pull-request-event-pull_request 14 | paths: 15 | - '**.ino' 16 | - '**.cpp' 17 | - '**.hpp' 18 | - '**.h' 19 | - '**LibraryBuild.yml' 20 | pull_request: 21 | 22 | jobs: 23 | build: 24 | name: ${{ matrix.arduino-boards-fqbn }} - test compiling examples 25 | 26 | runs-on: ubuntu-latest # I picked Ubuntu to use shell scripts. 27 | 28 | env: 29 | # Comma separated list without double quotes around the list. 30 | REQUIRED_LIBRARIES: Servo,LiquidCrystal 31 | 32 | strategy: 33 | matrix: 34 | # The matrix will produce one job for each configuration parameter of type `arduino-boards-fqbn` 35 | # In the Arduino IDE, the fqbn is printed in the first line of the verbose output for compilation as parameter -fqbn=... for the "arduino-builder -dump-prefs" command 36 | # 37 | # Examples: arduino:avr:uno, arduino:avr:leonardo, arduino:avr:nano, arduino:avr:mega 38 | # arduino:sam:arduino_due_x, arduino:samd:arduino_zero_native" 39 | # ATTinyCore:avr:attinyx5:chip=85,clock=1internal, digistump:avr:digispark-tiny, digistump:avr:digispark-pro 40 | # STMicroelectronics:stm32:GenF1:pnum=BLUEPILL_F103C8 41 | # esp8266:esp8266:huzzah:eesz=4M3M,xtal=80, esp32:esp32:featheresp32:FlashFreq=80 42 | # You may add a suffix behind the fqbn with "|" to specify one board for e.g. different compile options like arduino:avr:uno|trace 43 | ############################################################################################################# 44 | arduino-boards-fqbn: 45 | - arduino:avr:uno 46 | - arduino:avr:leonardo 47 | - arduino:avr:mega 48 | - arduino:sam:arduino_due_x 49 | - esp8266:esp8266:huzzah:eesz=4M3M,xtal=80 50 | - esp32:esp32:esp32doit-devkit-v1 51 | - STMicroelectronics:stm32:GenF1:pnum=BLUEPILL_F103C8 52 | - stm32duino:STM32F1:genericSTM32F103C 53 | 54 | # Specify parameters for each board. 55 | # With sketches-exclude you may exclude specific examples for a board. Use a comma separated list. 56 | ############################################################################################################# 57 | include: 58 | - arduino-boards-fqbn: arduino:avr:leonardo 59 | sketches-exclude: SimpleTouchScreenDSO,TouchGuiDemo # Too big 60 | 61 | - arduino-boards-fqbn: arduino:sam:arduino_due_x 62 | sketches-exclude: SimpleTouchScreenDSO,SimpleDSO_BlueDisplay,TwoButtonsOnLocalDisplay,BTModuleProgrammer,ShowSensorValues,TouchGuiDemo,ChartForMHZ19_CO2 # missing random() 63 | 64 | - arduino-boards-fqbn: MegaCore:avr:128:bootloader=no_bootloader,eeprom=keep,BOD=2v7,LTO=Os,clock=8MHz_internal 65 | platform-url: https://mcudude.github.io/MegaCore/package_MCUdude_MegaCore_index.json 66 | arduino-platform: arduino:avr,MegaCore:avr # gcc is taken from arduino:avr 67 | sketches-exclude: SimpleTouchScreenDSO,SimpleDSO_BlueDisplay,TwoButtonsOnLocalDisplay,ServoExample,ChartForMHZ19_CO2 # ServoEasing not available for Mega Core 68 | 69 | - arduino-boards-fqbn: esp8266:esp8266:huzzah:eesz=4M3M,xtal=80 70 | platform-url: https://arduino.esp8266.com/stable/package_esp8266com_index.json 71 | sketches-exclude: SimpleTouchScreenDSO,SimpleDSO_BlueDisplay,TwoButtonsOnLocalDisplay,BTModuleProgrammer,ChartForMHZ19_CO2 72 | 73 | - arduino-boards-fqbn: esp32:esp32:esp32doit-devkit-v1 74 | platform-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json 75 | sketches-exclude: SimpleTouchScreenDSO,SimpleDSO_BlueDisplay,TwoButtonsOnLocalDisplay,RcCarControl,BTModuleProgrammer,ServoExample,ChartForMHZ19_CO2 76 | # build-properties: # the flags were put in compiler.cpp.extra_flags 77 | # ShowSensorValues: -Wno-error=format-overflow # https://github.com/espressif/arduino-esp32/issues/7024 !!using this in ESP 3.x gives strange errors!!! 78 | 79 | - arduino-boards-fqbn: STMicroelectronics:stm32:GenF1:pnum=BLUEPILL_F103C8 80 | platform-url: https://raw.githubusercontent.com/stm32duino/BoardManagerFiles/main/package_stmicroelectronics_index.json 81 | sketches-exclude: SimpleTouchScreenDSO,SimpleDSO_BlueDisplay,TwoButtonsOnLocalDisplay,ChartForMHZ19_CO2 # Comma separated list of example names to exclude in build 82 | 83 | - arduino-boards-fqbn: stm32duino:STM32F1:genericSTM32F103C # Roger Clark version 84 | platform-url: http://dan.drown.org/stm32duino/package_STM32duino_index.json 85 | sketches-exclude: SimpleTouchScreenDSO,SimpleDSO_BlueDisplay,TwoButtonsOnLocalDisplay,BTModuleProgrammer,ChartForMHZ19_CO2 # Comma separated list of example names to exclude in build 86 | 87 | # fail-fast: false # false -> do not cancel all jobs / architectures if one job fails 88 | 89 | steps: 90 | - name: Checkout 91 | uses: actions/checkout@master 92 | 93 | - name: Compile all examples using the arduino-test-compile action 94 | uses: ArminJo/arduino-test-compile@master 95 | with: 96 | arduino-board-fqbn: ${{ matrix.arduino-boards-fqbn }} 97 | arduino-platform: ${{ matrix.arduino-platform }} # for MegaCore 98 | platform-url: ${{ matrix.platform-url }} 99 | required-libraries: ${{ env.REQUIRED_LIBRARIES }} 100 | sketches-exclude: ${{ matrix.sketches-exclude }} 101 | build-properties: ${{ toJson(matrix.build-properties) }} 102 | # build-properties: '{ "All": "-DOMIT_BD_DEPRECATED_FUNCTIONS{{ matrix.build-properties }}" }' 103 | 104 | # build-properties: '{ "SimpleTouchScreenDSO": "-DBD_USE_SIMPLE_SERIAL" }' 105 | # debug-install: true 106 | # debug-compile: true -------------------------------------------------------------------------------- /.github/workflows/PlatformIoPublish.yml: -------------------------------------------------------------------------------- 1 | # PlatformIoPublish.yml 2 | # Github workflow script to publish a release to PlatformIo. 3 | # 4 | # Copyright (C) 2021-2023 Armin Joachimsmeyer 5 | # https://github.com/ArminJo/Github-Actions 6 | # 7 | 8 | # This is the name of the workflow, visible on GitHub UI. 9 | name: PlatformIo publishing 10 | on: 11 | workflow_dispatch: # To run it manually 12 | description: manual PlatformIo publishing 13 | release: # see: https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#example-using-multiple-events-with-activity-types-or-configuration 14 | types: 15 | - created 16 | 17 | jobs: 18 | publish: 19 | runs-on: ubuntu-latest 20 | steps: 21 | 22 | - name: Checkout 23 | uses: actions/checkout@master 24 | 25 | - name: Set up Python 26 | uses: actions/setup-python@master 27 | with: 28 | python-version: '3.x' 29 | 30 | - name: Install dependencies 31 | run: | 32 | python -m pip install --upgrade pip 33 | pip install platformio 34 | 35 | - name: Build and publish 36 | env: 37 | PLATFORMIO_AUTH_TOKEN: ${{ secrets.PLATFORMIO_TOKEN }} 38 | run: | 39 | pio package publish --owner arminjo --non-interactive 40 | # run: | 41 | # pio package pack 42 | # pio package publish --owner arminjo --non-interactive 43 | -------------------------------------------------------------------------------- /examples/BTModuleProgrammer/BTModuleProgrammer_empty.log: -------------------------------------------------------------------------------- 1 | START ../src/BTModuleProgrammer.cpp 2 | Version 3.1 from Mar 21 2022 3 | HC-05 programming mode detected. Switch to JDY-31 mode by connecting pin 4 to ground or to pin 5. 4 | 5 | Now you have 5 seconds for releasing HC-05 module key, which should be pressed at power up to enter program mode. 6 | 7 | Now we try to connect to module, read version and baud and wait for new name to be entered. 8 | 9 | HC-05 module selected. 10 | 11 | Start with baudrate 38400 for HC-05 - factory default for AT command mode 12 | Setup HC-05 module. 13 | Sent: "AT\r\n" 14 | Received: "" 15 | No valid response to AT command. Program mode must be enabled to get a response! 16 | 17 | Programming skipped or not successful. You may now: 18 | - Press reset for a new try. 19 | - Enter "AT+". 20 | 21 | -------------------------------------------------------------------------------- /examples/BTModuleProgrammer/BTModuleProgrammer_master.log: -------------------------------------------------------------------------------- 1 | START ../src/BTModuleProgrammer.cpp 2 | Version 3.1 from Mar 21 2022 3 | HC-05 programming mode detected. Switch to JDY-31 mode by connecting pin 4 to ground or to pin 5. 4 | 5 | Now you have 5 seconds for releasing HC-05 module key, which should be pressed at power up to enter program mode. 6 | 7 | Now we try to connect to module, read version and baud and wait for new name to be entered. 8 | 9 | HC-05 module selected. 10 | 11 | Start with baudrate 38400 for HC-05 - factory default for AT command mode 12 | Setup HC-05 module. 13 | Sent: "AT\r\n" 14 | Received: "OK\r\n" 15 | Module attached OK. 16 | 17 | Get version 18 | Sent: "AT+VERSION\r\n" 19 | Received: "+VERSION:2.0-20100601\r\nOK\r\n" 20 | 21 | Get current baud 22 | Sent: "AT+UART\r\n" 23 | Received: "+UART:115200,0,0\r\nOK\r\n" 24 | 25 | Get current name 26 | Sent: "AT+NAME\r\n" 27 | Received: "" 28 | 29 | Get current PIN 30 | Sent: "AT+PSWD\r\n" 31 | Received: "+PSWD:1234\r\nOK\r\n" 32 | 33 | Get current Role (0->Slave, 1->Master, 2->Slave-Loop) 34 | Sent: "AT+ROLE\r\n" 35 | Received: "+ROLE:1\r\nOK\r\n" 36 | 37 | Get current Cmode (0->connect to fixed bind address, 1->connect to all) 38 | Sent: "AT+CMODE\r\n" 39 | Received: "+CMOD:1\r\nOK\r\n" 40 | 41 | Get Bind address 42 | Sent: "AT+BIND\r\n" 43 | Received: "+BIND:98d3:31:fb2f4f\r\nOK\r\n" 44 | 45 | Get own Address 46 | Sent: "AT+ADDR\r\n" 47 | Received: "+ADDR:98d3:31:fb2c82\r\nOK\r\n" 48 | 49 | Enter new module name to set this name and to set baudrate to 115200 - you will be asked for confirmation. 50 | Or enter empty string to skip (and enter direct AT mode). 51 | Timeout is 60 seconds. 52 | 53 | 54 | Programming skipped or not successful. You may now: 55 | - Press reset for a new try. 56 | - Enter "AT+". 57 | 58 | -------------------------------------------------------------------------------- /examples/BTModuleProgrammer/BTModuleProgrammer_setName.log: -------------------------------------------------------------------------------- 1 | START ../src/BTModuleProgrammer.cpp 2 | Version 3.1 from Mar 21 2022 3 | HC-05 programming mode detected. Switch to JDY-31 mode by connecting pin 4 to ground or to pin 5. 4 | 5 | Now you have 5 seconds for releasing HC-05 module key, which should be pressed at power up to enter program mode. 6 | 7 | Now we try to connect to module, read version and baud and wait for new name to be entered. 8 | 9 | HC-05 module selected. 10 | 11 | Start with baudrate 38400 for HC-05 - factory default for AT command mode 12 | Setup HC-05 module. 13 | Sent: "AT\r\n" 14 | Received: "OK\r\n" 15 | Module attached OK. 16 | 17 | Get version 18 | Sent: "AT+VERSION\r\n" 19 | Received: "VERSION:3.0-20170601\r\nOK\r\n" 20 | 21 | Get current baud 22 | Sent: "AT+UART\r\n" 23 | Received: "+UART:9600,0,0\r\nOK\r\n" 24 | 25 | Get current name 26 | Sent: "AT+NAME\r\n" 27 | Received: "+NAME:H-C-2010-06-01\r\nOK\r\n" 28 | 29 | Get current PIN 30 | Sent: "AT+PSWD\r\n" 31 | Received: "+PIN:"1234"\r\nOK\r\n" 32 | 33 | Get current Role (0->Slave, 1->Master, 2->Slave-Loop) 34 | Sent: "AT+ROLE\r\n" 35 | Received: "+ROLE:0\r\nOK\r\n" 36 | 37 | Get current Cmode (0->connect to fixed bind address, 1->connect to all) 38 | Sent: "AT+CMODE\r\n" 39 | Received: "+CMODE:1\r\nOK\r\n" 40 | 41 | Get Bind address 42 | Sent: "AT+BIND\r\n" 43 | Received: "+BIND:0:0:0\r\nOK\r\n" 44 | 45 | Get own Address 46 | Sent: "AT+ADDR\r\n" 47 | Received: "+ADDR:21:13:66F9\r\nOK\r\n" 48 | 49 | Enter new module name to set this name and to set baudrate to 115200 - you will be asked for confirmation. 50 | Or enter empty string to skip (and enter direct AT mode). 51 | Factory reset command is "AT+ORGL". 52 | Timeout is 60 seconds. 53 | 54 | 55 | Confirm setting to factory reset and setting name of the module to "4WD-CAR-MECANUM" and baudrate to 115200 56 | by entering any character or press reset or remove power. 57 | 58 | Sent: "AT\r\n" 59 | Received: "OK\r\n" 60 | Set name to "4WD-CAR-MECANUM" 61 | Sent: "AT+NAME=4WD-CAR-MECANUM\r\n" 62 | Received: "OK\r\n" 63 | 64 | Set baud to 115200 65 | Sent: "AT+UART=115200,0,0\r\n" 66 | Received: "OK\r\n" 67 | 68 | Successful programmed HC-05 module. 69 | 70 | 71 | Programming successful. You may now: 72 | - Press reset for a new try. 73 | - Enter "AT+". 74 | 75 | -------------------------------------------------------------------------------- /examples/BlueDisplayBlink/BlueDisplayBlink.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * BlueDisplayBlink.cpp 3 | * 4 | * Demo of using the BlueDisplay library for HC-05 on Arduino 5 | * 6 | * Copyright (C) 2014-2023 Armin Joachimsmeyer 7 | * armin.joachimsmeyer@gmail.com 8 | * 9 | * This file is part of BlueDisplay https://github.com/ArminJo/Arduino-BlueDisplay. 10 | * 11 | * BlueDisplay is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 19 | * See the GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | * 24 | */ 25 | 26 | #include 27 | 28 | #define DISPLAY_WIDTH DISPLAY_HALF_VGA_WIDTH // 320 29 | #define DISPLAY_HEIGHT DISPLAY_HALF_VGA_HEIGHT // 240 30 | 31 | /* 32 | * Settings to configure the BlueDisplay library and to reduce its size 33 | */ 34 | //#define BLUETOOTH_BAUD_RATE BAUD_115200 // Activate this, if you have reprogrammed the HC05 module for 115200, otherwise 9600 is used as baud rate 35 | //#define DO_NOT_NEED_BASIC_TOUCH_EVENTS // Disables basic touch events down, move and up. Saves 620 bytes program memory and 36 bytes RAM 36 | #define DO_NOT_NEED_LONG_TOUCH_DOWN_AND_SWIPE_EVENTS // Disables LongTouchDown and SwipeEnd events. 37 | //#define DO_NOT_NEED_SPEAK_EVENTS // Disables SpeakingDone event handling. Saves up to 54 bytes program memory and 18 bytes RAM. 38 | //#define ONLY_CONNECT_EVENT_REQUIRED // Disables reorientation, redraw and SensorChange events 39 | //#define BD_USE_SIMPLE_SERIAL // Do not use the Serial object. Saves up to 1250 bytes program memory and 185 bytes RAM, if Serial is not used otherwise 40 | //#define BD_USE_USB_SERIAL // Activate it, if you want to force using Serial instead of Serial1 for direct USB cable connection* to your smartphone / tablet. 41 | #include "BlueDisplay.hpp" 42 | 43 | bool doBlink = true; 44 | 45 | /* 46 | * The Start Stop button 47 | */ 48 | BDButton TouchButtonBlinkStartStop; 49 | 50 | // Touch handler for buttons 51 | void doBlinkStartStop(BDButton *aTheTouchedButton, int16_t aValue); 52 | 53 | // Callback handler for (re)connect and resize 54 | void initDisplay(void); 55 | void drawGui(void); 56 | 57 | // PROGMEM messages sent by BlueDisplay1.debug() are truncated to 32 characters :-(, so must use RAM here 58 | const char StartMessage[] PROGMEM = "START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_BLUE_DISPLAY; 59 | 60 | /******************************************************************************************* 61 | * Program code starts here 62 | *******************************************************************************************/ 63 | 64 | void setup() { 65 | // Initialize the LED pin as output. 66 | pinMode(LED_BUILTIN, OUTPUT); 67 | 68 | #if defined(ESP32) 69 | Serial.begin(115200); 70 | Serial.println(StartMessage); 71 | initSerial("ESP-BD_Example"); 72 | Serial.println("Start ESP32 BT-client with name \"ESP-BD_Example\""); 73 | #else 74 | initSerial(); 75 | #endif 76 | 77 | /* 78 | * Register callback handler and wait for 300 ms if Bluetooth connection is still active. 79 | * For ESP32 and after power on of the Bluetooth module (HC-05) at other platforms, Bluetooth connection is most likely not active here. 80 | * 81 | * If active, mCurrentDisplaySize and mHostUnixTimestamp are set and initDisplay() and drawGui() functions are called. 82 | * If not active, the periodic call of checkAndHandleEvents() in the main loop waits for the (re)connection and then performs the same actions. 83 | */ 84 | BlueDisplay1.initCommunication(&Serial, &initDisplay, &drawGui); // introduces up to 1.5 seconds delay 85 | 86 | #if defined(BD_USE_SERIAL1) || defined(ESP32) // BD_USE_SERIAL1 may be defined in BlueSerial.h 87 | // Serial(0) is available for Serial.print output. 88 | # if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/ \ 89 | || defined(SERIALUSB_PID) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_attiny3217) 90 | delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor! 91 | # endif 92 | // Just to know which program is running on my Arduino 93 | Serial.println(reinterpret_cast(StartMessage)); 94 | #elif !defined(BD_USE_SIMPLE_SERIAL) 95 | // If using simple serial on first USART we cannot use Serial.print, since this uses the same interrupt vector as simple serial. 96 | if (!BlueDisplay1.isConnectionEstablished()) { 97 | # if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/ \ 98 | || defined(SERIALUSB_PID) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_attiny3217) 99 | delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor! 100 | # endif 101 | // If connection is enabled, this message was already sent as BlueDisplay1.debug() by initDisplay() 102 | Serial.println(reinterpret_cast(StartMessage)); 103 | } 104 | #endif 105 | } 106 | 107 | void loop() { 108 | 109 | /* 110 | * This debug output can also be recognized at the Arduino Serial Monitor 111 | */ 112 | // BlueDisplay1.debug("\r\nDoBlink=", (uint8_t) doBlink); 113 | if (doBlink) { 114 | // LED on 115 | digitalWrite(LED_BUILTIN, HIGH); 116 | BlueDisplay1.fillCircle(DISPLAY_WIDTH / 2, DISPLAY_HEIGHT / 2, 20, COLOR16_RED); 117 | delayMillisWithCheckAndHandleEvents(300); 118 | } 119 | 120 | if (doBlink) { 121 | // LED off 122 | digitalWrite(LED_BUILTIN, LOW); 123 | BlueDisplay1.fillCircle(DISPLAY_WIDTH / 2, DISPLAY_HEIGHT / 2, 20, COLOR16_BLUE); 124 | delayMillisWithCheckAndHandleEvents(300); 125 | } 126 | 127 | // To get blink enable event 128 | checkAndHandleEvents(); 129 | } 130 | 131 | /* 132 | * Function used as callback handler for connect too 133 | */ 134 | void initDisplay(void) { 135 | // Initialize display size and flags 136 | BlueDisplay1.setFlagsAndSize(BD_FLAG_FIRST_RESET_ALL | BD_FLAG_USE_MAX_SIZE, DISPLAY_WIDTH, DISPLAY_HEIGHT); 137 | // Initialize button position, size, colors etc. 138 | TouchButtonBlinkStartStop.init((DISPLAY_WIDTH - BUTTON_WIDTH_2) / 2, BUTTON_HEIGHT_4_LINE_4, BUTTON_WIDTH_2, 139 | BUTTON_HEIGHT_4, COLOR16_BLUE, "Start", 44, FLAG_BUTTON_DO_BEEP_ON_TOUCH | FLAG_BUTTON_TYPE_TOGGLE, doBlink, 140 | &doBlinkStartStop); 141 | TouchButtonBlinkStartStop.setTextForValueTrue("Stop"); 142 | 143 | BlueDisplay1.debug(reinterpret_cast(StartMessage)); 144 | 145 | // Talk functions are only implemented in Android > 5.0 (Lollipop) 146 | BlueDisplay1.speakSetLocale(F("en-us")); 147 | BlueDisplay1.speakStringBlockingWait(F("Display ready")); // Maximum 32 characters supported for F("") 148 | } 149 | 150 | /* 151 | * Function is called for resize + connect too 152 | */ 153 | void drawGui(void) { 154 | BlueDisplay1.clearDisplay(COLOR16_BLUE); 155 | TouchButtonBlinkStartStop.drawButton(); 156 | } 157 | 158 | /* 159 | * Change doBlink flag as well as color and caption of the button. 160 | */ 161 | void doBlinkStartStop(BDButton *aTheTouchedButton __attribute__((unused)), int16_t aValue) { 162 | doBlink = aValue; 163 | /* 164 | * This debug output can also be recognized at the Arduino Serial Monitor 165 | */ 166 | BlueDisplay1.debug("\r\nDoBlink=", (uint8_t) doBlink); 167 | } 168 | -------------------------------------------------------------------------------- /examples/BlueDisplayExample/PinDefinitionsAndMore.h: -------------------------------------------------------------------------------- 1 | /* 2 | * PinDefinitionsAndMore.h 3 | * 4 | * Contains pin definitions for BlueDisplay examples for various platforms 5 | * 6 | * Copyright (C) 2020-2022 Armin Joachimsmeyer 7 | * armin.joachimsmeyer@gmail.com 8 | * 9 | * This file is part of BlueDisplay https://github.com/ArminJo/BlueDisplay. 10 | * 11 | * BlueDisplay is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 19 | * See the GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | * 24 | */ 25 | 26 | /* 27 | * Pin mapping table for different platforms 28 | * 29 | * Platform Tone HCSR04-Echo HCSR04-Trigger 30 | * ---------------------------------------------- 31 | * AVR 3 3 4 32 | * ESP8266 14 14 15 33 | * ESP832 15 26 27 34 | * BluePill 2 PB0 PB1 35 | */ 36 | 37 | #if defined(ESP8266) 38 | #define TONE_PIN 14 // labeled D5 39 | #define ANALOG_INPUT_PIN 0 40 | #define ECHO_IN_PIN 13 // labeled D7 41 | #define TRIGGER_OUT_PIN 15 // labeled D8 42 | 43 | #elif defined(ESP32) 44 | #define ANALOG_INPUT_PIN A0 // 36/VP 45 | #define ECHO_IN_PIN 26 46 | #define TRIGGER_OUT_PIN 27 47 | #define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer. 48 | // tone() is included in ESP32 core since 2.0.2 49 | # if !defined(ESP_ARDUINO_VERSION) 50 | #define ESP_ARDUINO_VERSION 0x010101 // Version 1.1.1 51 | # endif 52 | # if !defined(ESP_ARDUINO_VERSION_VAL) 53 | #define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) 54 | # endif 55 | #if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) 56 | #define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer. 57 | void tone(uint8_t aPinNumber, unsigned int aFrequency){ 58 | ledcAttachPin(aPinNumber, TONE_LEDC_CHANNEL); 59 | ledcWriteTone(TONE_LEDC_CHANNEL, aFrequency); 60 | } 61 | void tone(uint8_t aPinNumber, unsigned int aFrequency, unsigned long aDuration){ 62 | ledcAttachPin(aPinNumber, TONE_LEDC_CHANNEL); 63 | ledcWriteTone(TONE_LEDC_CHANNEL, aFrequency); 64 | delay(aDuration); 65 | ledcWriteTone(TONE_LEDC_CHANNEL, 0); 66 | } 67 | void noTone(uint8_t aPinNumber){ 68 | ledcWriteTone(TONE_LEDC_CHANNEL, 0); 69 | } 70 | #endif // ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) 71 | #define TONE_PIN 15 72 | 73 | #elif defined(ARDUINO_ARCH_SAM) 74 | #define ANALOG_INPUT_PIN A0 75 | #define ECHO_IN_PIN 4 76 | #define TRIGGER_OUT_PIN 5 77 | 78 | #define tone(...) void() // no tone() available 79 | #define noTone(a) void() 80 | #define TONE_PIN 42 // Dummy for examples using it 81 | 82 | #elif defined(STM32F1xx) || defined(__STM32F1__) 83 | // BluePill in 2 flavors 84 | // STM32F1xx is for "Generic STM32F1 series" from STM32 Boards from STM32 cores of Arduino Board manager 85 | // __STM32F1__is for "Generic STM32F103C series" from STM32F1 Boards (STM32duino.com) of Arduino Board manager 86 | #define TONE_PIN 2 87 | #define ANALOG_INPUT_PIN PA0 88 | #define ECHO_IN_PIN PB0 89 | #define TRIGGER_OUT_PIN PB1 90 | 91 | #else 92 | #define ECHO_IN_PIN 4 93 | #define TRIGGER_OUT_PIN 5 94 | #define TONE_PIN 3 // must be 3 to be compatible with talkie 95 | #define TONE_PIN_INVERTED 11 // must be 11 to be compatible with talkie 96 | #define ANALOG_INPUT_PIN A0 97 | #endif 98 | 99 | // for ESP32 LED_BUILTIN is defined as: static const uint8_t LED_BUILTIN 2 100 | #if !defined(LED_BUILTIN) && !defined(ESP32) 101 | #define LED_BUILTIN PB1 102 | #endif 103 | // On the Zero and others we switch explicitly to SerialUSB 104 | #if defined(ARDUINO_ARCH_SAMD) 105 | #define Serial SerialUSB 106 | // The Chinese SAMD21 M0-Mini clone has no led connected, if you connect it, it is on pin 24 like on the original board. 107 | // Attention! D2 and D4 are swapped on these boards 108 | //#undef LED_BUILTIN 109 | //#define LED_BUILTIN 25 // Or choose pin 25, it is the RX pin, but active low. 110 | #endif 111 | -------------------------------------------------------------------------------- /examples/BlueDisplayExample/TimeLib.h: -------------------------------------------------------------------------------- 1 | /* 2 | time.h - low level time and date functions 3 | */ 4 | 5 | /* 6 | July 3 2011 - fixed elapsedSecsThisWeek macro (thanks Vincent Valdy for this) 7 | - fixed daysToTime_t macro (thanks maniacbug) 8 | */ 9 | 10 | #ifndef _Time_h 11 | #ifdef __cplusplus 12 | #define _Time_h 13 | 14 | #include 15 | #ifndef __AVR__ 16 | #include // for __time_t_defined, but avr libc lacks sys/types.h 17 | #endif 18 | 19 | 20 | #if !defined(__time_t_defined) // avoid conflict with newlib or other posix libc 21 | typedef unsigned long time_t; 22 | #endif 23 | 24 | extern uint32_t prevMillis; 25 | 26 | // This ugly hack allows us to define C++ overloaded functions, when included 27 | // from within an extern "C", as newlib's sys/stat.h does. Actually it is 28 | // intended to include "time.h" from the C library (on ARM, but AVR does not 29 | // have that file at all). On Mac and Windows, the compiler will find this 30 | // "Time.h" instead of the C library "time.h", so we may cause other weird 31 | // and unpredictable effects by conflicting with the C library header "time.h", 32 | // but at least this hack lets us define C++ functions as intended. Hopefully 33 | // nothing too terrible will result from overriding the C library header?! 34 | extern "C++" { 35 | typedef enum {timeNotSet, timeNeedsSync, timeSet 36 | } timeStatus_t ; 37 | 38 | typedef enum { 39 | dowInvalid, dowSunday, dowMonday, dowTuesday, dowWednesday, dowThursday, dowFriday, dowSaturday 40 | } timeDayOfWeek_t; 41 | 42 | typedef enum { 43 | tmSecond, tmMinute, tmHour, tmWday, tmDay,tmMonth, tmYear, tmNbrFields 44 | } tmByteFields; 45 | 46 | typedef struct { 47 | uint8_t Second; 48 | uint8_t Minute; 49 | uint8_t Hour; 50 | uint8_t Wday; // day of week, sunday is day 1 51 | uint8_t Day; 52 | uint8_t Month; 53 | uint8_t Year; // offset from 1970; 54 | } tmElements_t, TimeElements, *tmElementsPtr_t; 55 | 56 | //convenience macros to convert to and from tm years 57 | #define tmYearToCalendar(Y) ((Y) + 1970) // full four digit year 58 | #define CalendarYrToTm(Y) ((Y) - 1970) 59 | #define tmYearToY2k(Y) ((Y) - 30) // offset is from 2000 60 | #define y2kYearToTm(Y) ((Y) + 30) 61 | 62 | typedef time_t(*getExternalTime)(); 63 | //typedef void (*setExternalTime)(const time_t); // not used in this version 64 | 65 | 66 | /*==============================================================================*/ 67 | /* Useful Constants */ 68 | #define SECS_PER_MIN ((time_t)(60UL)) 69 | #define SECS_PER_HOUR ((time_t)(3600UL)) 70 | #define SECS_PER_DAY ((time_t)(SECS_PER_HOUR * 24UL)) 71 | #define DAYS_PER_WEEK ((time_t)(7UL)) 72 | #define SECS_PER_WEEK ((time_t)(SECS_PER_DAY * DAYS_PER_WEEK)) 73 | #define SECS_PER_YEAR ((time_t)(SECS_PER_DAY * 365UL)) // TODO: ought to handle leap years 74 | #define SECS_YR_2000 ((time_t)(946684800UL)) // the time at the start of y2k 75 | 76 | /* Useful Macros for getting elapsed time */ 77 | #define numberOfSeconds(_time_) ((_time_) % SECS_PER_MIN) 78 | #define numberOfMinutes(_time_) (((_time_) / SECS_PER_MIN) % SECS_PER_MIN) 79 | #define numberOfHours(_time_) (((_time_) % SECS_PER_DAY) / SECS_PER_HOUR) 80 | #define dayOfWeek(_time_) ((((_time_) / SECS_PER_DAY + 4) % DAYS_PER_WEEK)+1) // 1 = Sunday 81 | #define elapsedDays(_time_) ((_time_) / SECS_PER_DAY) // this is number of days since Jan 1 1970 82 | #define elapsedSecsToday(_time_) ((_time_) % SECS_PER_DAY) // the number of seconds since last midnight 83 | // The following macros are used in calculating alarms and assume the clock is set to a date later than Jan 1 1971 84 | // Always set the correct time before setting alarms 85 | #define previousMidnight(_time_) (((_time_) / SECS_PER_DAY) * SECS_PER_DAY) // time at the start of the given day 86 | #define nextMidnight(_time_) (previousMidnight(_time_) + SECS_PER_DAY) // time at the end of the given day 87 | #define elapsedSecsThisWeek(_time_) (elapsedSecsToday(_time_) + ((dayOfWeek(_time_)-1) * SECS_PER_DAY)) // note that week starts on day 1 88 | #define previousSunday(_time_) ((_time_) - elapsedSecsThisWeek(_time_)) // time at the start of the week for the given time 89 | #define nextSunday(_time_) (previousSunday(_time_)+SECS_PER_WEEK) // time at the end of the week for the given time 90 | 91 | 92 | /* Useful Macros for converting elapsed time to a time_t */ 93 | #define minutesToTime_t ((M)) ( (M) * SECS_PER_MIN) 94 | #define hoursToTime_t ((H)) ( (H) * SECS_PER_HOUR) 95 | #define daysToTime_t ((D)) ( (D) * SECS_PER_DAY) // fixed on Jul 22 2011 96 | #define weeksToTime_t ((W)) ( (W) * SECS_PER_WEEK) 97 | 98 | /*============================================================================*/ 99 | /* time and date functions */ 100 | int hour(); // the hour now 101 | int hour(time_t t); // the hour for the given time 102 | int hourFormat12(); // the hour now in 12 hour format 103 | int hourFormat12(time_t t); // the hour for the given time in 12 hour format 104 | uint8_t isAM(); // returns true if time now is AM 105 | uint8_t isAM(time_t t); // returns true the given time is AM 106 | uint8_t isPM(); // returns true if time now is PM 107 | uint8_t isPM(time_t t); // returns true the given time is PM 108 | int minute(); // the minute now 109 | int minute(time_t t); // the minute for the given time 110 | int second(); // the second now 111 | int second(time_t t); // the second for the given time 112 | int day(); // the day now 113 | int day(time_t t); // the day for the given time 114 | int weekday(); // the weekday now (Sunday is day 1) 115 | int weekday(time_t t); // the weekday for the given time 116 | int month(); // the month now (Jan is month 1) 117 | int month(time_t t); // the month for the given time 118 | int year(); // the full four digit year: (2009, 2010 etc) 119 | int year(time_t t); // the year for the given time 120 | 121 | time_t now(); // return the current time as seconds since Jan 1 1970 122 | void setTime(time_t t); 123 | void setTime(int hr,int min,int sec,int day, int month, int yr); 124 | void adjustTime(long adjustment); 125 | 126 | /* date strings */ 127 | #define dt_MAX_STRING_LEN 9 // length of longest date string (excluding terminating null) 128 | char* monthStr(uint8_t month); 129 | char* dayStr(uint8_t day); 130 | char* monthShortStr(uint8_t month); 131 | char* dayShortStr(uint8_t day); 132 | 133 | /* time sync functions */ 134 | timeStatus_t timeStatus(); // indicates if time has been set and recently synchronized 135 | void setSyncProvider( getExternalTime getTimeFunction); // identify the external time provider 136 | void setSyncInterval(time_t interval); // set the number of seconds between re-sync 137 | 138 | /* low level functions to convert to and from system time */ 139 | void breakTime(time_t time, tmElements_t &tm); // break time_t into elements 140 | time_t makeTime(const tmElements_t &tm); // convert time elements into time_t 141 | 142 | } // extern "C++" 143 | #endif // __cplusplus 144 | #endif /* _Time_h */ 145 | -------------------------------------------------------------------------------- /examples/ChartForMHZ19_CO2/CO2LoggerAndChart.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CO2LoggerAndChart.h 3 | * 4 | * 5 | * Copyright (C) 2024 Armin Joachimsmeyer 6 | * armin.joachimsmeyer@gmail.com 7 | * 8 | * This program is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11 | * See the GNU General Public License for more details. 12 | 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program. If not, see . 15 | * 16 | */ 17 | 18 | #ifndef _CO2_LOGGER_AND_CHART_H 19 | #define _CO2_LOGGER_AND_CHART_H 20 | 21 | #include 22 | #include "TimeLib.h" // for useful macros like SECS_PER_MIN 23 | #include "BlueDisplay.h" 24 | 25 | #define CHART_BACKGROUND_COLOR COLOR16_WHITE 26 | #define CHART_DATA_COLOR COLOR16_RED 27 | #define CHART_AXES_COLOR COLOR16_BLUE 28 | #define CHART_GRID_COLOR COLOR16_GREEN 29 | #define CHART_DATA_COLOR COLOR16_RED 30 | #define CHART_TEXT_COLOR COLOR16_BLACK 31 | 32 | #define CO2_BASE_VALUE 400L 33 | #define CO2_COMPRESSION_FACTOR 5L // value 1 -> 405, 2 -> 410 etc. 34 | /* 35 | * Even with initDisplay() called from main loop we only have 1140 bytes available for application 36 | */ 37 | #define CO2_ARRAY_SIZE 1152L // 0x480 1152-> 4 days, 1440->5 days at 5 minutes / sample 38 | #define NUMBER_OF_DAYS_IN_BUFFER 4 39 | 40 | #define TIME_ADJUSTMENT 0 41 | //#define TIME_ADJUSTMENT SECS_PER_HOUR // To be subtracted from received timestamp 42 | #define MILLIS_IN_ONE_SECOND 1000L 43 | // sNextStorageMillis is required by CO2LoggerAndChart.hpp for toast at connection startup 44 | extern uint32_t sNextStorageMillis; // If not connected first storage in 1 after boot. 45 | 46 | #define BRIGHTNESS_LOW 2 47 | #define BRIGHTNESS_MIDDLE 1 48 | #define BRIGHTNESS_HIGH 0 49 | #define START_BRIGHTNESS BRIGHTNESS_HIGH 50 | extern uint8_t sCurrentBrightness; 51 | 52 | /* 53 | * Is intended to be called by setup 54 | */ 55 | void InitCo2LoggerAndChart(); 56 | 57 | /* 58 | * Is intended to be called by main loop 59 | */ 60 | bool storeCO2ValuePeriodically(uint16_t aCO2Value, const uint32_t aStoragePeriodMillis); 61 | 62 | /* 63 | * Use this instead of delay(), this checks the BlueDisplay communication and makes the program reactive 64 | */ 65 | void delayMillisWithHandleEventAndFlags(unsigned long aDelayMillis); 66 | /* 67 | * End prematurely, if event received 68 | */ 69 | bool delayMillisWithCheckForEventAndFlags(unsigned long aDelayMillis); 70 | /* 71 | * Checks for BlueDisplay events and returns true if event happened, 72 | * which may introduce an unknown delay the program might not be able to handle 73 | */ 74 | bool handleEventAndFlags(); 75 | 76 | /*********************** 77 | * Internal functions 78 | **********************/ 79 | /* 80 | * Array is in section .noinit 81 | * Therefore check checksum before initializing it after reboot 82 | */ 83 | void initializeCO2Array(); 84 | 85 | /* 86 | * aCO2Value is (CO2[ppm] - 400) / 5 87 | */ 88 | void writeToCO2Array(uint8_t aCO2Value); 89 | 90 | /* 91 | * This function is not called by event callback, it is called from main loop 92 | * signalInitDisplay() is called by event callback, which only sets a flag for the main loop. 93 | * This helps reducing stack usage, 94 | * !!!but BlueDisplay1.isConnectionEstablished() cannot be used as indicator for initialized BD data, without further handling!!! 95 | */ 96 | void initDisplay(void); 97 | void drawDisplay(); 98 | void initCO2Chart(); 99 | 100 | /* 101 | * Print difference between next storage time and now(), which is set by caller :-) 102 | * Serial output is displayed as an Android toast 103 | */ 104 | void printTimeToNextStorage(); 105 | void changeBrightness(); 106 | void drawCO2Chart(); 107 | void printCO2Value(); 108 | void printTime(); 109 | #endif // _CO2_LOGGER_AND_CHART_H 110 | -------------------------------------------------------------------------------- /examples/ChartForMHZ19_CO2/LiquidCrystal_I2C.h: -------------------------------------------------------------------------------- 1 | //YWROBOT 2 | #ifndef LiquidCrystal_I2C_h 3 | #define LiquidCrystal_I2C_h 4 | 5 | #include 6 | #include "Print.h" 7 | #if !defined(USE_SOFT_I2C_MASTER) && !defined(USE_SOFT_WIRE) 8 | #include 9 | #endif 10 | 11 | // commands 12 | #define LCD_CLEARDISPLAY 0x01 13 | #define LCD_RETURNHOME 0x02 14 | #define LCD_ENTRYMODESET 0x04 15 | #define LCD_DISPLAYCONTROL 0x08 16 | #define LCD_CURSORSHIFT 0x10 17 | #define LCD_FUNCTIONSET 0x20 18 | #define LCD_SETCGRAMADDR 0x40 19 | #define LCD_SETDDRAMADDR 0x80 20 | 21 | // flags for display entry mode 22 | #define LCD_ENTRYRIGHT 0x00 23 | #define LCD_ENTRYLEFT 0x02 24 | #define LCD_ENTRYSHIFTINCREMENT 0x01 25 | #define LCD_ENTRYSHIFTDECREMENT 0x00 26 | 27 | // flags for display on/off control 28 | #define LCD_DISPLAYON 0x04 29 | #define LCD_DISPLAYOFF 0x00 30 | #define LCD_CURSORON 0x02 31 | #define LCD_CURSOROFF 0x00 32 | #define LCD_BLINKON 0x01 33 | #define LCD_BLINKOFF 0x00 34 | 35 | // flags for display/cursor shift 36 | #define LCD_DISPLAYMOVE 0x08 37 | #define LCD_CURSORMOVE 0x00 38 | #define LCD_MOVERIGHT 0x04 39 | #define LCD_MOVELEFT 0x00 40 | 41 | // flags for function set 42 | #define LCD_8BITMODE 0x10 43 | #define LCD_4BITMODE 0x00 44 | #define LCD_2LINE 0x08 45 | #define LCD_1LINE 0x00 46 | #define LCD_5x10DOTS 0x04 47 | #define LCD_5x8DOTS 0x00 48 | 49 | // flags for backlight control 50 | #define LCD_BACKLIGHT 0x08 51 | #define LCD_NOBACKLIGHT 0x00 52 | 53 | #define En 0b00000100 // Enable bit 54 | #define Rw 0b00000010 // Read/Write bit 55 | #define Rs 0b00000001 // Register select bit 56 | 57 | class LiquidCrystal_I2C : public Print { 58 | public: 59 | LiquidCrystal_I2C(uint8_t lcd_Addr,uint8_t lcd_cols,uint8_t lcd_rows); 60 | void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS ); 61 | void clear(); 62 | void home(); 63 | void noDisplay(); 64 | void display(); 65 | void noBlink(); 66 | void blink(); 67 | void noCursor(); 68 | void cursor(); 69 | void scrollDisplayLeft(); 70 | void scrollDisplayRight(); 71 | void printLeft(); 72 | void printRight(); 73 | void leftToRight(); 74 | void rightToLeft(); 75 | void shiftIncrement(); 76 | void shiftDecrement(); 77 | void noBacklight(); 78 | void backlight(); 79 | void autoscroll(); 80 | void noAutoscroll(); 81 | void createChar(uint8_t, uint8_t[]); 82 | void createChar(uint8_t location, const char *charmap); 83 | // Example: const char bell[8] PROGMEM = {B00100,B01110,B01110,B01110,B11111,B00000,B00100,B00000}; 84 | 85 | void setCursor(uint8_t, uint8_t); 86 | size_t write(uint8_t); 87 | void command(uint8_t); 88 | void init(); 89 | void oled_init(); 90 | 91 | ////compatibility API function aliases 92 | void blink_on(); // alias for blink() 93 | void blink_off(); // alias for noBlink() 94 | void cursor_on(); // alias for cursor() 95 | void cursor_off(); // alias for noCursor() 96 | void setBacklight(uint8_t new_val); // alias for backlight() and nobacklight() 97 | void load_custom_character(uint8_t char_num, uint8_t *rows); // alias for createChar() 98 | void printstr(const char[]); 99 | 100 | ////Unsupported API functions (not implemented in this library) 101 | uint8_t status(); 102 | void setContrast(uint8_t new_val); 103 | uint8_t keypad(); 104 | void setDelay(int,int); 105 | void on(); 106 | void off(); 107 | uint8_t init_bargraph(uint8_t graphtype); 108 | void draw_horizontal_graph(uint8_t row, uint8_t column, uint8_t len, uint8_t pixel_col_end); 109 | void draw_vertical_graph(uint8_t row, uint8_t column, uint8_t len, uint8_t pixel_col_end); 110 | 111 | 112 | private: 113 | void init_priv(); 114 | void send(uint8_t, uint8_t); 115 | void write4bits(uint8_t); 116 | void expanderWrite(uint8_t); 117 | void pulseEnable(uint8_t); 118 | uint8_t _Addr; 119 | uint8_t _displayfunction; 120 | uint8_t _displaycontrol; 121 | uint8_t _displaymode; 122 | uint8_t _numlines; 123 | bool _oled; 124 | uint8_t _cols; 125 | uint8_t _rows; 126 | uint8_t _backlightval; 127 | }; 128 | 129 | #endif 130 | -------------------------------------------------------------------------------- /examples/ChartForMHZ19_CO2/MHZ19.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MHZ19.h 3 | * 4 | * Arduino library to control a MH-Z19C CO2 sensor. Tested with firmware version 5.2 and V5.12 5 | * Based on - https://github.com/WifWaf/MH-Z19 6 | * - https://revspace.nl/MH-Z19B 7 | * - 4 Winsen Datasheets https://datasheet.lcsc.com/szlcsc/1901021600_Zhengzhou-Winsen-Elec-Tech-MH-Z19_C242514.pdf 8 | * 9 | * 10 | * Copyright (C) 2022-2024 Armin Joachimsmeyer 11 | * armin.joachimsmeyer@gmail.com 12 | * 13 | * This file is part of MHZ19 https://github.com/ArminJo/MH-Z19. 14 | * 15 | * MHZ19 is free software: you can redistribute it and/or modify 16 | * it under the terms of the GNU General Public License as published by 17 | * the Free Software Foundation, either version 3 of the License, or 18 | * (at your option) any later version. 19 | * 20 | * This program is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 23 | * See the GNU General Public License for more details. 24 | 25 | * You should have received a copy of the GNU General Public License 26 | * along with this program. If not, see . 27 | * 28 | */ 29 | #ifndef MHZ19_H 30 | #define MHZ19_H 31 | 32 | #include 33 | 34 | //#define MHZ19_USE_MINIMAL_RAM // removes all field from the class, which are not required for just reading CO2 value 35 | 36 | #define MHZ19_BAUDRATE 9600 // Device to MH-Z19 Serial baudrate (should not be changed) -> around 1000 bytes per second 37 | #define MHZ19_DATA_LEN 9 // Data protocol length 38 | #define MHZ19_RESPONSE_TIMEOUT_MILLIS 500 // 1/2 second timeout period for MH-Z19C response 39 | #define MHZ19_DATASET_DURATION_MILLIS MHZ19_DATA_LEN // Data protocol duration 40 | 41 | // Constants for SETABC_ON_OFF command 42 | #define MHZ19_ABC_PERIOD_OFF 0x00 43 | #define MHZ19_ABC_PERIOD_DEF 0xA0 44 | 45 | #define TEMPERATURE_ADJUST_CONSTANT 40 // This is the constant value one get with command GETEMPERATURE_OFFSET. 46 | 47 | class MHZ19 { 48 | public: 49 | typedef enum { 50 | RECOVERY_RESET = 0x78, // Recovery Reset - Changes operation mode and performs MCU reset 51 | SETABC_ON_OFF = 0x79, // Turns SETABC_ON_OFF (Automatic Baseline Correction) logic on or off (b[3] == 0xA0 - on, 0x00 - off) - mentioned in datasheet 52 | GETABC = 0x7D, // Get SETABC_ON_OFF logic status (1 - enabled, 0 - disabled) 53 | PERIOD = 0x7E, // Set (b[3] = 2) and get measurement period - not from datasheet 54 | CO2RAW = 0x84, // Raw CO2 ADC value and temperature compensated zero ADC value - not from datasheet 55 | CO2_AND_TEMPERATURE = 0x85, // Smoothed temperature ADC value, CO2 level - not from datasheet 56 | CO2MASKED_AND_TEMP = 0x86, // CO2 masked at 500 in the first minute, temperature integer - not from datasheet 57 | SETZERO_CALIBRATION = 0x87, // Zero point calibration (like connecting HD to ground) 58 | SETSPAN_CALIBRATION = 0x88, // Span calibration Note: do ZERO calibration before span calibration 59 | SETRANGE = 0x99, // Sets sensor range. Note that parameter byte numbers are taken from the Chinese and not the English datasheet 60 | GETRANGE = 0x9B, // Get Range 61 | GETCO2 = 0x9C, // Get CO2 returns the same value as other CO2 62 | GETFIRMWARE_VERSION = 0xA0, // Get firmware version - not from datasheet 63 | GETLAST_RESPONSE = 0xA2, // Get Last Response - not from datasheet 64 | GETEMPERATURE_OFFSET = 0xA3 // Get temperature offset - returns constant 40 - not from datasheet 65 | } MHZ19_command_t; 66 | 67 | /* 68 | * The serial connections 69 | */ 70 | Stream *SerialToMHZ19; 71 | Print *SerialForDebug; 72 | 73 | // Possible values of member variable errorCode 74 | typedef enum { 75 | RESULT_NULL = 0, RESULT_OK = 1, RESULT_TIMEOUT = 2, RESULT_MATCH = 3, RESULT_CHECKSUM = 4 76 | } Error_Code_t; 77 | Error_Code_t errorCode; // Holds last received error code from recieveResponse() 78 | 79 | char VersionString[5]; // 0512, 80 | 81 | 82 | #define ABC_COUNTER_MAX 143 83 | /* 84 | * Results of command 0x85 CO2_AND_TEMPERATURE 85 | */ 86 | float TemperatureFloat; // Seems to be around 2.00 degree for 2 seconds and 4.4 degree for 1 second period higher than environment. 87 | uint16_t CO2Unmasked; // Is displayed even at first minute. Values are also clipped between 405 and 5000. V5.12 value was seen to go down to 175. 88 | #if !defined(MHZ19_USE_MINIMAL_RAM) 89 | uint16_t MinimumLightADC; 90 | #endif 91 | 92 | bool AutoBaselineCorrectionEnabled; 93 | 94 | #if !defined(MHZ19_USE_MINIMAL_RAM) 95 | uint16_t Version; 96 | uint8_t VersionMajor; 97 | uint8_t VersionMinor; 98 | /* 99 | * Results of command 0x84 CO2RAW 100 | */ 101 | uint16_t CO2RawADC; 102 | uint16_t CO2RawTemperatureCompensatedBaseADC; // v5.2 The ADC Value of 410 ppm ??? compensated by temperature. V5.12 constant 32000. 103 | int16_t CO2RawADCDelta; // v5.2 CO2RawTemperatureCompensatedBaseADC - CO2RawADC, V5.12 CO2RawADC - CO2RawTemperatureCompensatedBaseADC 104 | uint16_t Unknown2; 105 | 106 | /* 107 | * Results of command 0x86 CO2MASKED_AND_TEMP 108 | */ 109 | uint16_t CO2; // == CO2Unmasked, except that it is displayed / masked as 500 for the first minute. Values are clipped between 405 and 5000. 110 | int8_t Temperature; 111 | uint8_t ABCCounter; // Is incremented by MHZ19 every 10 minutes. Range is from 0 to 143 112 | 113 | 114 | /* 115 | * Results of other commands 116 | */ 117 | uint16_t SensorRange; // 5.12 is 5000 118 | uint16_t CO2Alternate; // 5.12 Values are clipped at 400. 119 | uint16_t Period; // 5.12 is 0 120 | 121 | bool SerialDebugOutputIsEnabled = false; // if true, SerialForDebug must be set (by enableDebug()) 122 | #endif 123 | 124 | /* 125 | * The send and receive buffers 126 | */ 127 | #define COMMAND_RECEIVE_INDEX 1 // Index of command in ReceivedResponse 128 | #define COMMAND_SEND_INDEX 2 // Index of command in CommandToSend 129 | #define CHECKSUM_INDEX 8 // Index of checksum in CommandToSend and ReceivedResponse 130 | uint8_t CommandToSend[MHZ19_DATA_LEN]; // Array for commands to be sent 131 | uint8_t ReceivedResponse[MHZ19_DATA_LEN]; // Array for response 132 | 133 | void setSerial(Stream *aStream); 134 | bool begin(Stream *aStream); 135 | bool begin(Stream &aStream); // use & to be compatible to other libraries 136 | 137 | 138 | uint8_t computeChecksum(uint8_t *aArray); 139 | bool processCommand(MHZ19_command_t aCommand, bool aDoNotWaitForResponse = false); 140 | bool readResponse(); 141 | bool readCO2UnmaskedAndTemperatureFloat(); 142 | bool readVersion(); 143 | bool readABC(); // Reads SETABC_ON_OFF-Status using command 125 / 0x7D 144 | #if !defined(MHZ19_USE_MINIMAL_RAM) 145 | void enableDebug(Print *aSerialForDebugOutput); 146 | void disableDebug(); 147 | bool readCO2MaskedTemperatureIntAndABCCounter(); 148 | bool readRange(); 149 | bool readCO2Alternate(); 150 | bool readPeriod(); 151 | bool readCO2Raw(); 152 | void setSpanCalibration(uint16_t aValueOfCurrentCO2); 153 | void setRange(uint16_t aRange); 154 | void setPeriod(); 155 | #endif 156 | 157 | void setZeroCalibration(); 158 | void setAutoCalibration(bool aSwitchOn); 159 | 160 | void printErrorCode(Print *aSerial); 161 | void printErrorMessage(Print *aSerial); 162 | 163 | void printCommand(MHZ19_command_t aCommand, Print *aSerial); 164 | 165 | }; 166 | #endif 167 | -------------------------------------------------------------------------------- /examples/ChartForMHZ19_CO2/SoftI2CMasterConfig.h: -------------------------------------------------------------------------------- 1 | /* Arduino SoftI2C library. 2 | * 3 | * SoftI2CMasterConfig.h 4 | * 5 | * This contains a sample configuration setting for SoftI2CMaster.h 6 | * The existence of this file can trigger the use of SoftI2CMaster by usage of "#if __has_include("SoftI2CMasterConfig.h")", 7 | * which saves 2110 bytes program memory and 200 bytes RAM compared with Arduino Wire. 8 | * 9 | * Copyright (C) 2022, Armin Joachimsmeyer 10 | * 11 | * This file is part of SoftI2CMaster https://github.com/felias-fogg/SoftI2CMaster. 12 | * 13 | * This Library is free software: you can redistribute it and/or modify 14 | * it under the terms of the GNU General Public License as published by 15 | * the Free Software Foundation, either version 3 of the License, or 16 | * (at your option) any later version. 17 | * 18 | * This Library is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 21 | * GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with the Arduino I2cMaster Library. If not, see 25 | * . 26 | */ 27 | 28 | /* In order to use the library, you need to define SDA_PIN, SCL_PIN, 29 | * SDA_PORT and SCL_PORT before including this file. Have a look at 30 | * http://www.arduino.cc/en/Reference/PortManipulation for finding out 31 | * which values to use. For example, if you use digital pin 3 (corresponding 32 | * to PD3) for SDA and digital pin 13 (corresponding to PB5) 33 | * for SCL on a standard Arduino, 34 | * you have to use the following definitions: 35 | * #define SDA_PIN 3 36 | * #define SDA_PORT PORTD 37 | * #define SCL_PIN 5 38 | * #define SCL_PORT PORTB 39 | * 40 | * Alternatively, you can define the compile time constant I2C_HARDWARE, 41 | * in which case the TWI hardware is used. In this case you have to use 42 | * the standard SDA/SCL pins (and, of course, the chip needs to support 43 | * this). 44 | * 45 | * You can also define the following constants (see also below): 46 | ' - I2C_PULLUP = 1 meaning that internal pullups should be used 47 | * - I2C_CPUFREQ, when changing CPU clock frequency dynamically 48 | * - I2C_FASTMODE = 1 meaning that the I2C bus allows speeds up to 400 kHz 49 | * - I2C_SLOWMODE = 1 meaning that the I2C bus will allow only up to 25 kHz 50 | * - I2C_NOINTERRUPT = 1 in order to prohibit interrupts while 51 | * communicating (see below). This can be useful if you use the library 52 | * for communicating with SMbus devices, which have timeouts. 53 | * Note, however, that interrupts are disabled from issuing a start condition 54 | * until issuing a stop condition. So use this option with care! 55 | * - I2C_TIMEOUT = 0...10000 msec in order to return from the I2C functions 56 | * in case of a I2C bus lockup (i.e., SCL constantly low). 0 means no timeout. 57 | * - I2C_MAXWAIT = 0...32767 number of retries in i2c_start_wait. 0 means never stop. 58 | */ 59 | #ifndef _SOFT_I2C_MASTER_CONFIG_H 60 | #define _SOFT_I2C_MASTER_CONFIG_H 61 | 62 | //#define SCL_PIN 5 63 | //#define SCL_PORT PORTC 64 | //#define SDA_PIN 4 65 | //#define SDA_PORT PORTC 66 | #define I2C_HARDWARE 1 // use I2C Hardware 67 | #define I2C_PULLUP 1 68 | //#define I2C_TIMEOUT 5000 // costs 350 bytes 69 | #define I2C_FASTMODE 1 70 | 71 | #endif // _SOFT_I2C_MASTER_CONFIG_H 72 | -------------------------------------------------------------------------------- /examples/ChartForMHZ19_CO2/TimeLib.h: -------------------------------------------------------------------------------- 1 | /* 2 | time.h - low level time and date functions 3 | */ 4 | 5 | /* 6 | July 3 2011 - fixed elapsedSecsThisWeek macro (thanks Vincent Valdy for this) 7 | - fixed daysToTime_t macro (thanks maniacbug) 8 | */ 9 | 10 | #ifndef _Time_h 11 | #ifdef __cplusplus 12 | #define _Time_h 13 | 14 | #include 15 | #ifndef __AVR__ 16 | #include // for __time_t_defined, but avr libc lacks sys/types.h 17 | #endif 18 | 19 | 20 | #if !defined(__time_t_defined) // avoid conflict with newlib or other posix libc 21 | typedef unsigned long time_t; 22 | #endif 23 | 24 | extern uint32_t prevMillis; 25 | 26 | // This ugly hack allows us to define C++ overloaded functions, when included 27 | // from within an extern "C", as newlib's sys/stat.h does. Actually it is 28 | // intended to include "time.h" from the C library (on ARM, but AVR does not 29 | // have that file at all). On Mac and Windows, the compiler will find this 30 | // "Time.h" instead of the C library "time.h", so we may cause other weird 31 | // and unpredictable effects by conflicting with the C library header "time.h", 32 | // but at least this hack lets us define C++ functions as intended. Hopefully 33 | // nothing too terrible will result from overriding the C library header?! 34 | extern "C++" { 35 | typedef enum {timeNotSet, timeNeedsSync, timeSet 36 | } timeStatus_t ; 37 | 38 | typedef enum { 39 | dowInvalid, dowSunday, dowMonday, dowTuesday, dowWednesday, dowThursday, dowFriday, dowSaturday 40 | } timeDayOfWeek_t; 41 | 42 | typedef enum { 43 | tmSecond, tmMinute, tmHour, tmWday, tmDay,tmMonth, tmYear, tmNbrFields 44 | } tmByteFields; 45 | 46 | typedef struct { 47 | uint8_t Second; 48 | uint8_t Minute; 49 | uint8_t Hour; 50 | uint8_t Wday; // day of week, sunday is day 1 51 | uint8_t Day; 52 | uint8_t Month; 53 | uint8_t Year; // offset from 1970; 54 | } tmElements_t, TimeElements, *tmElementsPtr_t; 55 | 56 | //convenience macros to convert to and from tm years 57 | #define tmYearToCalendar(Y) ((Y) + 1970) // full four digit year 58 | #define CalendarYrToTm(Y) ((Y) - 1970) 59 | #define tmYearToY2k(Y) ((Y) - 30) // offset is from 2000 60 | #define y2kYearToTm(Y) ((Y) + 30) 61 | 62 | typedef time_t(*getExternalTime)(); 63 | //typedef void (*setExternalTime)(const time_t); // not used in this version 64 | 65 | 66 | /*==============================================================================*/ 67 | /* Useful Constants */ 68 | #define SECS_PER_MIN ((time_t)(60UL)) 69 | #define SECS_PER_HOUR ((time_t)(3600UL)) 70 | #define SECS_PER_DAY ((time_t)(SECS_PER_HOUR * 24UL)) 71 | #define DAYS_PER_WEEK ((time_t)(7UL)) 72 | #define SECS_PER_WEEK ((time_t)(SECS_PER_DAY * DAYS_PER_WEEK)) 73 | #define SECS_PER_YEAR ((time_t)(SECS_PER_DAY * 365UL)) // TODO: ought to handle leap years 74 | #define SECS_YR_2000 ((time_t)(946684800UL)) // the time at the start of y2k 75 | 76 | /* Useful Macros for getting elapsed time */ 77 | #define numberOfSeconds(_time_) ((_time_) % SECS_PER_MIN) 78 | #define numberOfMinutes(_time_) (((_time_) / SECS_PER_MIN) % SECS_PER_MIN) 79 | #define numberOfHours(_time_) (((_time_) % SECS_PER_DAY) / SECS_PER_HOUR) 80 | #define dayOfWeek(_time_) ((((_time_) / SECS_PER_DAY + 4) % DAYS_PER_WEEK)+1) // 1 = Sunday 81 | #define elapsedDays(_time_) ((_time_) / SECS_PER_DAY) // this is number of days since Jan 1 1970 82 | #define elapsedSecsToday(_time_) ((_time_) % SECS_PER_DAY) // the number of seconds since last midnight 83 | // The following macros are used in calculating alarms and assume the clock is set to a date later than Jan 1 1971 84 | // Always set the correct time before setting alarms 85 | #define previousMidnight(_time_) (((_time_) / SECS_PER_DAY) * SECS_PER_DAY) // time at the start of the given day 86 | #define nextMidnight(_time_) (previousMidnight(_time_) + SECS_PER_DAY) // time at the end of the given day 87 | #define elapsedSecsThisWeek(_time_) (elapsedSecsToday(_time_) + ((dayOfWeek(_time_)-1) * SECS_PER_DAY)) // note that week starts on day 1 88 | #define previousSunday(_time_) ((_time_) - elapsedSecsThisWeek(_time_)) // time at the start of the week for the given time 89 | #define nextSunday(_time_) (previousSunday(_time_)+SECS_PER_WEEK) // time at the end of the week for the given time 90 | 91 | 92 | /* Useful Macros for converting elapsed time to a time_t */ 93 | #define minutesToTime_t ((M)) ( (M) * SECS_PER_MIN) 94 | #define hoursToTime_t ((H)) ( (H) * SECS_PER_HOUR) 95 | #define daysToTime_t ((D)) ( (D) * SECS_PER_DAY) // fixed on Jul 22 2011 96 | #define weeksToTime_t ((W)) ( (W) * SECS_PER_WEEK) 97 | 98 | /*============================================================================*/ 99 | /* time and date functions */ 100 | int hour(); // the hour now 101 | int hour(time_t t); // the hour for the given time 102 | int hourFormat12(); // the hour now in 12 hour format 103 | int hourFormat12(time_t t); // the hour for the given time in 12 hour format 104 | uint8_t isAM(); // returns true if time now is AM 105 | uint8_t isAM(time_t t); // returns true the given time is AM 106 | uint8_t isPM(); // returns true if time now is PM 107 | uint8_t isPM(time_t t); // returns true the given time is PM 108 | int minute(); // the minute now 109 | int minute(time_t t); // the minute for the given time 110 | int second(); // the second now 111 | int second(time_t t); // the second for the given time 112 | int day(); // the day now 113 | int day(time_t t); // the day for the given time 114 | int weekday(); // the weekday now (Sunday is day 1) 115 | int weekday(time_t t); // the weekday for the given time 116 | int month(); // the month now (Jan is month 1) 117 | int month(time_t t); // the month for the given time 118 | int year(); // the full four digit year: (2009, 2010 etc) 119 | int year(time_t t); // the year for the given time 120 | 121 | time_t now(); // return the current time as seconds since Jan 1 1970 122 | void setTime(time_t t); 123 | void setTime(int hr,int min,int sec,int day, int month, int yr); 124 | void adjustTime(long adjustment); 125 | 126 | /* date strings */ 127 | #define dt_MAX_STRING_LEN 9 // length of longest date string (excluding terminating null) 128 | char* monthStr(uint8_t month); 129 | char* dayStr(uint8_t day); 130 | char* monthShortStr(uint8_t month); 131 | char* dayShortStr(uint8_t day); 132 | 133 | /* time sync functions */ 134 | timeStatus_t timeStatus(); // indicates if time has been set and recently synchronized 135 | void setSyncProvider( getExternalTime getTimeFunction); // identify the external time provider 136 | void setSyncInterval(time_t interval); // set the number of seconds between re-sync 137 | 138 | /* low level functions to convert to and from system time */ 139 | void breakTime(time_t time, tmElements_t &tm); // break time_t into elements 140 | time_t makeTime(const tmElements_t &tm); // convert time elements into time_t 141 | 142 | } // extern "C++" 143 | #endif // __cplusplus 144 | #endif /* _Time_h */ 145 | -------------------------------------------------------------------------------- /examples/ManySlidersAndButtons/ManySlidersAndButtonsHelper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ManySlidersAndButtonsHelper.h 3 | * 4 | * Definitions for helper code for ManySlidersAndButtons example. 5 | * 6 | * Copyright (C) 2025 Armin Joachimsmeyer 7 | * armin.joachimsmeyer@gmail.com 8 | * 9 | * This file is part of BlueDisplay https://github.com/ArminJo/Arduino-BlueDisplay. 10 | * 11 | * BlueDisplay is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 19 | * See the GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | * 24 | */ 25 | 26 | #ifndef _MANY_SLIDER_AND_BUTTONS_HELPER_H 27 | #define _MANY_SLIDER_AND_BUTTONS_HELPER_H 28 | 29 | /******************** 30 | * SLIDERS 31 | ********************/ 32 | #if !defined(SLIDER_BAR_WIDTH) 33 | #define SLIDER_BAR_WIDTH 12 34 | #endif 35 | #if !defined(SLIDER_BAR_LENGTH) 36 | #define SLIDER_BAR_LENGTH 128 37 | #endif 38 | #if !defined(SLIDER_CAPTION_SIZE) 39 | #define SLIDER_CAPTION_SIZE 7 40 | #endif 41 | #if !defined(SLIDER_CAPTION_MARGIN) 42 | #define SLIDER_CAPTION_MARGIN 2 43 | #endif 44 | #if !defined(SLIDER_BAR_COLOR) 45 | #define SLIDER_BAR_COLOR COLOR16_GREEN 46 | #endif 47 | #if !defined(SLIDER_BAR_BG_COLOR) 48 | #define SLIDER_BAR_BG_COLOR COLOR16_YELLOW 49 | #endif 50 | #if !defined(SLIDER_CAPTION_COLOR) 51 | #define SLIDER_CAPTION_COLOR COLOR16_BLACK 52 | #endif 53 | #if !defined(SLIDER_VALUE_COLOR) 54 | #define SLIDER_VALUE_COLOR COLOR16_BLUE 55 | #endif 56 | #if !defined(SLIDER_CAPTION_BG_COLOR) 57 | #define SLIDER_CAPTION_BG_COLOR DISPLAY_BACKGROUND_COLOR 58 | #endif 59 | 60 | /* 61 | * PROGMEM caption strings for sliders 62 | */ 63 | const char sString_ParameterValue1[] PROGMEM = "Parameter value 1"; 64 | const char sString_ParameterValue2[] PROGMEM = "Parameter value 2"; 65 | const char sString_ParameterValue3[] PROGMEM = "Parameter value 3"; 66 | const char sString_ParameterValue4[] PROGMEM = "Parameter value 4"; 67 | const char sString_ParameterValue5[] PROGMEM = "Parameter value 5"; 68 | const char sString_ParameterValue6[] PROGMEM = "Parameter value 6"; 69 | const char sString_ParameterValue7[] PROGMEM = "Parameter value 7"; 70 | const char sString_ParameterValue8[] PROGMEM = "Parameter value 8"; 71 | const char sString_ParameterValue9[] PROGMEM = "Parameter value 9"; 72 | const char sString_ParameterValue10[] PROGMEM = "Parameter value 10"; 73 | const char sString_ParameterValue11[] PROGMEM = "Parameter value 11"; 74 | const char sString_ParameterValue12[] PROGMEM = "Parameter value 12"; 75 | const char sString_ParameterValue13[] PROGMEM = "Parameter value 13"; 76 | const char sString_ParameterValue14[] PROGMEM = "Parameter value 14"; 77 | const char sString_ParameterValue15[] PROGMEM = "Parameter value 15"; 78 | const char sString_ParameterValue16[] PROGMEM = "Parameter value 16"; 79 | 80 | const char sString_AnalogValue1[] PROGMEM = "Analog value 1"; 81 | const char sString_AnalogValue2[] PROGMEM = "Analog value 2"; 82 | const char sString_AnalogValue3[] PROGMEM = "Analog value 3"; 83 | const char sString_AnalogValue4[] PROGMEM = "Analog value 4"; 84 | const char sString_AnalogValue5[] PROGMEM = "Analog value 5"; 85 | const char sString_AnalogValue6[] PROGMEM = "Analog value 6"; 86 | const char sString_AnalogValue7[] PROGMEM = "Analog value 7"; 87 | const char sString_AnalogValue8[] PROGMEM = "Analog value 8"; 88 | const char sString_AnalogValue9[] PROGMEM = "Analog value 9"; 89 | const char sString_AnalogValue10[] PROGMEM = "Analog value 10"; 90 | const char sString_AnalogValue11[] PROGMEM = "Analog value 11"; 91 | const char sString_AnalogValue12[] PROGMEM = "Analog value 12"; 92 | const char sString_AnalogValue13[] PROGMEM = "Analog value 13"; 93 | const char sString_AnalogValue14[] PROGMEM = "Analog value 14"; 94 | const char sString_AnalogValue15[] PROGMEM = "Analog value 15"; 95 | const char sString_AnalogValue16[] PROGMEM = "Analog value 16"; 96 | 97 | /** 98 | * This structure holds the values, which are different for each slider created 99 | */ 100 | struct SliderStaticInfoStruct { 101 | const char *SliderName; // String in PROGMEM 102 | int16_t MinValue; 103 | int16_t MaxValue; 104 | int16_t Threshold; 105 | }; 106 | 107 | /******************** 108 | * BUTTONS 109 | ********************/ 110 | #define BUTTON_WIDTH BUTTON_WIDTH_4 111 | #if NUMBER_OF_RIGHT_SLIDERS > 0 112 | #define BUTTONS_START_X ((DISPLAY_WIDTH - BUTTON_WIDTH) / 2) 113 | #else 114 | #define BUTTONS_START_X (SLIDER_BAR_LENGTH + BUTTON_DEFAULT_SPACING) 115 | #endif 116 | #define BUTTON_HEIGHT (SLIDER_BAR_WIDTH + SLIDER_CAPTION_SIZE) 117 | #define BUTTON_TEXT_SIZE 7 118 | 119 | // PROGMEM text strings for buttons 120 | const char sString_Load[] PROGMEM = "Load\nvalues"; 121 | const char sString_Store[] PROGMEM = "Store\nvalues"; 122 | const char sString_LedOn[] PROGMEM = "LED On"; 123 | const char sString_LedOff[] PROGMEM = "LED Off"; 124 | const char sString_On[] PROGMEM = "On"; 125 | const char sString_Off[] PROGMEM = "Off"; 126 | const char sString_Button1[] PROGMEM = "Button_1"; 127 | const char sString_Button2[] PROGMEM = "Button_2"; 128 | const char sString_Button3[] PROGMEM = "Button_3"; 129 | const char sString_Button4[] PROGMEM = "Button_4"; 130 | const char sString_Button5[] PROGMEM = "Button_5"; 131 | const char sString_Button6[] PROGMEM = "Button_6"; 132 | const char sString_Button7[] PROGMEM = "Button_7"; 133 | const char sString_Button8[] PROGMEM = "Button_8"; 134 | 135 | struct ButtonStaticInfoStruct { 136 | int16_t Value; 137 | const char *ButtonText; // String in PROGMEM 138 | const char *ButtonTextForValueTrue; // if not 0 | NULL | nullptr a Red/Green toggle button is created 139 | }; 140 | 141 | /******************** 142 | * COMMON 143 | ********************/ 144 | #if !defined(SLIDER_AND_BUTTON_START_Y) 145 | #define SLIDER_AND_BUTTON_START_Y BUTTON_HEIGHT_6 146 | #endif 147 | #if !defined(SLIDER_AND_BUTTON_DELTA_Y) 148 | #define SLIDER_AND_BUTTON_DELTA_Y (2 * SLIDER_BAR_WIDTH) 149 | #endif 150 | 151 | void initSlidersAndButtons(const SliderStaticInfoStruct *aLeftSliderStaticPGMInfoPtr, 152 | const SliderStaticInfoStruct *aRightSliderStaticPGMInfoPtr); 153 | void drawSlidersAndButtons(void); 154 | uint8_t copyPGMStringStoredInPGMVariable(char *aStringBuffer, void *aPGMStringPtrStoredInPGMVariable); 155 | void storeSliderValuesToEEPROM(); 156 | void loadSliderValuesFromEEPROM(); 157 | 158 | #if !defined(STR) 159 | #define STR_HELPER(x) #x 160 | #define STR(x) STR_HELPER(x) 161 | #endif 162 | 163 | #endif // _MANY_SLIDER_AND_BUTTONS_HELPER_H 164 | -------------------------------------------------------------------------------- /examples/RcCarControl/HCSR04.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HCSR04.h 3 | * 4 | * Supports 1 Pin mode as you get on the HY-SRF05 if you connect OUT to ground. 5 | * You can modify the HC-SR04 modules to 1 Pin mode by: 6 | * Old module with 3 16 pin chips: Connect Trigger and Echo direct or use a resistor < 4.7 kOhm. 7 | * If you remove both 10 kOhm pullup resistor you can use a connecting resistor < 47 kOhm, but I suggest to use 10 kOhm which is more reliable. 8 | * Old module with 3 16 pin chips but with no pullup resistors near the connector row: Connect Trigger and Echo with a resistor > 200 ohm. Use 10 kOhm. 9 | * New module with 1 16 pin and 2 8 pin chips: Connect Trigger and Echo by a resistor > 200 ohm and < 22 kOhm. 10 | * All modules: Connect Trigger and Echo by a resistor of 4.7 kOhm. 11 | * 12 | * Copyright (C) 2018-2020 Armin Joachimsmeyer 13 | * Email: armin.joachimsmeyer@gmail.com 14 | * 15 | * This file is part of Arduino-Utils https://github.com/ArminJo/Arduino-Utils. 16 | * 17 | * Arduino-Utils is free software: you can redistribute it and/or modify 18 | * it under the terms of the GNU General Public License as published by 19 | * the Free Software Foundation, either version 3 of the License, or 20 | * (at your option) any later version. 21 | * 22 | * This program is distributed in the hope that it will be useful, 23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 25 | * See the GNU General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | * 30 | */ 31 | 32 | #ifndef _HCSR04_H 33 | #define _HCSR04_H 34 | 35 | #include 36 | 37 | #define DISTANCE_TIMEOUT_RESULT 0 38 | #define US_DISTANCE_DEFAULT_TIMEOUT_MICROS 20000 // Timeout of 20000L is 3.43 meter 39 | #define US_DISTANCE_DEFAULT_TIMEOUT_CENTIMETER 343 // Timeout of 20000L is 3.43 meter 40 | 41 | #define US_DISTANCE_TIMEOUT_MICROS_FOR_1_METER 5825 // Timeout of 5825 is 1 meter 42 | #define US_DISTANCE_TIMEOUT_MICROS_FOR_2_METER 11650 // Timeout of 11650 is 2 meter 43 | #define US_DISTANCE_TIMEOUT_MICROS_FOR_3_METER 17475 // Timeout of 17475 is 3 meter 44 | 45 | void initUSDistancePins(uint8_t aTriggerOutPin, uint8_t aEchoInPin = 0); 46 | void initUSDistancePin(uint8_t aTriggerOutEchoInPin); // Using this determines one pin mode 47 | void setHCSR04OnePinMode(bool aUseOnePinMode); 48 | unsigned int getUSDistance(unsigned int aTimeoutMicros = US_DISTANCE_DEFAULT_TIMEOUT_MICROS); 49 | unsigned int getCentimeterFromUSMicroSeconds(unsigned int aDistanceMicros); 50 | uint8_t getMillisFromUSCentimeter(unsigned int aDistanceCentimeter); 51 | unsigned int getUSDistanceAsCentimeter(unsigned int aTimeoutMicros = US_DISTANCE_DEFAULT_TIMEOUT_MICROS); 52 | unsigned int getUSDistanceAsCentimeterWithCentimeterTimeout(unsigned int aTimeoutCentimeter); 53 | bool getUSDistanceAsCentimeterWithCentimeterTimeoutPeriodicallyAndPrintIfChanged(unsigned int aTimeoutCentimeter, 54 | unsigned int aMillisBetweenMeasurements, Print *aSerial); 55 | void testUSSensor(uint16_t aSecondsToTest); 56 | 57 | #if (defined(USE_PIN_CHANGE_INTERRUPT_D0_TO_D7) | defined(USE_PIN_CHANGE_INTERRUPT_D8_TO_D13) | defined(USE_PIN_CHANGE_INTERRUPT_A0_TO_A5)) 58 | /* 59 | * Non blocking version 60 | */ 61 | void startUSDistanceAsCentimeterWithCentimeterTimeoutNonBlocking(unsigned int aTimeoutCentimeter); 62 | bool isUSDistanceMeasureFinished(); 63 | extern unsigned int sUSDistanceCentimeter; 64 | extern volatile unsigned long sUSPulseMicros; 65 | #endif 66 | 67 | #define HCSR04_MODE_UNITITIALIZED 0 68 | #define HCSR04_MODE_USE_1_PIN 1 69 | #define HCSR04_MODE_USE_2_PINS 2 70 | extern uint8_t sHCSR04Mode; 71 | extern unsigned long sLastUSDistanceMeasurementMillis; // Only written by getUSDistanceAsCentimeterWithCentimeterTimeoutPeriodicallyAndPrintIfChanged() 72 | extern unsigned int sLastUSDistanceCentimeter; // Only written by getUSDistanceAsCentimeterWithCentimeterTimeoutPeriodicallyAndPrintIfChanged() 73 | extern unsigned int sUSDistanceMicroseconds; 74 | extern unsigned int sUSDistanceCentimeter; 75 | extern uint8_t sUsedMillisForMeasurement; // is optimized out if not used 76 | 77 | #endif // _HCSR04_H 78 | -------------------------------------------------------------------------------- /examples/RcCarControl/RcCarControl.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * RcCarControl.cpp 3 | * Demo of using the BlueDisplay library for HC-05 on Arduino 4 | 5 | * Copyright (C) 2015 Armin Joachimsmeyer 6 | * armin.joachimsmeyer@gmail.com 7 | * 8 | * This file is part of BlueDisplay. 9 | * BlueDisplay is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 17 | * See the GNU General Public License for more details. 18 | 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #include 25 | 26 | #include "RcCarControlBD.h" 27 | 28 | /******************************************************************************************* 29 | * Program code starts here 30 | *******************************************************************************************/ 31 | 32 | void setup() { 33 | BDsetup(); 34 | } 35 | 36 | void loop() { 37 | BDloop(); 38 | } 39 | -------------------------------------------------------------------------------- /examples/RcCarControl/RcCarControlBD.h: -------------------------------------------------------------------------------- 1 | /* 2 | * RcCarControlBD.h 3 | * 4 | * Created on: 02.06.2016 5 | * Author: Armin 6 | */ 7 | 8 | #ifndef SRC_RCCARCONTROLBD_H_ 9 | #define SRC_RCCARCONTROLBD_H_ 10 | 11 | #define DIRECTION_STRAIGHT 0 12 | #define DIRECTION_RIGHT 1 13 | #define DIRECTION_LEFT 2 14 | 15 | void BDsetup(); 16 | void BDloop(); 17 | 18 | 19 | #endif /* SRC_RCCARCONTROLBD_H_ */ 20 | -------------------------------------------------------------------------------- /examples/SimpleDSO_BlueDisplay/FrequencyGeneratorPage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FrequencyGeneratorPage.h 3 | * 4 | * Copyright (C) 2015 Armin Joachimsmeyer 5 | * Email: armin.joachimsmeyer@gmail.com 6 | * License: GPL v3 (http://www.gnu.org/licenses/gpl.html) 7 | */ 8 | #ifndef _FREQUENCY_GENERATOR_PAGE_H 9 | #define _FREQUENCY_GENERATOR_PAGE_H 10 | 11 | #include "BDButton.h" 12 | 13 | #include 14 | #include 15 | 16 | /** 17 | * From FrequencyGenerator page 18 | */ 19 | void initFrequencyGenerator(void); 20 | void initFrequencyGeneratorPage(void); 21 | void drawFrequencyGeneratorPage(void); 22 | void startFrequencyGeneratorPage(void); 23 | void loopFrequencyGeneratorPage(void); 24 | void stopFrequencyGeneratorPage(void); 25 | 26 | //extern BDButton TouchButtonFrequencyPage; 27 | 28 | extern const char StringStop[] PROGMEM; // "Stop" 29 | 30 | #endif // _FREQUENCY_GENERATOR_PAGE_H 31 | -------------------------------------------------------------------------------- /examples/SimpleDSO_BlueDisplay/Waveforms.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Waveforms.h 3 | * 4 | * Copyright (C) 2017-2023 Armin Joachimsmeyer 5 | * Email: armin.joachimsmeyer@gmail.com 6 | * 7 | * This file is part of Arduino-Simple-DSO https://github.com/ArminJo/Arduino-Simple-DSO. 8 | * 9 | * Arduino-Simple-DSO is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 17 | * See the GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef _WAVEFORMS_H 24 | #define _WAVEFORMS_H 25 | 26 | #define WAVEFORM_SQUARE 0 27 | #define WAVEFORM_SINE 1 28 | #define WAVEFORM_TRIANGLE 2 29 | #define WAVEFORM_SAWTOOTH 3 30 | #define WAVEFORM_MASK 0x03 31 | 32 | #define FREQUENCY_RANGE_INDEX_MILLI_HERTZ 0 33 | #define FREQUENCY_RANGE_INDEX_HERTZ 1 34 | #define FREQUENCY_RANGE_INDEX_KILO_HERTZ 2 35 | #define FREQUENCY_RANGE_INDEX_MEGA_HERTZ 3 36 | 37 | struct FrequencyInfoStruct { 38 | union { 39 | uint32_t DividerInt; // Only for square wave and for info - may be (divider * prescaler) - resolution is 1/8 us 40 | uint32_t BaseFrequencyFactorShift16; // Value used by ISR - only for NON square wave 41 | } ControlValue; 42 | uint32_t PeriodMicros; // only for display purposes 43 | float Frequency; // use float, since we have mHz. 44 | 45 | uint8_t Waveform; // 0 to WAVEFORM_MAX 46 | bool isOutputEnabled; 47 | 48 | /* 49 | * Normalized frequency variables for display 50 | * The effective frequency is FrequencyNormalizedTo_1_to_1000 * (FrequencyNormalizedFactorTimes1000 / 1000) 51 | */ 52 | float FrequencyNormalizedTo_1_to_1000; // Frequency values from 1 to 1000 for slider 53 | uint32_t FrequencyNormalizedFactorTimes1000; // factor for mHz/Hz/kHz/MHz - times 1000 because of mHz handling - 1 -> 1 mHz, 1000 -> 1 Hz, 1000000 -> 1 kHz 54 | uint8_t FrequencyRangeIndex; // index for FrequencyRangeChars[]. 0->mHz, 1->Hz, 2->kHz, 3->MHz 55 | 56 | /* 57 | * Internal (private) values 58 | */ 59 | int32_t BaseFrequencyFactorAccumulator; // Value used by ISR - used to handle fractions of BaseFrequencyFactorShift16 60 | 61 | uint8_t PrescalerRegisterValueBackup; // backup of old value for start/stop of square wave 62 | }; 63 | extern struct FrequencyInfoStruct sFrequencyInfo; 64 | 65 | extern const char FrequencyRangeChars[4]; // see FrequencyRangeIndex above 66 | 67 | void setWaveformMode(uint8_t aNewMode); 68 | void cycleWaveformMode(); 69 | const __FlashStringHelper* cycleWaveformModePGMString(); 70 | const __FlashStringHelper* getWaveformModePGMString(); 71 | float getPeriodMicros(); 72 | 73 | void setNormalizedFrequencyAndFactor(float aFrequency); 74 | void setNormalizedFrequencyFactorFromRangeIndex(uint8_t aFrequencyRangeIndex); 75 | 76 | void initTimer1For8BitPWM(); 77 | bool setWaveformFrequencyFromNormalizedValues(); 78 | bool setWaveformFrequency(float aFrequency); 79 | bool setSquareWaveFrequency(float aFrequency); 80 | 81 | void stopWaveform(); 82 | void startWaveform(); 83 | 84 | // utility Function 85 | void computeSineTableValues(uint8_t aSineTable[], unsigned int aNumber); 86 | 87 | #endif // _WAVEFORMS_H 88 | -------------------------------------------------------------------------------- /examples/SimpleTouchScreenDSO/README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | # SimpleTouchScreenDSO 4 | Simple DSO Software for Arduino Uno/MEGA with a Touchscreen Shield. 5 | 6 | [![Badge License: GPLv3](https://img.shields.io/badge/License-GPLv3-brightgreen.svg)](https://www.gnu.org/licenses/gpl-3.0) 7 |     8 | [![Badge Build Status](https://github.com/ArminJo/SimpleTouchScreenDSO/workflows/TestCompile/badge.svg)](https://github.com/ArminJo/SimpleTouchScreenDSO/actions) 9 |     10 | ![Badge Hit Counter](https://visitor-badge.laobi.icu/badge?page_id=ArminJo_SimpleTouchScreenDSO) 11 |
12 |
13 | [![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://stand-with-ukraine.pp.ua) 14 | 15 |
16 | 17 |
18 | 19 | ## No dedicated hardware, just off the shelf components + c software 20 | 21 | Just add: 22 | - A **piezo buzzer** for audio feedback of touches. 23 | - One **capacitator, 2 resistors and a switch** to have an AC input. 24 | - **few more resistors, capacitors for compensating and a input range select switch** for an attenuator. 25 | 26 | ## Features: 27 | 28 | - 300 kSamples per second 29 | - Timebase 1-2-5 from 100 microseconds to 500 milliseconds per div (31 pixel) 30 | - Automatic trigger,range and offset value selection 31 | - Single shot mode 32 | - 580 Byte sample buffer 33 | - Min, max, average and peak-to-peak voltage display 34 | - Fast draw mode. Up to 45 screens per second in pixel mode 35 | - Switching between fast pixel and slower line display mode 36 | - All settings can be changed during measurement 37 | - All AVR ADC input channels selectable 38 | - Touch trigger level select 39 | - Touch voltage picker 40 | - 1.1 or 5 Volt reference selectable 41 | 42 | ## Hardware: 43 | 44 | - [Arduino Uno Rev ](https://shop.watterott.com/Arduino-Uno-R3) 45 | - [mSD-Shield](https://shop.watterott.com/mSD-Shield-v2-microSD-RTC-Datenlogger-Shield) 46 | - [MI0283QT-2 Adapter](https://shop.watterott.com/MI0283QT-Adapter-v1-inkl-28-LCD-Touchpanel) 47 | 48 | # Safety circuit range select and AC/DC switch 49 | 50 | ``` 51 | ADC INPUT PIN 52 | /\ 53 | | VREF----|R 2.2M|---+---|R 2.2M|---GND 54 | | | 55 | | | 56 | \ o-----+ o\ o 57 | \ | \ 58 | AC/DC \ = C 0.1uF AC/DC \ 59 | Switch \ | Switch \ 60 | o-----+ o 61 | | | 62 | | | 63 | +---|R 1K |-----< INPUT DIRECT >------------o \ | 64 | | \ | 65 | | \ | 66 | +---|R 2.2M|-+---< INPUT 10 VOLT >------o \ | 67 | +---|R 2.2M|-+ \ | 68 | +------||----+ Range select switch \ | 69 | | app. 80 pF (adjustable trimmer) o---+------ A0 70 | | | 71 | ATTENUATOR +---|R 3.3M|-+---< INPUT 20 VOLT >------o | Safety circuit 72 | +------||----+ VCC(5V)---|<|---+---|<|---GND 73 | | app. 25 pF 74 | | 75 | +---|R 4.7M|-|R 4.7M|--+---< INPUT 50 VOLT >-o 76 | | | 77 | +-----------||---------+ 78 | app. 10 pF 79 | ``` 80 | ![Hardware](https://github.com/ArminJo/SimpleTouchScreenDSO/blob/master/pictures/Hardware.jpg) 81 | ![StartScreen](https://github.com/ArminJo/SimpleTouchScreenDSO/blob/master/pictures/StartScreen.jpg) 82 | ![Settings](https://github.com/ArminJo/SimpleTouchScreenDSO/blob/master/pictures/Settings.jpg) 83 | ![5kHzSine](https://github.com/ArminJo/SimpleTouchScreenDSO/blob/master/pictures/5kHzSine.jpg) 84 | ![Linearity-100us / div](https://github.com/ArminJo/SimpleTouchScreenDSO/blob/master/pictures/Linearity-100.JPG) 85 | ![Linearity-200us / div](https://github.com/ArminJo/SimpleTouchScreenDSO/blob/master/pictures/Linearity-200.JPG) 86 | ![slowTimebase](https://github.com/ArminJo/SimpleTouchScreenDSO/blob/master/pictures/slowTimebase.jpg) 87 | -------------------------------------------------------------------------------- /examples/TouchGuiDemo/GameOfLife.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GameOfLife.h 3 | * 4 | * 5 | * Copyright (C) 2012-2023 Armin Joachimsmeyer 6 | * armin.joachimsmeyer@gmail.com 7 | * 8 | * This file is part of BlueDisplay https://github.com/ArminJo/Arduino-BlueDisplay. 9 | * This file is part of STMF3-Discovery-Demos https://github.com/ArminJo/STMF3-Discovery-Demos. 10 | * 11 | * STMF3-Discovery-Demos + BlueDisplay are free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef _GAME_OF_LIFE_H 26 | #define _GAME_OF_LIFE_H 27 | 28 | #define EMPTY_CELL_COLOR (0) 29 | #define ALIVE_COLOR_INDEX (1) 30 | #define JUST_DIED_COLOR (2) 31 | #define LONGER_DEAD_COLOR (3) 32 | #define DEAD_COLOR_INDEX (4) 33 | 34 | #define GAME_OF_LIFE_MAX_GEN (600) //max generations 35 | #if defined(SUPPORT_LOCAL_DISPLAY) && (defined(RAMEND) || defined(RAMSIZE)) && (RAMEND <= 0x8FF || RAMSIZE < 0x8FF) 36 | // One cell requires one byte 37 | #define GAME_OF_LIFE_X_SIZE (20) 38 | #define GAME_OF_LIFE_Y_SIZE (15) 39 | #else 40 | #define GAME_OF_LIFE_X_SIZE (40) 41 | #define GAME_OF_LIFE_Y_SIZE (30) 42 | #endif 43 | 44 | /* 45 | * Cell bit meanings 46 | */ 47 | #define CELL_IS_EMPTY (0x00) 48 | #define CELL_JUST_DIED (0x04) 49 | #define CELL_IS_ALIVE (0x08) 50 | #define CELL_IS_NEW (0x10) 51 | #define CELL_DIE_HISTORY_COUNTER_MASK (0x03) // Lower 2 bits are used as a die history counter from 2 to 0 52 | 53 | extern uint8_t (*tGameOfLifeByteArray)[GAME_OF_LIFE_Y_SIZE]; 54 | extern uint16_t sCurrentGameOfLifeGeneration; 55 | 56 | void initGameOfLife(void); 57 | void playGameOfLife(void); 58 | void drawGameOfLife(void); 59 | void drawGenerationText(void); 60 | void ClearScreenAndDrawGameOfLifeGrid(void); 61 | 62 | extern bool GameOfLifeShowDying; 63 | 64 | #endif // _GAME_OF_LIFE_H 65 | -------------------------------------------------------------------------------- /examples/TouchGuiDemo/GuiDemo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GuiDemo.h 3 | * 4 | * Copyright (C) 2012-2023 Armin Joachimsmeyer 5 | * armin.joachimsmeyer@gmail.com 6 | * 7 | * This file is part of BlueDisplay https://github.com/ArminJo/Arduino-BlueDisplay. 8 | * This file is part of STMF3-Discovery-Demos https://github.com/ArminJo/STMF3-Discovery-Demos. 9 | * 10 | * STMF3-Discovery-Demos + BlueDisplay are free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef _GUI_DEMO_H 25 | #define _GUI_DEMO_H 26 | 27 | void initGuiDemo(void); 28 | void startGuiDemo(void); 29 | void loopGuiDemo(void); 30 | void stopGuiDemo(void); 31 | 32 | #endif // _GUI_DEMO_H 33 | -------------------------------------------------------------------------------- /examples/TouchGuiDemo/LocalDisplayGUI.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * LocalDisplayGui.cpp 3 | * 4 | * GUI for local display settings like backlight and ADS7846 settings and info 5 | * 6 | * 7 | * Copyright (C) 2023-2024 Armin Joachimsmeyer 8 | * armin.joachimsmeyer@gmail.com 9 | * 10 | * This file is part of BlueDisplay https://github.com/ArminJo/Arduino-BlueDisplay. 11 | * This file is part of STMF3-Discovery-Demos https://github.com/ArminJo/STMF3-Discovery-Demos. 12 | * 13 | * STMF3-Discovery-Demos + BlueDisplay are free software: you can redistribute it and/or modify 14 | * it under the terms of the GNU General Public License as published by 15 | * the Free Software Foundation, either version 3 of the License, or 16 | * (at your option) any later version. 17 | * 18 | * This program is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with this program. If not, see . 25 | */ 26 | 27 | #ifndef _LOCAL_DISPLAY_GUI_HPP 28 | #define _LOCAL_DISPLAY_GUI_HPP 29 | 30 | #if defined(SUPPORT_LOCAL_DISPLAY) 31 | 32 | #if !defined(Button) 33 | #define BUTTON_IS_DEFINED_LOCALLY 34 | # if defined(SUPPORT_LOCAL_DISPLAY) && defined(DISABLE_REMOTE_DISPLAY) 35 | /* 36 | * For programs, that must save memory when running on local display only 37 | * Only local display must be supported, so LocalTouchButton, etc. is sufficient 38 | */ 39 | #define Button LocalTouchButton 40 | #define AutorepeatButton LocalTouchButtonAutorepeat 41 | #define Slider LocalTouchSlider 42 | #define Display LocalDisplay 43 | # else 44 | // Remote display is used here, so use BD elements, they are aware of the existence of Local* objects and use them if SUPPORT_LOCAL_DISPLAY is enabled 45 | #define Button BDButton 46 | #define AutorepeatButton BDButton 47 | #define Slider BDSlider 48 | #define Display BlueDisplay1 49 | # endif 50 | #endif 51 | 52 | #if !defined(BACKLIGHT_CONTROL_X) 53 | #define BACKLIGHT_CONTROL_X 30 54 | #define BACKLIGHT_CONTROL_Y 4 55 | #endif 56 | 57 | AutorepeatButton TouchButtonAutorepeatBacklight_Plus; 58 | AutorepeatButton TouchButtonAutorepeatBacklight_Minus; 59 | 60 | /******************* 61 | * Backlight stuff 62 | *******************/ 63 | void doChangeBacklight(Button *aTheTouchedButton, int16_t aValue); 64 | void doBacklightSlider(Slider *aTheTouchedSlider, int16_t aBrightnessPercent); 65 | 66 | /** 67 | * create backlight slider and autorepeat buttons 68 | */ 69 | void createBacklightGUI(void) { 70 | TouchButtonAutorepeatBacklight_Plus.init(BACKLIGHT_CONTROL_X, BACKLIGHT_CONTROL_Y, BUTTON_WIDTH_10, 71 | BUTTON_HEIGHT_6, COLOR16_RED, "+", TEXT_SIZE_22, FLAG_BUTTON_DO_BEEP_ON_TOUCH | FLAG_BUTTON_TYPE_AUTOREPEAT, 1, 72 | &doChangeBacklight); 73 | /* 74 | * Backlight slider 75 | */ 76 | TouchSliderBacklight.init(BACKLIGHT_CONTROL_X, BACKLIGHT_CONTROL_Y + BUTTON_HEIGHT_6 + 4, 77 | SLIDER_DEFAULT_BAR_WIDTH, BACKLIGHT_MAX_BRIGHTNESS_VALUE, BACKLIGHT_MAX_BRIGHTNESS_VALUE, sCurrentBacklightPercent, COLOR16_BLUE, 78 | COLOR16_GREEN, FLAG_SLIDER_SHOW_BORDER | FLAG_SLIDER_SHOW_VALUE, &doBacklightSlider); 79 | TouchSliderBacklight.setCaptionProperties(TEXT_SIZE_11, FLAG_SLIDER_VALUE_CAPTION_ALIGN_MIDDLE, SLIDER_DEFAULT_VALUE_MARGIN, COLOR16_RED, 80 | BACKGROUND_COLOR); 81 | TouchSliderBacklight.setCaption("Backlight"); 82 | TouchSliderBacklight.setPrintValueProperties(TEXT_SIZE_11, FLAG_SLIDER_VALUE_CAPTION_ALIGN_MIDDLE, SLIDER_DEFAULT_VALUE_MARGIN + TEXT_SIZE_11, 83 | COLOR16_BLUE, BACKGROUND_COLOR); 84 | 85 | TouchButtonAutorepeatBacklight_Minus.init(BACKLIGHT_CONTROL_X, 180, BUTTON_WIDTH_10, BUTTON_HEIGHT_6, COLOR16_RED, "-", TEXT_SIZE_22, 86 | FLAG_BUTTON_DO_BEEP_ON_TOUCH | FLAG_BUTTON_TYPE_AUTOREPEAT, -1, &doChangeBacklight); 87 | 88 | TouchButtonAutorepeatBacklight_Plus.setButtonAutorepeatTiming(600, 100, 10, 20); 89 | TouchButtonAutorepeatBacklight_Minus.setButtonAutorepeatTiming(600, 100, 10, 20); 90 | } 91 | 92 | 93 | void deinitBacklightElements(void) { 94 | TouchButtonAutorepeatBacklight_Plus.deinit(); 95 | TouchButtonAutorepeatBacklight_Minus.deinit(); 96 | TouchSliderBacklight.deinit(); 97 | } 98 | 99 | void drawBacklightElements(void) { 100 | TouchButtonAutorepeatBacklight_Plus.drawButton(); 101 | TouchSliderBacklight.drawSlider(); 102 | TouchButtonAutorepeatBacklight_Minus.drawButton(); 103 | } 104 | 105 | void doBacklightSlider(Slider *aTheTouchedSlider, int16_t aBrightnessPercent) { 106 | LocalDisplay.setBacklightBrightness(aBrightnessPercent); 107 | } 108 | 109 | void doChangeBacklight(Button *aTheTouchedButton, int16_t aValue) { 110 | auto tCurrentBacklightPercent = sCurrentBacklightPercent + aValue; // See 8 bit roll-under here :-) 111 | if(tCurrentBacklightPercent == 101) { // we know that aValue can only be 1 or -1 112 | tCurrentBacklightPercent = 100; 113 | AutorepeatButton::disableAutorepeatUntilEndOfTouch(); 114 | } 115 | LocalDisplay.setBacklightBrightness(tCurrentBacklightPercent); 116 | TouchSliderBacklight.setValueAndDrawBar(tCurrentBacklightPercent); 117 | } 118 | #endif 119 | 120 | #if defined(BUTTON_IS_DEFINED_LOCALLY) 121 | #undef BUTTON_IS_DEFINED_LOCALLY 122 | #undef Button 123 | #undef AutorepeatButton 124 | #undef Slider 125 | #undef Display 126 | #endif 127 | 128 | #endif // _LOCAL_DISPLAY_GUI_HPP 129 | -------------------------------------------------------------------------------- /examples/TouchGuiDemo/PageDraw.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * PageDraw.cpp 3 | * 4 | * Select a color and draw pixels or lines by touching and moving on the screen. 5 | * 6 | * Copyright (C) 2013-2024 Armin Joachimsmeyer 7 | * armin.joachimsmeyer@gmail.com 8 | * 9 | * This file is part of BlueDisplay https://github.com/ArminJo/Arduino-BlueDisplay. 10 | * This file is part of STMF3-Discovery-Demos https://github.com/ArminJo/STMF3-Discovery-Demos. 11 | * 12 | * STMF3-Discovery-Demos + BlueDisplay are free software: you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation, either version 3 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * This program is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | */ 25 | 26 | #ifndef _PAGE_DRAW_HPP 27 | #define _PAGE_DRAW_HPP 28 | 29 | #if !defined(Button) 30 | #define BUTTON_IS_DEFINED_LOCALLY 31 | # if defined(SUPPORT_LOCAL_DISPLAY) && defined(DISABLE_REMOTE_DISPLAY) 32 | /* 33 | * For programs, that must save memory when running on local display only 34 | * Only local display must be supported, so LocalTouchButton, etc. is sufficient 35 | */ 36 | #define Button LocalTouchButton 37 | #define AutorepeatButton LocalTouchButtonAutorepeat 38 | #define Slider LocalTouchSlider 39 | #define Display LocalDisplay 40 | # else 41 | // Remote display is used here, so use BD elements, they are aware of the existence of Local* objects and use them if SUPPORT_LOCAL_DISPLAY is enabled 42 | #define Button BDButton 43 | #define AutorepeatButton BDButton 44 | #define Slider BDSlider 45 | #define Display BlueDisplay1 46 | # endif 47 | #endif 48 | 49 | static struct XYPosition sLastPos; 50 | static uint16_t sDrawColor = COLOR16_BLACK; 51 | 52 | Button TouchButtonClear; 53 | #define NUMBER_OF_DRAW_COLORS 5 54 | Button TouchButtonsDrawColor[NUMBER_OF_DRAW_COLORS]; 55 | static const uint16_t DrawColors[NUMBER_OF_DRAW_COLORS] = 56 | { COLOR16_BLACK, COLOR16_RED, COLOR16_GREEN, COLOR16_BLUE, COLOR16_YELLOW }; 57 | 58 | void initDrawPage(void) { 59 | } 60 | 61 | void drawDrawPage(void) { 62 | Display.clearDisplay(BACKGROUND_COLOR); 63 | for (uint8_t i = 0; i < 5; ++i) { 64 | TouchButtonsDrawColor[i].drawButton(); 65 | } 66 | TouchButtonClear.drawButton(); 67 | #if defined(MAIN_HOME_AVAILABLE) 68 | TouchButtonMainHome.drawButton(); 69 | #else 70 | TouchButtonBack.drawButton(); 71 | #endif 72 | } 73 | 74 | void doDrawClear(Button *aTheTouchedButton, int16_t aValue) { 75 | (void) aTheTouchedButton; 76 | (void) aValue; 77 | drawDrawPage(); 78 | } 79 | 80 | static void doDrawColor(Button *aTheTouchedButton, int16_t aValue) { 81 | (void) aTheTouchedButton; 82 | (void) aValue; 83 | sDrawColor = DrawColors[aValue]; 84 | } 85 | 86 | #if defined(SUPPORT_LOCAL_DISPLAY) && !defined(LOCAL_DISPLAY_GENERATES_BD_EVENTS) 87 | void drawLine(const bool aNewStart, unsigned int color) { 88 | static unsigned int last_x = 0, last_y = 0; 89 | if (aNewStart) { 90 | LocalDisplay.drawPixel(TouchPanel.getCurrentX(), TouchPanel.getCurrentY(), color); 91 | } else { 92 | LocalDisplay.drawLine(last_x, last_y, TouchPanel.getCurrentX(), TouchPanel.getCurrentY(), color); 93 | } 94 | last_x = TouchPanel.getCurrentX(); 95 | last_y = TouchPanel.getCurrentY(); 96 | } 97 | #endif 98 | 99 | /* 100 | * Position changed -> draw line 101 | */ 102 | void drawPageTouchMoveCallbackHandler(struct TouchEvent *const aCurrentPositionPtr) { 103 | Display.drawLine(sLastPos.PositionX, sLastPos.PositionY, aCurrentPositionPtr->TouchPosition.PositionX, 104 | aCurrentPositionPtr->TouchPosition.PositionY, sDrawColor); 105 | sLastPos.PositionX = aCurrentPositionPtr->TouchPosition.PositionX; 106 | sLastPos.PositionY = aCurrentPositionPtr->TouchPosition.PositionY; 107 | } 108 | 109 | /* 110 | * Touch is going down on canvas -> draw starting point 111 | */ 112 | void drawPageTouchDownCallbackHandler(struct TouchEvent *const aCurrentPositionPtr) { 113 | int x = aCurrentPositionPtr->TouchPosition.PositionX; 114 | int y = aCurrentPositionPtr->TouchPosition.PositionY; 115 | Display.drawPixel(x, y, sDrawColor); 116 | sLastPos.PositionX = x; 117 | sLastPos.PositionY = y; 118 | } 119 | 120 | void startDrawPage(void) { 121 | // Color buttons 122 | uint16_t tPosY = 0; 123 | for (uint8_t i = 0; i < 5; ++i) { 124 | TouchButtonsDrawColor[i].init(0, tPosY, 30, 30, DrawColors[i], "", TEXT_SIZE_11, FLAG_BUTTON_DO_BEEP_ON_TOUCH, i, 125 | &doDrawColor); 126 | tPosY += 30; 127 | } 128 | 129 | TouchButtonClear.init(BUTTON_WIDTH_3_POS_3, BUTTON_HEIGHT_4_LINE_4, BUTTON_WIDTH_3, BUTTON_HEIGHT_4, COLOR16_RED, F("Clear"), 130 | TEXT_SIZE_22, FLAG_BUTTON_DO_BEEP_ON_TOUCH, 0, &doDrawClear); 131 | 132 | #if !defined(DISABLE_REMOTE_DISPLAY) 133 | registerTouchDownCallback(&drawPageTouchDownCallbackHandler); 134 | registerTouchMoveCallback(&drawPageTouchMoveCallbackHandler); 135 | registerRedrawCallback(&drawDrawPage); 136 | #endif 137 | 138 | drawDrawPage(); 139 | } 140 | 141 | void loopDrawPage(void) { 142 | #if defined(SUPPORT_LOCAL_DISPLAY) && !defined(LOCAL_DISPLAY_GENERATES_BD_EVENTS) 143 | if (TouchPanel.ADS7846TouchActive && sTouchObjectTouched == PANEL_TOUCHED) { 144 | drawLine(TouchPanel.wasJustTouched(), sDrawColor); 145 | } 146 | printLocalTouchPanelData(); 147 | // checkAndHandleTouchPanelEvents(); // we know it is called at the loop which called us 148 | #else 149 | checkAndHandleEvents(); 150 | #endif 151 | } 152 | 153 | void stopDrawPage(void) { 154 | // free buttons 155 | for (unsigned int i = 0; i < NUMBER_OF_DRAW_COLORS; ++i) { 156 | TouchButtonsDrawColor[i].deinit(); 157 | } 158 | TouchButtonClear.deinit(); 159 | } 160 | 161 | #if defined(BUTTON_IS_DEFINED_LOCALLY) 162 | #undef BUTTON_IS_DEFINED_LOCALLY 163 | #undef Button 164 | #undef AutorepeatButton 165 | #undef Slider 166 | #undef Display 167 | #endif 168 | 169 | #endif // _PAGE_DRAW_HPP 170 | -------------------------------------------------------------------------------- /examples/TwoButtonsOnLocalDisplay/TwoButtonsOnLocalDisplay.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * TwoButtonsOnLocalDisplay.cpp 3 | * 4 | * Demo of creating two buttons on a local display 5 | * using the LocalTouchButton lib for Arduino Uno 6 | * with mSD-Shield and MI0283QT Adapter from www.watterott.net 7 | * and the ADS7846 and MI0283QT2 libs from 8 | * https://github.com/watterott/mSD-Shield/downloads 9 | * 10 | * Copyright (C) 2012-2024 Armin Joachimsmeyer 11 | * armin.joachimsmeyer@gmail.com 12 | * 13 | * This file is part of BlueDisplay https://github.com/ArminJo/Arduino-BlueDisplay. 14 | * 15 | * BlueDisplay is free software: you can redistribute it and/or modify 16 | * it under the terms of the GNU General Public License as published by 17 | * the Free Software Foundation, either version 3 of the License, or 18 | * (at your option) any later version. 19 | * 20 | * This program is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 23 | * See the GNU General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU General Public License 26 | * along with this program. If not, see . 27 | * 28 | */ 29 | #include 30 | 31 | /* 32 | * Settings to configure the LocalGUI library 33 | */ 34 | #define LOCAL_GUI_FEEDBACK_TONE_PIN 2 35 | #define SUPPORT_ONLY_TEXT_SIZE_11_AND_22 // Saves 248 bytes program memory 36 | #define DISABLE_REMOTE_DISPLAY // Suppress drawing to Bluetooth connected display. Allow only drawing on the locally attached display 37 | #define SUPPORT_LOCAL_DISPLAY // Supports simultaneously drawing on the locally attached display. Not (yet) implemented for all commands! 38 | #define FONT_8X12 // Font size used here 39 | #include "LocalHX8347DDisplay.hpp" // The implementation of the local display must be included first since it defines LOCAL_DISPLAY_HEIGHT etc. 40 | #include "LocalGUI.hpp" // Includes the sources for LocalTouchButton etc. 41 | 42 | /* 43 | * LCD and touch panel stuff 44 | */ 45 | #define TP_EEPROMADDR (E2END -1 - sizeof(CAL_MATRIX)) //eeprom address for calibration data - 28 bytes 46 | void printTPData(void); 47 | void printRGB(const uint16_t aColor, const uint16_t aXPos, const uint16_t aYPos); 48 | 49 | #define BACKGROUND_COLOR COLOR16_WHITE 50 | 51 | // a string buffer for any purpose... 52 | char sStringBuffer[128]; 53 | 54 | #define BUTTON_WIDTH 180 55 | #define BUTTON_HEIGHT 50 56 | #define BUTTON_SPACING 30 57 | 58 | // Increment to create a lot of different colors 59 | #define CAPTION_COLOR_INCREMENT COLOR16(0x08,0x20,0x60) 60 | #define BUTTON_BACKGROUND_COLOR_INCREMENT COLOR16(0x08,0x10,0x40) 61 | LocalTouchButtonAutorepeat TouchButtonTextColorAutorepeat; 62 | LocalTouchButton TouchButtonBackgroundColor; 63 | 64 | // Callback touch handler 65 | void doButtons(LocalTouchButton *const aTheTouchedButton, int16_t aValue); 66 | 67 | void setup() { 68 | 69 | #if defined(DEBUG) 70 | Serial.begin(115200); 71 | // Just to know which program is running on my Arduino 72 | delay(2000); 73 | Serial.println(F("START " __FILE__ " from " __DATE__)); 74 | #endif 75 | 76 | //init display 77 | // faster SPI mode - works fine :-) 78 | LocalDisplay.init(2); //spi-clk = Fcpu/2 79 | // LocalDisplay.init(4); //spi-clk = Fcpu/4 80 | 81 | LocalDisplay.clearDisplay(COLOR16_WHITE); 82 | 83 | //init touch controller 84 | TouchPanel.initAndCalibrateOnPress(TP_EEPROMADDR); 85 | 86 | // Create 2 buttons 87 | int8_t tErrorValue = TouchButtonTextColorAutorepeat.init(20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, COLOR16_RED, "Text", 88 | TEXT_SIZE_22, FLAG_BUTTON_DO_BEEP_ON_TOUCH, 0, &doButtons); 89 | TouchButtonTextColorAutorepeat.setButtonAutorepeatTiming(1000, 400, 5, 100); 90 | 91 | tErrorValue += TouchButtonBackgroundColor.init(20, TouchButtonTextColorAutorepeat.getPositionYBottom() + BUTTON_SPACING, 92 | BUTTON_WIDTH, BUTTON_HEIGHT, COLOR16_RED, "Background", TEXT_SIZE_22, FLAG_BUTTON_DO_BEEP_ON_TOUCH, 0, &doButtons); 93 | 94 | TouchButtonTextColorAutorepeat.drawButton(); 95 | TouchButtonBackgroundColor.drawButton(); 96 | 97 | if (tErrorValue != 0) { 98 | // Show Error 99 | LocalDisplay.clearDisplay(BACKGROUND_COLOR); 100 | LocalDisplay.drawText(40, 100, (char*) "Error on button rendering", TEXT_SIZE_22, COLOR16_RED, BACKGROUND_COLOR); 101 | // LocalDisplay.drawText(40, 120, tErrorValue, TEXT_SIZE_22, COLOR16_RED, BACKGROUND_COLOR); 102 | delay(5000); 103 | } 104 | LocalTouchButton::playFeedbackTone(); 105 | } 106 | 107 | void loop() { 108 | checkAndHandleTouchPanelEvents(); 109 | printTPData(); 110 | } 111 | 112 | void doButtons(LocalTouchButton *const aTheTouchedButton, int16_t aValue) { 113 | printRGB(aValue, 10, 200); 114 | if (aTheTouchedButton == &TouchButtonTextColorAutorepeat) { 115 | aValue += CAPTION_COLOR_INCREMENT; 116 | aTheTouchedButton->setTextColor(aValue); 117 | aTheTouchedButton->setValue(aValue); 118 | aTheTouchedButton->drawText(); 119 | return; 120 | } 121 | if (aTheTouchedButton == &TouchButtonBackgroundColor) { 122 | aValue += BUTTON_BACKGROUND_COLOR_INCREMENT; 123 | aTheTouchedButton->setButtonColor(aValue); 124 | aTheTouchedButton->setValue(aValue); 125 | aTheTouchedButton->drawButton(); 126 | return; 127 | } 128 | } 129 | 130 | /* 131 | * Show RGB data of touched button 132 | */ 133 | void printRGB(const uint16_t aColor, uint16_t aXPos, const uint16_t aYPos) { 134 | //RED 135 | snprintf(sStringBuffer, sizeof(sStringBuffer), "R=%02X", (aColor & 0xF800) >> 8); 136 | aXPos = LocalDisplay.drawText(aXPos, aYPos, sStringBuffer, TEXT_SIZE_22, COLOR16_RED, BACKGROUND_COLOR); 137 | //GREEN 138 | snprintf(sStringBuffer, sizeof(sStringBuffer), "G=%02X", (aColor & 0x07E0) >> 3); 139 | aXPos += 2 * FONT_WIDTH; 140 | aXPos = LocalDisplay.drawText(aXPos, aYPos, sStringBuffer, TEXT_SIZE_22, COLOR16_GREEN, BACKGROUND_COLOR); 141 | //BLUE 142 | snprintf(sStringBuffer, sizeof(sStringBuffer), "B=%02X", (aColor & 0x001F) << 3); 143 | aXPos += 2 * FONT_WIDTH; 144 | LocalDisplay.drawText(aXPos, aYPos, sStringBuffer, TEXT_SIZE_22, COLOR16_BLUE, BACKGROUND_COLOR); 145 | } 146 | 147 | /* 148 | * Show touch panel raw and processed data in the first line 149 | */ 150 | void printTPData(void) { 151 | snprintf(sStringBuffer, sizeof(sStringBuffer), "X:%03i|%04i Y:%03i|%04i P:%03i", TouchPanel.getCurrentX(), TouchPanel.getRawX(), 152 | TouchPanel.getCurrentY(), TouchPanel.getRawY(), TouchPanel.getPressure()); 153 | LocalDisplay.drawText(20, 2, sStringBuffer, TEXT_SIZE_11, COLOR16_BLACK, BACKGROUND_COLOR); 154 | } 155 | -------------------------------------------------------------------------------- /examples/US_Distance/HCSR04.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HCSR04.h 3 | * 4 | * Supports 1 Pin mode as you get on the HY-SRF05 if you connect OUT to ground. 5 | * You can modify the HC-SR04 modules to 1 Pin mode by: 6 | * Old module with 3 16 pin chips: Connect Trigger and Echo direct or use a resistor < 4.7 kOhm. 7 | * If you remove both 10 kOhm pullup resistor you can use a connecting resistor < 47 kOhm, but I suggest to use 10 kOhm which is more reliable. 8 | * Old module with 3 16 pin chips but with no pullup resistors near the connector row: Connect Trigger and Echo with a resistor > 200 ohm. Use 10 kOhm. 9 | * New module with 1 16 pin and 2 8 pin chips: Connect Trigger and Echo by a resistor > 200 ohm and < 22 kOhm. 10 | * All modules: Connect Trigger and Echo by a resistor of 4.7 kOhm. 11 | * 12 | * Copyright (C) 2018-2020 Armin Joachimsmeyer 13 | * Email: armin.joachimsmeyer@gmail.com 14 | * 15 | * This file is part of Arduino-Utils https://github.com/ArminJo/Arduino-Utils. 16 | * 17 | * Arduino-Utils is free software: you can redistribute it and/or modify 18 | * it under the terms of the GNU General Public License as published by 19 | * the Free Software Foundation, either version 3 of the License, or 20 | * (at your option) any later version. 21 | * 22 | * This program is distributed in the hope that it will be useful, 23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 25 | * See the GNU General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | * 30 | */ 31 | 32 | #ifndef _HCSR04_H 33 | #define _HCSR04_H 34 | 35 | #include 36 | 37 | #define DISTANCE_TIMEOUT_RESULT 0 38 | #define US_DISTANCE_DEFAULT_TIMEOUT_MICROS 20000 // Timeout of 20000L is 3.43 meter 39 | #define US_DISTANCE_DEFAULT_TIMEOUT_CENTIMETER 343 // Timeout of 20000L is 3.43 meter 40 | 41 | #define US_DISTANCE_TIMEOUT_MICROS_FOR_1_METER 5825 // Timeout of 5825 is 1 meter 42 | #define US_DISTANCE_TIMEOUT_MICROS_FOR_2_METER 11650 // Timeout of 11650 is 2 meter 43 | #define US_DISTANCE_TIMEOUT_MICROS_FOR_3_METER 17475 // Timeout of 17475 is 3 meter 44 | 45 | void initUSDistancePins(uint8_t aTriggerOutPin, uint8_t aEchoInPin = 0); 46 | void initUSDistancePin(uint8_t aTriggerOutEchoInPin); // Using this determines one pin mode 47 | void setHCSR04OnePinMode(bool aUseOnePinMode); 48 | unsigned int getUSDistance(unsigned int aTimeoutMicros = US_DISTANCE_DEFAULT_TIMEOUT_MICROS); 49 | unsigned int getCentimeterFromUSMicroSeconds(unsigned int aDistanceMicros); 50 | uint8_t getMillisFromUSCentimeter(unsigned int aDistanceCentimeter); 51 | unsigned int getUSDistanceAsCentimeter(unsigned int aTimeoutMicros = US_DISTANCE_DEFAULT_TIMEOUT_MICROS); 52 | unsigned int getUSDistanceAsCentimeterWithCentimeterTimeout(unsigned int aTimeoutCentimeter); 53 | bool getUSDistanceAsCentimeterWithCentimeterTimeoutPeriodicallyAndPrintIfChanged(unsigned int aTimeoutCentimeter, 54 | unsigned int aMillisBetweenMeasurements, Print *aSerial); 55 | void testUSSensor(uint16_t aSecondsToTest); 56 | 57 | #if (defined(USE_PIN_CHANGE_INTERRUPT_D0_TO_D7) | defined(USE_PIN_CHANGE_INTERRUPT_D8_TO_D13) | defined(USE_PIN_CHANGE_INTERRUPT_A0_TO_A5)) 58 | /* 59 | * Non blocking version 60 | */ 61 | void startUSDistanceAsCentimeterWithCentimeterTimeoutNonBlocking(unsigned int aTimeoutCentimeter); 62 | bool isUSDistanceMeasureFinished(); 63 | extern unsigned int sUSDistanceCentimeter; 64 | extern volatile unsigned long sUSPulseMicros; 65 | #endif 66 | 67 | #define HCSR04_MODE_UNITITIALIZED 0 68 | #define HCSR04_MODE_USE_1_PIN 1 69 | #define HCSR04_MODE_USE_2_PINS 2 70 | extern uint8_t sHCSR04Mode; 71 | extern unsigned long sLastUSDistanceMeasurementMillis; // Only written by getUSDistanceAsCentimeterWithCentimeterTimeoutPeriodicallyAndPrintIfChanged() 72 | extern unsigned int sLastUSDistanceCentimeter; // Only written by getUSDistanceAsCentimeterWithCentimeterTimeoutPeriodicallyAndPrintIfChanged() 73 | extern unsigned int sUSDistanceMicroseconds; 74 | extern unsigned int sUSDistanceCentimeter; 75 | extern uint8_t sUsedMillisForMeasurement; // is optimized out if not used 76 | 77 | #endif // _HCSR04_H 78 | -------------------------------------------------------------------------------- /examples/US_Distance/PinDefinitionsAndMore.h: -------------------------------------------------------------------------------- 1 | /* 2 | * PinDefinitionsAndMore.h 3 | * 4 | * Contains pin definitions for BlueDisplay examples for various platforms 5 | * 6 | * Copyright (C) 2020-2022 Armin Joachimsmeyer 7 | * armin.joachimsmeyer@gmail.com 8 | * 9 | * This file is part of BlueDisplay https://github.com/ArminJo/BlueDisplay. 10 | * 11 | * BlueDisplay is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 19 | * See the GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | * 24 | */ 25 | 26 | /* 27 | * Pin mapping table for different platforms 28 | * 29 | * Platform Tone HCSR04-Echo HCSR04-Trigger 30 | * ---------------------------------------------- 31 | * AVR 3 3 4 32 | * ESP8266 14 14 15 33 | * ESP832 15 26 27 34 | * BluePill 2 PB0 PB1 35 | */ 36 | 37 | #if defined(ESP8266) 38 | #define TONE_PIN 14 // labeled D5 39 | #define ANALOG_INPUT_PIN 0 40 | #define ECHO_IN_PIN 13 // labeled D7 41 | #define TRIGGER_OUT_PIN 15 // labeled D8 42 | 43 | #elif defined(ESP32) 44 | #define ANALOG_INPUT_PIN A0 // 36/VP 45 | #define ECHO_IN_PIN 26 46 | #define TRIGGER_OUT_PIN 27 47 | #define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer. 48 | // tone() is included in ESP32 core since 2.0.2 49 | # if !defined(ESP_ARDUINO_VERSION) 50 | #define ESP_ARDUINO_VERSION 0x010101 // Version 1.1.1 51 | # endif 52 | # if !defined(ESP_ARDUINO_VERSION_VAL) 53 | #define ESP_ARDUINO_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) 54 | # endif 55 | #if ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) 56 | #define TONE_LEDC_CHANNEL 1 // Using channel 1 makes tone() independent of receiving timer -> No need to stop receiving timer. 57 | void tone(uint8_t aPinNumber, unsigned int aFrequency){ 58 | ledcAttachPin(aPinNumber, TONE_LEDC_CHANNEL); 59 | ledcWriteTone(TONE_LEDC_CHANNEL, aFrequency); 60 | } 61 | void tone(uint8_t aPinNumber, unsigned int aFrequency, unsigned long aDuration){ 62 | ledcAttachPin(aPinNumber, TONE_LEDC_CHANNEL); 63 | ledcWriteTone(TONE_LEDC_CHANNEL, aFrequency); 64 | delay(aDuration); 65 | ledcWriteTone(TONE_LEDC_CHANNEL, 0); 66 | } 67 | void noTone(uint8_t aPinNumber){ 68 | ledcWriteTone(TONE_LEDC_CHANNEL, 0); 69 | } 70 | #endif // ESP_ARDUINO_VERSION <= ESP_ARDUINO_VERSION_VAL(2, 0, 2) 71 | #define TONE_PIN 15 72 | 73 | #elif defined(ARDUINO_ARCH_SAM) 74 | #define ANALOG_INPUT_PIN A0 75 | #define ECHO_IN_PIN 4 76 | #define TRIGGER_OUT_PIN 5 77 | 78 | #define tone(...) void() // no tone() available 79 | #define noTone(a) void() 80 | #define TONE_PIN 42 // Dummy for examples using it 81 | 82 | #elif defined(STM32F1xx) || defined(__STM32F1__) 83 | // BluePill in 2 flavors 84 | // STM32F1xx is for "Generic STM32F1 series" from STM32 Boards from STM32 cores of Arduino Board manager 85 | // __STM32F1__is for "Generic STM32F103C series" from STM32F1 Boards (STM32duino.com) of Arduino Board manager 86 | #define TONE_PIN 2 87 | #define ANALOG_INPUT_PIN PA0 88 | #define ECHO_IN_PIN PB0 89 | #define TRIGGER_OUT_PIN PB1 90 | 91 | #else 92 | #define ECHO_IN_PIN 4 93 | #define TRIGGER_OUT_PIN 5 94 | #define TONE_PIN 3 // must be 3 to be compatible with talkie 95 | #define TONE_PIN_INVERTED 11 // must be 11 to be compatible with talkie 96 | #define ANALOG_INPUT_PIN A0 97 | #endif 98 | 99 | // for ESP32 LED_BUILTIN is defined as: static const uint8_t LED_BUILTIN 2 100 | #if !defined(LED_BUILTIN) && !defined(ESP32) 101 | #define LED_BUILTIN PB1 102 | #endif 103 | // On the Zero and others we switch explicitly to SerialUSB 104 | #if defined(ARDUINO_ARCH_SAMD) 105 | #define Serial SerialUSB 106 | // The Chinese SAMD21 M0-Mini clone has no led connected, if you connect it, it is on pin 24 like on the original board. 107 | // Attention! D2 and D4 are swapped on these boards 108 | //#undef LED_BUILTIN 109 | //#define LED_BUILTIN 25 // Or choose pin 25, it is the RX pin, but active low. 110 | #endif 111 | -------------------------------------------------------------------------------- /extras/Arduino_Nano_DSO_Schaltplan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-BlueDisplay/09ae320970c40395356c8693c35459903940334f/extras/Arduino_Nano_DSO_Schaltplan.png -------------------------------------------------------------------------------- /extras/Arduino_Nano_DSO_Simple_Schaltplan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-BlueDisplay/09ae320970c40395356c8693c35459903940334f/extras/Arduino_Nano_DSO_Simple_Schaltplan.png -------------------------------------------------------------------------------- /extras/Arduino_Nano_DSO_Simple_Steckplatine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-BlueDisplay/09ae320970c40395356c8693c35459903940334f/extras/Arduino_Nano_DSO_Simple_Steckplatine.png -------------------------------------------------------------------------------- /extras/Arduino_Nano_DSO_Steckplatine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-BlueDisplay/09ae320970c40395356c8693c35459903940334f/extras/Arduino_Nano_DSO_Steckplatine.png -------------------------------------------------------------------------------- /extras/BlueDisplayBlink.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-BlueDisplay/09ae320970c40395356c8693c35459903940334f/extras/BlueDisplayBlink.fzz -------------------------------------------------------------------------------- /extras/BlueDisplayBlink_Schaltplan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-BlueDisplay/09ae320970c40395356c8693c35459903940334f/extras/BlueDisplayBlink_Schaltplan.png -------------------------------------------------------------------------------- /extras/BlueDisplayBlink_Steckplatine.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-BlueDisplay/09ae320970c40395356c8693c35459903940334f/extras/BlueDisplayBlink_Steckplatine.png -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "BlueDisplay", 3 | "version": "5.0.0", 4 | "description": "This library enables an Android smartphone or tablet to act as a graphical display for your Arduino.", 5 | "keywords": "Bluetooth, display, remote, graphics, GUI", 6 | "homepage": "https://github.com/ArminJo/Arduino-BlueDisplay", 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/ArminJo/Arduino-BlueDisplay.git" 10 | }, 11 | "authors": { 12 | "name": "Armin Joachimsmeyer", 13 | "email": "armin.arduino@gmail.com", 14 | "maintainer": true 15 | }, 16 | "license": "GPL-3.0-or-later", 17 | "frameworks": "arduino", 18 | "platforms": ["atmelavr", "atmelmegaavr", "espressif8266", "espressif32", "ststm32"], 19 | "headers": "BlueDisplay.h", 20 | "examples": "examples/*/*.ino", 21 | "export": {"exclude": [".github", "pictures"]} 22 | } -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=BlueDisplay 2 | version=5.0.0 3 | author=Armin Joachimsmeyer 4 | maintainer=Armin Joachimsmeyer 5 | sentence=This library enables an Android smartphone or tablet to act as a graphical display for your Arduino. 6 | paragraph=Let your Arduino program create a GUI with Graphics, Text, Buttons and Sliders on your smartphone or tablet by simply connecting a HC-05 to the rx/tx pins of your Arduino. No Android programming required! 7 | category=Communication 8 | url=https://github.com/ArminJo/Arduino-BlueDisplay 9 | architectures=avr,esp8266,esp32,stm32,STM32F1,sam 10 | includes=BlueDisplay.hpp 11 | -------------------------------------------------------------------------------- /pictures/AccelerometerOnPlotter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-BlueDisplay/09ae320970c40395356c8693c35459903940334f/pictures/AccelerometerOnPlotter.png -------------------------------------------------------------------------------- /pictures/ArduinoDSO_Simple.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-BlueDisplay/09ae320970c40395356c8693c35459903940334f/pictures/ArduinoDSO_Simple.jpg -------------------------------------------------------------------------------- /pictures/BTModuleProgrammer.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-BlueDisplay/09ae320970c40395356c8693c35459903940334f/pictures/BTModuleProgrammer.jpg -------------------------------------------------------------------------------- /pictures/Blink.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-BlueDisplay/09ae320970c40395356c8693c35459903940334f/pictures/Blink.jpg -------------------------------------------------------------------------------- /pictures/BlueDisplayBlink_off.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-BlueDisplay/09ae320970c40395356c8693c35459903940334f/pictures/BlueDisplayBlink_off.jpg -------------------------------------------------------------------------------- /pictures/BlueDisplayBlink_on.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-BlueDisplay/09ae320970c40395356c8693c35459903940334f/pictures/BlueDisplayBlink_on.jpg -------------------------------------------------------------------------------- /pictures/BlueDisplayExample.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-BlueDisplay/09ae320970c40395356c8693c35459903940334f/pictures/BlueDisplayExample.jpg -------------------------------------------------------------------------------- /pictures/BlueDisplayExample_Test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-BlueDisplay/09ae320970c40395356c8693c35459903940334f/pictures/BlueDisplayExample_Test.jpg -------------------------------------------------------------------------------- /pictures/ChartForMHZ19_CO2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-BlueDisplay/09ae320970c40395356c8693c35459903940334f/pictures/ChartForMHZ19_CO2.png -------------------------------------------------------------------------------- /pictures/ChartPage.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-BlueDisplay/09ae320970c40395356c8693c35459903940334f/pictures/ChartPage.bmp -------------------------------------------------------------------------------- /pictures/Distance+Smartphone.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-BlueDisplay/09ae320970c40395356c8693c35459903940334f/pictures/Distance+Smartphone.jpg -------------------------------------------------------------------------------- /pictures/DrawPage.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-BlueDisplay/09ae320970c40395356c8693c35459903940334f/pictures/DrawPage.bmp -------------------------------------------------------------------------------- /pictures/GameOfLife.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-BlueDisplay/09ae320970c40395356c8693c35459903940334f/pictures/GameOfLife.bmp -------------------------------------------------------------------------------- /pictures/GameOfLifeStartPage.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-BlueDisplay/09ae320970c40395356c8693c35459903940334f/pictures/GameOfLifeStartPage.bmp -------------------------------------------------------------------------------- /pictures/ManySlidersAndButtons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-BlueDisplay/09ae320970c40395356c8693c35459903940334f/pictures/ManySlidersAndButtons.png -------------------------------------------------------------------------------- /pictures/RCCar+Tablet.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-BlueDisplay/09ae320970c40395356c8693c35459903940334f/pictures/RCCar+Tablet.jpg -------------------------------------------------------------------------------- /pictures/RCCarControl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-BlueDisplay/09ae320970c40395356c8693c35459903940334f/pictures/RCCarControl.png -------------------------------------------------------------------------------- /pictures/Screenshot_20201015-145931.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-BlueDisplay/09ae320970c40395356c8693c35459903940334f/pictures/Screenshot_20201015-145931.jpg -------------------------------------------------------------------------------- /pictures/ServoExample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-BlueDisplay/09ae320970c40395356c8693c35459903940334f/pictures/ServoExample.png -------------------------------------------------------------------------------- /pictures/ServoExample_Bias.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-BlueDisplay/09ae320970c40395356c8693c35459903940334f/pictures/ServoExample_Bias.png -------------------------------------------------------------------------------- /pictures/SettingsPage.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-BlueDisplay/09ae320970c40395356c8693c35459903940334f/pictures/SettingsPage.bmp -------------------------------------------------------------------------------- /pictures/TouchGuiDemoMainPage.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArminJo/Arduino-BlueDisplay/09ae320970c40395356c8693c35459903940334f/pictures/TouchGuiDemoMainPage.bmp -------------------------------------------------------------------------------- /src/BlueDisplayUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BlueDisplayUtils.h 3 | * 4 | * Convenience functions using BlueDisplay 5 | * 6 | * Copyright (C) 2023 Armin Joachimsmeyer 7 | * armin.joachimsmeyer@gmail.com 8 | * 9 | * This file is part of BlueDisplay https://github.com/ArminJo/android-blue-display. 10 | * 11 | * BlueDisplay is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 19 | * See the GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | * 24 | */ 25 | 26 | #ifndef _BLUEDISPLAY_UTILS_H 27 | #define _BLUEDISPLAY_UTILS_H 28 | 29 | #include "BlueDisplay.h" 30 | 31 | void printVCCAndTemperaturePeriodically(BlueDisplay &aBlueDisplay, uint16_t aXPos, uint16_t aYPos, uint16_t aFontSize, uint16_t aPeriodMillis); 32 | 33 | #endif // _BLUEDISPLAY_UTILS_H 34 | -------------------------------------------------------------------------------- /src/BlueDisplayUtils.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * BlueDisplayUtils.hpp 3 | * 4 | * C stub for the Android BlueDisplay app (and the local LCD screens with SSD1289 (on HY32D board) or HX8347 (on MI0283QT2 board) controller. 5 | * 6 | * It implements also a few display test functions. 7 | * 8 | * SUMMARY 9 | * Blue Display is an Open Source Android remote Display for Arduino etc. 10 | * It receives basic draw requests from Arduino etc. over Bluetooth and renders it. 11 | * It also implements basic GUI elements as buttons and sliders. 12 | * GUI callback, touch and sensor events are sent back to Arduino. 13 | * 14 | * Copyright (C) 2014-2023 Armin Joachimsmeyer 15 | * armin.joachimsmeyer@gmail.com 16 | * 17 | * This file is part of BlueDisplay https://github.com/ArminJo/android-blue-display. 18 | * 19 | * BlueDisplay is free software: you can redistribute it and/or modify 20 | * it under the terms of the GNU General Public License as published by 21 | * the Free Software Foundation, either version 3 of the License, or 22 | * (at your option) any later version. 23 | * 24 | * This program is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 27 | * See the GNU General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU General Public License 30 | * along with this program. If not, see . 31 | * 32 | */ 33 | #ifndef _BLUEDISPLAY_UTILS_HPP 34 | #define _BLUEDISPLAY_UTILS_HPP 35 | 36 | #include "BlueDisplayUtils.h" 37 | 38 | #include "ADCUtils.hpp" // for getCPUTemperature() and getVCCVoltage() 39 | /* 40 | * Show temperature and VCC voltage 41 | */ 42 | void printVCCAndTemperaturePeriodically(BlueDisplay &aBlueDisplay, uint16_t aXPos, uint16_t aYPos, uint16_t aFontSize, 43 | uint16_t aPeriodMillis) { 44 | #if defined (AVR) 45 | static unsigned long sMillisOfLastVCCInfo = 0; 46 | uint32_t tMillis = millis(); 47 | 48 | if ((tMillis - sMillisOfLastVCCInfo) >= aPeriodMillis) { 49 | sMillisOfLastVCCInfo = tMillis; 50 | 51 | char tDataBuffer[18]; 52 | char tVCCString[6]; 53 | char tTempString[6]; 54 | 55 | float tTemp = getCPUTemperature(); 56 | dtostrf(tTemp, 4, 1, tTempString); 57 | 58 | float tVCCvoltage = getVCCVoltage(); 59 | dtostrf(tVCCvoltage, 4, 2, tVCCString); 60 | 61 | snprintf_P(tDataBuffer, sizeof(tDataBuffer), PSTR("%s volt %s\xB0" "C"), tVCCString, tTempString); // \xB0 is degree character 62 | aBlueDisplay.drawText(aXPos, aYPos, tDataBuffer, aFontSize, COLOR16_BLACK, COLOR16_WHITE); 63 | } 64 | #else 65 | // No dtostrf() and no getCPUTemperature() and getVCCVoltage() 66 | (void)aBlueDisplay; 67 | (void)aXPos; 68 | (void)aYPos; 69 | (void)aFontSize; 70 | (void)aPeriodMillis; 71 | #endif 72 | } 73 | 74 | #endif // _BLUEDISPLAY_UTILS_HPP 75 | -------------------------------------------------------------------------------- /src/BlueSerial.h: -------------------------------------------------------------------------------- 1 | /* 2 | * BlueSerial.h 3 | * 4 | * 5 | * Copyright (C) 2014-2023 Armin Joachimsmeyer 6 | * armin.joachimsmeyer@gmail.com 7 | * 8 | * This file is part of BlueDisplay https://github.com/ArminJo/android-blue-display. 9 | * 10 | * BlueDisplay is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | * See the GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | #ifndef _BLUESERIAL_H 25 | #define _BLUESERIAL_H 26 | 27 | #if defined(ARDUINO) 28 | #include // for UBRR1H + BOARD_HAVE_USART1 + SERIAL_USB 29 | #elif defined(STM32F10X) 30 | #include 31 | #include 32 | #elif defined(STM32F30X) 33 | #include 34 | #include "stm32f3xx_hal_conf.h" // for UART_HandleTypeDef 35 | #include 36 | #endif 37 | 38 | #include "Colors.h" 39 | 40 | /* 41 | * Simple serial is a simple blocking serial version without receive buffer and other overhead. 42 | * Simple serial on the MEGA2560 uses USART1 43 | */ 44 | //#define BD_USE_SIMPLE_SERIAL // Do not use the Serial object. Saves up to 1250 bytes program memory and 185 bytes RAM, if Serial is not used otherwise 45 | #if defined(SERIAL_PORT_HARDWARE1) // is defined for Arduino Due 46 | #define BOARD_HAVE_USART2 // they start counting with 0 47 | #endif 48 | 49 | // If Serial1 is available, but you want to use direct connection by USB to your smartphone / tablet, 50 | // then you have to activate the next line 51 | //#define BD_USE_USB_SERIAL 52 | 53 | /* 54 | * Determine which serial to use. 55 | * - Use standard Serial if BD_USE_USB_SERIAL is requested. 56 | * - Prefer the use of second USART for BlueDisplay communication, to have the standard Serial available for application (debug) use except for ATmega328P and PB. 57 | * - Use Serial1 on stm32 if SERIAL_USB and USART1 is existent. If no SERIAL_USB existent, it requires USART2 to have Serial1 available. 58 | * - Use Serial1 on AVR if second USART is existent, as on the ATmega Boards. 59 | */ 60 | // In some cores for ATmega328PB only ATmega328P is defined 61 | #if ! defined(BD_USE_USB_SERIAL) && ! defined(__AVR_ATmega328P__) && ! defined(__AVR_ATmega328PB__) && ((defined(BOARD_HAVE_USART1) && defined(SERIAL_USB)) \ 62 | || (defined(BOARD_HAVE_USART2) && ! defined(SERIAL_USB)) \ 63 | || defined(UBRR1H) || /*BluePill*/(defined(USBD_USE_CDC) && defined(USART2))) 64 | #define BD_USE_SERIAL1 65 | #endif 66 | 67 | #define BAUD_STRING_4800 "4800" 68 | #define BAUD_STRING_9600 "9600" 69 | #define BAUD_STRING_19200 "19200" 70 | #define BAUD_STRING_38400 "38400" 71 | #define BAUD_STRING_57600 "57600" 72 | #define BAUD_STRING_115200 "115200" 73 | #define BAUD_STRING_230400 "230400" 74 | #define BAUD_STRING_460800 "460800" 75 | #define BAUD_STRING_921600 " 921600" 76 | #define BAUD_STRING_1382400 "1382400" 77 | 78 | #define BAUD_4800 (4800) 79 | #define BAUD_9600 (9600) 80 | #define BAUD_19200 (19200) 81 | #define BAUD_38400 (38400) 82 | #define BAUD_57600 (57600) 83 | #define BAUD_115200 (115200) 84 | #define BAUD_230400 (230400) 85 | #define BAUD_460800 (460800) 86 | #define BAUD_921600 ( 921600) 87 | #define BAUD_1382400 (1382400) 88 | 89 | /* 90 | * Common functions which are independent of using simple or standard serial 91 | */ 92 | /* 93 | * Checks if additional remote display is paired to avoid program slow down by UART sending to a not paired connection 94 | * 95 | * USART_isBluetoothPaired() is only required if defined(SUPPORT_REMOTE_AND_LOCAL_DISPLAY) 96 | * to disable sending by Bluetooth if BT is not connected. 97 | * It is reduced to return false if defined(DISABLE_REMOTE_DISPLAY) 98 | * It is reduced to return true if not defined(SUPPORT_REMOTE_AND_LOCAL_DISPLAY) 99 | */ 100 | bool USART_isBluetoothPaired(void); 101 | #if !defined(PAIRED_PIN) && defined(SUPPORT_REMOTE_AND_LOCAL_DISPLAY) 102 | #define PAIRED_PIN 5 103 | #endif 104 | void setUsePairedPin(bool aUsePairedPin); 105 | 106 | void sendUSARTArgs(uint8_t aFunctionTag, uint_fast8_t aNumberOfArgs, ...); 107 | void sendUSARTArgsAndByteBuffer(uint8_t aFunctionTag, uint_fast8_t aNumberOfArgs, ...); 108 | void sendUSART5Args(uint8_t aFunctionTag, uint16_t aStartX, uint16_t aStartY, uint16_t aEndX, uint16_t aEndY, color16_t aColor); 109 | // used internal by the above functions 110 | void sendUSARTBufferNoSizeCheck(uint8_t *aParameterBufferPointer, uint8_t aParameterBufferLength, uint8_t *aDataBufferPointer, 111 | size_t aDataBufferLength); 112 | 113 | /* 114 | * Functions only valid for standard serial 115 | */ 116 | #if !defined(BD_USE_SIMPLE_SERIAL) 117 | uint8_t getReceiveBufferByte(void); 118 | void serialEvent(void); // Is called by Arduino runtime in main loop, if (Serial0_available && serialEvent && Serial0_available()) serialEvent(); 119 | #endif 120 | 121 | #if defined(ARDUINO) 122 | bool isReceivingActive(); 123 | size_t getReceiveBytesAvailable(void); 124 | 125 | /* 126 | * Functions which depends on using simple or standard serial on AVR 127 | */ 128 | void initSerial(); 129 | 130 | #if defined(ESP32) 131 | void initSerial(String aBTClientName); 132 | #else 133 | void initSerial(uint32_t aBaudRate); 134 | #endif 135 | void clearSerialInputBuffer(); 136 | 137 | void sendUSART(char aChar); 138 | void sendUSART(const char *aString); 139 | #endif 140 | 141 | /* 142 | * Functions only valid for simple serial 143 | */ 144 | #if defined(BD_USE_SIMPLE_SERIAL) 145 | void initSimpleSerial(uint32_t aBaudRate); 146 | void initSimpleSerial(uint32_t aBaudRate, bool aUsePairedPin); 147 | #endif 148 | 149 | #if defined(STM32F303xC) || defined(STM32F103xB) 150 | /* 151 | * Stuff for STM 152 | */ 153 | #ifdef STM32F303xC 154 | #define UART_BD USART3 155 | #define UART_BD_TX_PIN GPIO_PIN_10 156 | #define UART_BD_RX_PIN GPIO_PIN_11 157 | #define UART_BD_PORT GPIOC 158 | #define UART_BD_IO_CLOCK_ENABLE() __GPIOC_CLK_ENABLE() 159 | #define UART_BD_CLOCK_ENABLE() __USART3_CLK_ENABLE() 160 | #define UART_BD_IRQ USART3_IRQn 161 | #define UART_BD_IRQHANDLER USART3_IRQHandler 162 | 163 | #define UART_BD_DMA_TX_CHANNEL DMA1_Channel2 164 | #define UART_BD_DMA_RX_CHANNEL DMA1_Channel3 165 | #define UART_BD_DMA_CLOCK_ENABLE() __DMA1_CLK_ENABLE() 166 | 167 | #define BLUETOOTH_PAIRED_DETECT_PIN GPIO_PIN_13 168 | #define BLUETOOTH_PAIRED_DETECT_PORT GPIOC 169 | #endif 170 | 171 | #ifdef STM32F103xB 172 | #define UART_BD USART1 173 | #define UART_BD_TX_PIN GPIO_PIN_9 174 | #define UART_BD_RX_PIN GPIO_PIN_10 175 | #define UART_BD_PORT GPIOA 176 | #define UART_BD_IO_CLOCK_ENABLE() __GPIOA_CLK_ENABLE() 177 | #define UART_BD_CLOCK_ENABLE() __USART1_CLK_ENABLE() 178 | #define UART_BD_IRQ USART1_IRQn 179 | #define UART_BD_IRQHANDLER USART1_IRQHandler 180 | 181 | #define UART_BD_DMA_TX_CHANNEL DMA1_Channel4 182 | #define UART_BD_DMA_RX_CHANNEL DMA1_Channel5 183 | #define UART_BD_DMA_CLOCK_ENABLE() __DMA1_CLK_ENABLE() 184 | 185 | #define BLUETOOTH_PAIRED_DETECT_PIN GPIO_PIN_7 186 | #define BLUETOOTH_PAIRED_DETECT_PORT GPIOA 187 | #endif 188 | 189 | // The UART used by BlueDisplay 190 | extern UART_HandleTypeDef UART_BD_Handle; 191 | #ifdef __cplusplus 192 | extern "C" { 193 | #endif 194 | void UART_BD_IRQHANDLER(void); 195 | #ifdef __cplusplus 196 | } 197 | #endif 198 | 199 | // Send functions using buffer and DMA 200 | int getSendBufferFreeSpace(void); 201 | 202 | void UART_BD_initialize(uint32_t aBaudRate); 203 | void HAL_UART_MspInit(UART_HandleTypeDef* aUARTHandle); 204 | 205 | uint32_t getUSART_BD_BaudRate(void); 206 | void setUART_BD_BaudRate(uint32_t aBaudRate); 207 | 208 | // Simple blocking serial version without overhead 209 | void sendUSARTBufferSimple(uint8_t * aParameterBufferPointer, size_t aParameterBufferLength, 210 | uint8_t * aDataBufferPointer, size_t aDataBufferLength); 211 | 212 | #endif // defined(__AVR__) 213 | #endif // _BLUESERIAL_H 214 | -------------------------------------------------------------------------------- /src/Colors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Colors.h 3 | * 4 | * 5 | * Copyright (C) 2018-2021 Armin Joachimsmeyer 6 | * armin.joachimsmeyer@gmail.com 7 | * 8 | * This file is part of BlueDisplay https://github.com/ArminJo/android-blue-display. 9 | * 10 | * BlueDisplay is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | * See the GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | */ 24 | 25 | #ifndef _COLORS_H 26 | #define _COLORS_H 27 | 28 | #include 29 | 30 | /* 31 | * Basic 16 Bit Colors 32 | * RGB to 16 bit 565 schema - 5 red | 6 green | 5 blue 33 | */ 34 | typedef uint16_t color16_t; 35 | 36 | // If used as background color for char or text, the background will not filled 37 | #define COLOR16_BLUEMASK 0x1F 38 | #define COLOR16_GET_RED(rgb) ((rgb & 0xF800) >> 8) 39 | #define COLOR16_GET_GREEN(rgb) ((rgb & 0x07E0) >> 3) 40 | #define COLOR16_GET_BLUE(rgb) ((rgb & 0x001F) << 3) 41 | #define COLOR16(r,g,b) ((color16_t)(((r&0xF8)<<8)|((g&0xFC)<<3)|((b&0xF8)>>3))) // 5 red | 6 green | 5 blue 42 | 43 | #define COLOR16_WHITE ((color16_t)0xFFFF) 44 | #define COLOR16_ALMOST_WHITE ((color16_t)0xF7DE) // Every color is 1 bit less than maximum value, but we can distinguish it from white 45 | 46 | #define COLOR16_NO_BACKGROUND ((color16_t)COLOR16_WHITE - 1) // No background drawing for text and button (Only-text button) 47 | 48 | #define COLOR16_LIGHT_GREY ((color16_t)0x7BEF) 49 | #define COLOR16_GREY ((color16_t)0x39E7) 50 | #define COLOR16_DARK_GREY ((color16_t)0x18E3) 51 | 52 | #define COLOR16_NO_DELETE ((color16_t)0X0001) // 01 is used as flag (e.g. for not delete old chart) 53 | #define COLOR16_BLACK ((color16_t)0X0000) 54 | #define COLOR16_RED ((color16_t)0xF800) 55 | #define COLOR16_GREEN ((color16_t)0X07E0) 56 | #define COLOR16_BLUE ((color16_t)0x001F) 57 | #define COLOR16_DARK_BLUE ((color16_t)0x0014) 58 | #define COLOR16_YELLOW ((color16_t)0XFFE0) 59 | #define COLOR16_ORANGE ((color16_t)0XFE00) 60 | #define COLOR16_PURPLE ((color16_t)0xF81F) 61 | #define COLOR16_CYAN ((color16_t)0x07FF) 62 | 63 | /* 64 | * 32 Bit Color values 65 | */ 66 | typedef uint32_t color32_t; 67 | 68 | #define COLOR32_GET_WHITE(color) ((color >> 24) & 0xFF) 69 | #define COLOR32_GET_RED(color) ((color >> 16) & 0xFF) 70 | #define COLOR32_GET_GREEN(color) ((color >> 8) & 0xFF) 71 | #define COLOR32_GET_BLUE(color) (color & 0xFF) 72 | // Eases constant color declarations but should only be used for constant colors. Otherwise better use Adafruit_NeoPixel::Color() to save program memory 73 | #define COLOR32(r,g,b) ((color32_t)(((uint32_t)r<<16)|((uint16_t)g<<8)|b)) // return ((uint32_t)r << 16) | ((uint32_t)g << 8) | b; 74 | #define COLOR32_W(r,g,b,w) ((color32_t)(((uint32_t)w<<24)|((uint32_t)r<<16)|((uint16_t)g<<8)|b)) // return ((uint32_t)w << 24) |(uint32_t)r << 16) | ((uint32_t)g << 8) | b; 75 | 76 | #define COLOR32_BLACK COLOR32(0,0,0) 77 | 78 | #define COLOR32_WHITE COLOR32(255,255,255) 79 | #define COLOR32_SPECIAL (COLOR32(255,255,255) - 1) // To signal special color treatment e.g. use random color 80 | #define COLOR32_WHITE_HALF COLOR32(128,128,128) // to reduce power consumption 81 | #define COLOR32_WHITE_QUARTER COLOR32(64,64,64) // to reduce power consumption 82 | #define COLOR32_WHITE_EIGHTH COLOR32(32,32,32) // to reduce power consumption 83 | #define COLOR32_WHITE_16TH COLOR32(16,16,16) 84 | #define COLOR32_WHITE_32TH COLOR32(8,8,8) 85 | #define COLOR32_WHITE_64TH COLOR32(4,4,4) 86 | #define COLOR32_WHITE_128TH COLOR32(2,2,2) 87 | #define COLOR32_RED COLOR32(255,0,0) 88 | #define COLOR32_RED_HALF COLOR32(128,0,0) 89 | #define COLOR32_RED_QUARTER COLOR32(64,0,0) 90 | #define COLOR32_GREEN COLOR32(0,255,0) 91 | #define COLOR32_GREEN_HALF COLOR32(0,128,0) 92 | #define COLOR32_GREEN_QUARTER COLOR32(0,64,0) 93 | #define COLOR32_BLUE COLOR32(0,0,255) 94 | #define COLOR32_BLUE_HALF COLOR32(0,0,128) 95 | #define COLOR32_BLUE_QUARTER COLOR32(0,0,64) 96 | #define COLOR32_YELLOW COLOR32(255,200,0) // value was visually determined 97 | #define COLOR32_YELLOW_HALF COLOR32(128,100,0) 98 | #define COLOR32_YELLOW_QUARTER COLOR32(64,50,0) 99 | #define COLOR32_ORANGE COLOR32(255,64,0) // value was visually determined 100 | #define COLOR32_ORANGE_HALF COLOR32(128,32,0) 101 | #define COLOR32_ORANGE_QUARTER COLOR32(64,16,0) 102 | #define COLOR32_PURPLE COLOR32(255,0,255) 103 | #define COLOR32_PURPLE_HALF COLOR32(128,0,128) 104 | #define COLOR32_PURPLE_QUARTER COLOR32(64,0,64) 105 | #define COLOR32_CYAN COLOR32(0,255,255) 106 | #define COLOR32_CYAN_HALF COLOR32(0,128,128) 107 | #define COLOR32_CYAN_QUARTER COLOR32(0,64,64) 108 | 109 | // deprecated 110 | #define COLOR32(r,g,b) ((color32_t)(((uint32_t)r<<16)|((uint16_t)g<<8)|b)) // return ((uint32_t)r << 16) | ((uint32_t)g << 8) | b; 111 | #define COLOR_W32(r,g,b,w) ((color32_t)(((uint32_t)w<<24)|((uint32_t)r<<16)|((uint16_t)g<<8)|b)) // return ((uint32_t)w << 24) |(uint32_t)r << 16) | ((uint32_t)g << 8) | b; 112 | #define WHITE(color) ((color >> 24) & 0xFF) 113 | #define RED(color) ((color >> 16) & 0xFF) 114 | #define GREEN(color) ((color >> 8) & 0xFF) 115 | #define BLUE(color) (color & 0xFF) 116 | // end deprecated 117 | 118 | #endif // _COLORS_H 119 | -------------------------------------------------------------------------------- /src/EventHandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * EventHandler.h 3 | * 4 | * 5 | * Copyright (C) 2014-2025 Armin Joachimsmeyer 6 | * armin.joachimsmeyer@gmail.com 7 | * 8 | * This file is part of BlueDisplay https://github.com/ArminJo/android-blue-display. 9 | * 10 | * BlueDisplay is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | * See the GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | */ 24 | 25 | #ifndef _EVENTHANDLER_H 26 | #define _EVENTHANDLER_H 27 | 28 | #include "Colors.h" 29 | 30 | #if defined(DO_NOT_NEED_TOUCH_AND_SWIPE_EVENTS) // Old value 31 | #define DO_NOT_NEED_LONG_TOUCH_DOWN_AND_SWIPE_EVENTS 32 | #endif 33 | 34 | /* 35 | * If defined, registerDelayCallback() and changeDelayCallback() is used to control a timer for checking for 36 | * auto repeats, moves and long touch. 37 | * Otherwise the main loop has to call checkAndHandleTouchPanelEvents() to detect long touch. 38 | * Move and swipe recognition is currently not implemented in ADS7846.hpp, if USE_TIMER_FOR_PERIODIC_LOCAL_TOUCH_CHECKS is not defined. 39 | */ 40 | //#define USE_TIMER_FOR_PERIODIC_LOCAL_TOUCH_CHECKS // Use registerDelayCallback() and changeDelayCallback() for periodic touch checks 41 | //#define DO_NOT_NEED_BASIC_TOUCH_EVENTS // Disables basic touch events down, move and up. Saves 620 bytes program memory and 36 bytes RAM 42 | 43 | #if !defined(IS_STOP_REQUESTED) 44 | #define IS_STOP_REQUESTED isStopRequested() 45 | #endif 46 | #if !defined(RETURN_IF_STOP) 47 | #define RETURN_IF_STOP if (isStopRequested()) return 48 | #endif 49 | #if !defined(BREAK_IF_STOP) 50 | #define BREAK_IF_STOP if (isStopRequested()) break 51 | #endif 52 | #if !defined(DELAY_AND_RETURN_IF_STOP) 53 | #define DELAY_AND_RETURN_IF_STOP(aDurationMillis) if (delayMillisAndCheckForStop(aDurationMillis)) return 54 | #endif 55 | #if !defined(DELAY_UNTIL_EVENT) 56 | #define DELAY_UNTIL_EVENT(aDurationMillis) delayMillisAndCheckForEvent(aDurationMillis) 57 | #endif 58 | 59 | #if !defined(DISABLE_REMOTE_DISPLAY) 60 | #include "BlueDisplayProtocol.h" 61 | #endif 62 | 63 | extern bool sBDEventJustReceived; // is set to true by handleEvent() and can be reset by main loop. 64 | extern unsigned long sMillisOfLastReceivedBDEvent; // is updated with millis() at each received event. Can be used for timeout detection. 65 | 66 | extern struct BluetoothEvent remoteEvent; 67 | #if defined(__AVR__) && defined(BD_USE_SIMPLE_SERIAL) 68 | // Is used for touch down events and stores its position. If remoteEvent is not empty, it is used as buffer for next regular event to avoid overwriting of remoteEvent 69 | extern struct BluetoothEvent remoteTouchDownEvent; 70 | #endif 71 | 72 | #if defined(SUPPORT_LOCAL_DISPLAY) && defined(LOCAL_DISPLAY_GENERATES_BD_EVENTS) 73 | extern struct BluetoothEvent localTouchEvent; 74 | #endif 75 | 76 | #if !defined(DO_NOT_NEED_BASIC_TOUCH_EVENTS) 77 | // Callbacks 78 | void registerTouchDownCallback(void (*aTouchDownCallback)(struct TouchEvent *aActualPositionPtr)); 79 | void registerTouchMoveCallback(void (*aTouchMoveCallback)(struct TouchEvent *aActualPositionPtr)); 80 | // Touch UP callback 81 | void registerTouchUpCallback(void (*aTouchUpCallback)(struct TouchEvent *aActualPositionPtr)); 82 | void (* getTouchUpCallback(void))(struct TouchEvent * ); // returns current callback function 83 | void setTouchUpCallbackEnabled(bool aTouchUpCallbackEnabled); 84 | extern bool sTouchUpCallbackEnabled; 85 | extern bool sDisableMoveEventsUntilTouchUpIsDone; // Skip all touch move and touch up events until touch is released 86 | 87 | extern struct TouchEvent sCurrentPosition; // for printEventTouchPositionData() 88 | extern bool sTouchIsStillDown; 89 | 90 | # if !defined(ESP32) 91 | // Display X Y touch position on screen 92 | bool isDisplayXYValuesEnabled(void); 93 | void setDisplayXYValuesFlag(bool aEnableDisplay); 94 | void printEventTouchPositionData(int x, int y, color16_t aColor, color16_t aBackColor); 95 | # endif 96 | #endif 97 | 98 | bool isStopRequested(void); 99 | void delayMillisWithCheckAndHandleEvents(unsigned long aDelayMillis); 100 | void delayMillisWithCheckForStartedReceivingAndHandleEvents(unsigned long aDelayMillis); 101 | bool delayMillisAndCheckForEvent(unsigned long aDelayMillis); 102 | bool delayMillisAndCheckForStop(uint16_t aDelayMillis); 103 | 104 | void checkAndHandleEvents(void); 105 | 106 | #if !defined(DO_NOT_NEED_LONG_TOUCH_DOWN_AND_SWIPE_EVENTS) 107 | /* 108 | * Long touch down stuff 109 | */ 110 | #define TOUCH_STANDARD_LONG_TOUCH_TIMEOUT_MILLIS 800 // Millis after which a touch is classified as a long touch 111 | extern void (*sLongTouchDownCallback)(struct TouchEvent*); 112 | extern uint32_t sLongTouchDownTimeoutMillis; 113 | extern bool sDisableTouchUpOnce; // Disable next touch up detection. E.g. because we are already in a touch handler and don't want the end of this touch to be interpreted for a newly displayed button. 114 | 115 | void registerLongTouchDownCallback(void (*aLongTouchCallback)(struct TouchEvent*), uint16_t aLongTouchTimeoutMillis); 116 | /* 117 | * Swipe stuff 118 | */ 119 | void registerSwipeEndCallback(void (*aSwipeEndCallback)(struct Swipe*)); 120 | void setSwipeEndCallbackEnabled(bool aSwipeEndCallbackEnabled); 121 | extern bool sSwipeEndCallbackEnabled; // for temporarily disabling swipe callbacks 122 | #endif 123 | 124 | #if !defined(DO_NOT_NEED_SPEAK_EVENTS) 125 | void registerSpeakingDoneCallback(void (*aSpeakingDoneCallback)(int16_t tErrorCode)); 126 | #endif 127 | 128 | void registerConnectCallback(void (*aConnectCallback)(void)); 129 | 130 | void registerReorientationCallback(void (*aReorientationCallback)(void)); 131 | /* 132 | * Redraw event is intended to redraw screen, if size of display changes. 133 | * Connect and reorientation always include a redraw 134 | */ 135 | void registerRedrawCallback(void (*aRedrawCallback)(void)); 136 | void (* getRedrawCallback(void))(void); 137 | 138 | void registerSensorChangeCallback(uint8_t aSensorType, uint8_t aSensorRate, uint8_t aFilterFlag, 139 | void (*aSensorChangeCallback)(uint8_t aSensorType, struct SensorCallback *aSensorCallbackInfo)); 140 | 141 | // defines for backward compatibility 142 | #define registerSimpleConnectCallback(aConnectCallback) registerConnectCallback(aConnectCallback) 143 | #define registerSimpleResizeAndReconnectCallback(aRedrawCallback) registerRedrawCallback(aRedrawCallback) 144 | #define registerSimpleResizeAndConnectCallback registerRedrawCallback(aRedrawCallback) 145 | #define registerSimpleResizeCallback(aRedrawCallback) registerRedrawCallback(aRedrawCallback) 146 | #define getSimpleResizeAndConnectCallback() getRedrawCallback() 147 | 148 | #ifdef __cplusplus 149 | extern "C" { 150 | #endif 151 | void handleEvent(struct BluetoothEvent *aEvent); // may be called by plain C function 152 | #ifdef __cplusplus 153 | } 154 | #endif 155 | 156 | #endif // _EVENTHANDLER_H 157 | -------------------------------------------------------------------------------- /src/GUIHelper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GUIHelper.h 3 | * 4 | * Definitions for GUI layouts and text sizes 5 | * 6 | * 7 | * Copyright (C) 2014-2025 Armin Joachimsmeyer 8 | * armin.joachimsmeyer@gmail.com 9 | * 10 | * This file is part of BlueDisplay https://github.com/ArminJo/android-blue-display. 11 | * 12 | * BlueDisplay is free software: you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation, either version 3 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * This program is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 20 | * See the GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | * 25 | */ 26 | 27 | #ifndef _GUI_HELPER_H 28 | #define _GUI_HELPER_H 29 | 30 | #include 31 | 32 | #include "LayoutHelper.h" 33 | 34 | /*************************** 35 | * Origin 0.0 is upper left 36 | **************************/ 37 | #define DISPLAY_HALF_VGA_HEIGHT 240 38 | #define DISPLAY_HALF_VGA_WIDTH 320 39 | #define DISPLAY_VGA_HEIGHT 480 40 | #define DISPLAY_VGA_WIDTH 640 41 | #define DISPLAY_DEFAULT_HEIGHT DISPLAY_HALF_VGA_HEIGHT // 240 - value to use if not connected 42 | #define DISPLAY_DEFAULT_WIDTH DISPLAY_HALF_VGA_WIDTH // 320 - value to use if not connected 43 | #define STRING_BUFFER_STACK_SIZE 48 // Size for buffer allocated on stack with "char tStringBuffer[STRING_BUFFER_STACK_SIZE]" for ...PGM() functions. 44 | #define STRING_BUFFER_STACK_SIZE_FOR_DEBUG_WITH_MESSAGE 34 // Size for buffer allocated on stack with "char tStringBuffer[STRING_BUFFER_STACK_SIZE_FOR_DEBUG]" for debug(const char *aMessage,...) functions. 45 | 46 | #if !defined(BACKGROUND_COLOR) 47 | #define BACKGROUND_COLOR COLOR16_WHITE 48 | #endif 49 | 50 | /* 51 | * Some useful text sizes constants 52 | */ 53 | #if defined(SUPPORT_ONLY_TEXT_SIZE_11_AND_22) 54 | #define TEXT_SIZE_11 11 55 | #define TEXT_SIZE_22 22 56 | #else 57 | #define TEXT_SIZE_8 8 58 | #define TEXT_SIZE_9 9 59 | #define TEXT_SIZE_10 10 60 | #define TEXT_SIZE_11 11 61 | #define TEXT_SIZE_12 12 62 | #define TEXT_SIZE_13 13 63 | #define TEXT_SIZE_14 14 64 | #define TEXT_SIZE_16 16 65 | #define TEXT_SIZE_18 18 66 | #define TEXT_SIZE_20 20 67 | #define TEXT_SIZE_22 22 68 | #define TEXT_SIZE_26 26 69 | // for factor 3 of 8*12 font 70 | #define TEXT_SIZE_33 33 71 | // for factor 4 of 8*12 font 72 | #define TEXT_SIZE_44 44 73 | #endif 74 | 75 | // TextWidth = TextSize * 0.6 76 | #if defined(SUPPORT_LOCAL_DISPLAY) 77 | // 8/16 instead of 7/13 to be compatible with 8*12 font 78 | #define TEXT_SIZE_11_WIDTH 8 79 | #define TEXT_SIZE_22_WIDTH 16 80 | #else 81 | #define TEXT_SIZE_11_WIDTH 7 82 | #define TEXT_SIZE_12_WIDTH 7 83 | #define TEXT_SIZE_13_WIDTH 8 84 | #define TEXT_SIZE_14_WIDTH 8 85 | #define TEXT_SIZE_16_WIDTH 10 86 | #define TEXT_SIZE_18_WIDTH 11 87 | #define TEXT_SIZE_22_WIDTH 13 88 | #define TEXT_SIZE_33_WIDTH 20 89 | #define TEXT_SIZE_44_WIDTH 26 90 | #endif 91 | 92 | // TextSize * 1,125 ( 1 + 1/8) 93 | // 12 instead of 11 to be compatible with 8*12 font and have a margin 94 | #define TEXT_SIZE_10_HEIGHT 11 95 | #define TEXT_SIZE_11_HEIGHT 12 96 | #define TEXT_SIZE_12_HEIGHT 13 97 | #define TEXT_SIZE_14_HEIGHT 15 98 | #define TEXT_SIZE_16_HEIGHT 18 99 | #define TEXT_SIZE_18_HEIGHT 20 100 | #define TEXT_SIZE_20_HEIGHT 22 101 | #define TEXT_SIZE_22_HEIGHT 24 102 | #define TEXT_SIZE_33_HEIGHT 36 103 | #define TEXT_SIZE_44_HEIGHT 48 104 | 105 | // TextSize * 0.76 106 | // TextSize * 0.855 to have ASCEND + DECEND = HEIGHT 107 | // 9 instead of 8 to have ASCEND + DECEND = HEIGHT 108 | #define TEXT_SIZE_11_ASCEND 9 109 | #define TEXT_SIZE_12_ASCEND 9 110 | #define TEXT_SIZE_13_ASCEND 10 111 | #define TEXT_SIZE_14_ASCEND 11 112 | #define TEXT_SIZE_16_ASCEND 12 113 | #define TEXT_SIZE_18_ASCEND 14 114 | // 18 instead of 17 to have ASCEND + DECEND = HEIGHT 115 | #define TEXT_SIZE_22_ASCEND 18 116 | #define TEXT_SIZE_33_ASCEND 28 117 | #define TEXT_SIZE_44_ASCEND 37 118 | 119 | // TextSize * 0.24 120 | // TextSize * 0.27 to have ASCEND + DECEND = HEIGHT 121 | #define TEXT_SIZE_11_DECEND 3 122 | #define TEXT_SIZE_11_DECEND 3 123 | // 6 instead of 5 to have ASCEND + DECEND = HEIGHT 124 | #define TEXT_SIZE_22_DECEND 6 125 | #define TEXT_SIZE_33_DECEND 8 126 | #define TEXT_SIZE_44_DECEND 11 127 | 128 | uint16_t getTextHeight(uint16_t aTextSize); 129 | uint16_t getTextWidth(uint16_t aTextSize); 130 | uint16_t getTextAscend(uint16_t aTextSize); 131 | uint16_t getTextAscendMinusDescend(uint16_t aTextSize); 132 | //uint16_t getTextMiddleCorrection(uint16_t aTextSize); 133 | 134 | uint16_t getFontScaleFactorFromTextSize(uint16_t aTextSize); 135 | 136 | /* 137 | * Layout for 320 x 240 screen size 138 | */ 139 | #define LAYOUT_320_WIDTH 320 140 | #define LAYOUT_240_HEIGHT 240 141 | #define LAYOUT_256_HEIGHT 256 142 | 143 | #endif // _GUI_HELPER_H 144 | -------------------------------------------------------------------------------- /src/GUIHelper.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * GUIHelper.hpp 3 | * 4 | * Helper functions for text sizes etc. 5 | * 6 | * Text Y and X position is upper left corner of character 7 | * Text Y bottom position is position + TextSize 8 | * Text Y middle position is position + TextSize / 2 9 | * 10 | * 11 | * Copyright (C) 2023-2025 Armin Joachimsmeyer 12 | * armin.joachimsmeyer@gmail.com 13 | * 14 | * This file is part of BlueDisplay https://github.com/ArminJo/android-blue-display. 15 | * 16 | * BlueDisplay is free software: you can redistribute it and/or modify 17 | * it under the terms of the GNU General Public License as published by 18 | * the Free Software Foundation, either version 3 of the License, or 19 | * (at your option) any later version. 20 | * 21 | * This program is distributed in the hope that it will be useful, 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 24 | * See the GNU General Public License for more details. 25 | * 26 | * You should have received a copy of the GNU General Public License 27 | * along with this program. If not, see . 28 | * 29 | */ 30 | #ifndef _GUI_HELPER_HPP 31 | #define _GUI_HELPER_HPP 32 | 33 | #include "GUIHelper.h" 34 | 35 | //#define SUPPORT_ONLY_TEXT_SIZE_11_AND_22 36 | /* 37 | * TextSize * 1,125 (* (1 + 1/8)) 38 | */ 39 | uint16_t getTextHeight(uint16_t aTextSize) { 40 | #if defined(SUPPORT_ONLY_TEXT_SIZE_11_AND_22) 41 | if (aTextSize == 11) { 42 | return TEXT_SIZE_11_HEIGHT; 43 | } 44 | return TEXT_SIZE_22_HEIGHT; 45 | #else 46 | return aTextSize + aTextSize / 8; // TextSize * 1,125 47 | #endif 48 | } 49 | 50 | /* 51 | * Formula for Monospace Font on Android 52 | * TextSize * 0.6 53 | * Integer Formula (rounded): (TextSize *6)+4 / 10 54 | */ 55 | uint16_t getTextWidth(uint16_t aTextSize) { 56 | #if defined(SUPPORT_ONLY_TEXT_SIZE_11_AND_22) 57 | if (aTextSize == 11) { 58 | return TEXT_SIZE_11_WIDTH; 59 | } 60 | return TEXT_SIZE_22_WIDTH; 61 | #else 62 | return ((aTextSize * 6) + 4) / 10; 63 | #endif 64 | } 65 | 66 | /* 67 | * The part of text above baseline 68 | * Formula for Monospace Font on Android 69 | * float: TextSize * 0.76 70 | * int: (TextSize * 195 + 128) >> 8 71 | */ 72 | uint16_t getTextAscend(const uint16_t aTextSize) { 73 | #if defined(SUPPORT_ONLY_TEXT_SIZE_11_AND_22) 74 | if (aTextSize == TEXT_SIZE_11) { 75 | return TEXT_SIZE_11_ASCEND; 76 | } 77 | return TEXT_SIZE_22_ASCEND; 78 | #else 79 | uint32_t tRetvalue = aTextSize; 80 | tRetvalue = ((tRetvalue * 195) + 128) >> 8; 81 | return tRetvalue; 82 | #endif 83 | } 84 | 85 | /* 86 | * The part of text below baseline 87 | * Formula for Monospace Font on Android 88 | * float: TextSize * 0.24 89 | * int: (TextSize * 61 + 128) >> 8 90 | */ 91 | uint16_t getTextDecend(uint16_t aTextSize) { 92 | #if defined(SUPPORT_ONLY_TEXT_SIZE_11_AND_22) 93 | if (aTextSize == TEXT_SIZE_11) { 94 | return TEXT_SIZE_11_DECEND; 95 | } 96 | return TEXT_SIZE_22_DECEND; 97 | #else 98 | uint32_t tRetvalue = aTextSize; 99 | tRetvalue = ((tRetvalue * 61) + 128) >> 8; 100 | return tRetvalue; 101 | #endif 102 | } 103 | /* 104 | * Ascend - Decent 105 | */ 106 | uint16_t getTextAscendMinusDescend(uint16_t aTextSize) { 107 | #if defined(SUPPORT_ONLY_TEXT_SIZE_11_AND_22) 108 | if (aTextSize == TEXT_SIZE_11) { 109 | return TEXT_SIZE_11_ASCEND - TEXT_SIZE_11_DECEND; 110 | } 111 | return TEXT_SIZE_22_ASCEND - TEXT_SIZE_22_DECEND; 112 | #else 113 | uint32_t tRetvalue = aTextSize; 114 | tRetvalue = ((tRetvalue * 133) + 128) >> 8; 115 | return tRetvalue; 116 | #endif 117 | } 118 | 119 | /* 120 | * getTextMiddle is ((Ascend - Decent) / 2) 121 | * 122 | * It is used to position text in the middle of a button or line 123 | * The text ascend is greater than the descend, so the middle of the text is above the Y position 124 | * Correct it with YPosition + (getTextAscendMinusDescend() / 2) to get the YPosition lower 125 | * Formula for positioning in the middle of a button: 126 | * YPosition = ButtonTop + (ButtonHeight + getTextAscendMinusDescend())/2 127 | */ 128 | //uint16_t getTextMiddleCorrection(uint16_t aTextSize) { 129 | //#if defined(SUPPORT_ONLY_TEXT_SIZE_11_AND_22) 130 | // if (aTextSize == TEXT_SIZE_11) { 131 | // return (TEXT_SIZE_11_ASCEND - TEXT_SIZE_11_DECEND) / 2; 132 | // } 133 | // return (TEXT_SIZE_22_ASCEND - TEXT_SIZE_22_DECEND) / 2; 134 | //#else 135 | // uint32_t tRetvalue = aTextSize; 136 | // tRetvalue = ((tRetvalue * 66) + 128) >> 8; 137 | // return tRetvalue; 138 | //#endif 139 | //} 140 | 141 | /* 142 | * Fast divide by 11 for MI0283QT2 driver arguments 143 | */ 144 | uint16_t getFontScaleFactorFromTextSize(uint16_t aTextSize) { 145 | #if defined(SUPPORT_ONLY_TEXT_SIZE_11_AND_22) 146 | if (aTextSize <= 11) { 147 | return 1; 148 | } 149 | return 2; 150 | #else 151 | return aTextSize / 11; 152 | #endif 153 | } 154 | #endif // _GUI_HELPER_HPP 155 | -------------------------------------------------------------------------------- /src/LocalDisplay/ADS7846.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ADS7846.h 3 | * 4 | * Copyright (C) 2012-2023 Armin Joachimsmeyer 5 | * armin.joachimsmeyer@gmail.com 6 | * 7 | * This file is part of BlueDisplay https://github.com/ArminJo/android-blue-display. 8 | * 9 | * BlueDisplay is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 17 | * See the GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef _ADS7846_H 25 | #define _ADS7846_H 26 | 27 | #include 28 | #include "BlueDisplayProtocol.h" // for struct XYPosition 29 | 30 | #define CAL_POINT_X1 (20) 31 | #define CAL_POINT_Y1 (20) 32 | #define CAL_POINT1 {CAL_POINT_X1,CAL_POINT_Y1} 33 | 34 | #define CAL_POINT_X2 (300) 35 | #define CAL_POINT_Y2 (120) 36 | #define CAL_POINT2 {CAL_POINT_X2,CAL_POINT_Y2} 37 | 38 | #define CAL_POINT_X3 (160) 39 | #define CAL_POINT_Y3 (220) 40 | #define CAL_POINT3 {CAL_POINT_X3,CAL_POINT_Y3} 41 | 42 | #define MIN_REASONABLE_PRESSURE 9 // depends on position :-(( even slight touch gives more than this 43 | #define MAX_REASONABLE_PRESSURE 110 // Greater means panel not connected 44 | /* 45 | * without oversampling data is very noisy i.e oversampling of 2 is not suitable for drawing (it gives x +/-1 and y +/-2 pixel noise) 46 | * since Y value has much more noise than X, Y is oversampled 2 times. 47 | * 4 is reasonable, 8 is pretty good y +/-1 pixel 48 | */ 49 | #define ADS7846_READ_OVERSAMPLING_DEFAULT 4 50 | 51 | // A/D input channel for readChannel() 52 | #define CMD_TEMP0 (0x00) 53 | // 2,5V reference 2,1 mV/Celsius 600 mV at 25 Celsius 12 Bit 54 | // 25 Celsius reads 983 / 0x3D7 and 1 celsius is 3,44064 => Celsius is 897 / 0x381 55 | #define CMD_X_POS (0x10) 56 | #define CMD_BATT (0x20) // read Vcc /4 57 | #define CMD_Z1_POS (0x30) 58 | #define CMD_Z2_POS (0x40) 59 | #define CMD_Y_POS (0x50) 60 | #define CMD_AUX (0x60) 61 | #define CMD_TEMP1 (0x70) 62 | 63 | #define CHANNEL_MASK (0x70) 64 | 65 | #define CMD_START (0x80) 66 | #define CMD_12BIT (0x00) 67 | #define CMD_8BIT (0x08) 68 | #define CMD_DIFF (0x00) 69 | #define CMD_SINGLE (0x04) 70 | 71 | typedef struct { 72 | long x; 73 | long y; 74 | } CAL_POINT; // only for calibrating purposes 75 | 76 | typedef struct { 77 | long a; 78 | long b; 79 | long c; 80 | long d; 81 | long e; 82 | long f; 83 | long div; 84 | } CAL_MATRIX; 85 | 86 | #define ADS7846_CHANNEL_COUNT 8 // The number of ADS7846 channel 87 | extern const char *const ADS7846ChannelStrings[ADS7846_CHANNEL_COUNT]; 88 | extern const char ADS7846ChannelChars[ADS7846_CHANNEL_COUNT]; 89 | // Channel number to text mapping 90 | extern unsigned char ADS7846ChannelMapping[ADS7846_CHANNEL_COUNT]; 91 | 92 | class ADS7846 { 93 | public: 94 | 95 | struct XYPosition mCurrentTouchPosition; // calibrated (screen) position 96 | struct XYPosition mLastTouchPosition; // for suppressing of pseudo or micro moves for generating of move event and for touch up event position 97 | struct XYPosition mTouchDownPosition; // Required for move, long touch down and swipe 98 | uint8_t mPressure; // touch panel pressure can be 0 or >= MIN_REASONABLE_PRESSURE 99 | 100 | #if defined(__AVR__) 101 | bool ADS7846TouchActive = false; // is true as long as touch lasts 102 | bool ADS7846TouchStart = false; // is true once for every touch is reset by call to 103 | #else 104 | volatile bool ADS7846TouchActive = false; // is true as long as touch lasts 105 | volatile bool ADS7846TouchStart = false; // is true once for every touch - independent from calling mLongTouchCallback 106 | #endif 107 | 108 | ADS7846(); 109 | void init(void); 110 | void readData(void); 111 | uint8_t getPressure(void); 112 | bool wasJustTouched(void); 113 | 114 | #if defined(__AVR__) 115 | void doCalibration(uint16_t eeprom_addr, bool check_eeprom); 116 | void initAndCalibrateOnPress(uint16_t eeprom_addr); 117 | #else 118 | void readData(uint8_t aOversampling); 119 | void doCalibration(bool aCheckRTC); 120 | void initAndCalibrateOnPress(); 121 | #endif 122 | 123 | uint16_t getRawX(void); 124 | uint16_t getRawY(void); 125 | uint16_t getCurrentX(void); 126 | uint16_t getCurrentY(void); 127 | 128 | uint16_t readChannel(uint8_t channel, bool use12Bit, bool useDiffMode, uint8_t numberOfReadingsToIntegrate); 129 | 130 | #if defined(__AVR__) 131 | bool writeCalibration(uint16_t eeprom_addr); 132 | bool readCalibration(uint16_t eeprom_addr); 133 | #else 134 | void writeCalibration(CAL_MATRIX aMatrix); 135 | void readCalibration(CAL_MATRIX *aMatrix); 136 | #endif 137 | 138 | private: 139 | struct XYPosition mTouchActualPositionRaw; // raw pos (touch panel) 140 | struct XYPosition mTouchLastCalibratedPositionRaw; // last calibrated raw pos - to avoid calibrating the same position twice 141 | 142 | CAL_MATRIX tp_matrix; //calibrate matrix 143 | bool setCalibration(CAL_POINT *lcd, CAL_POINT *tp); 144 | void calibrate(void); 145 | 146 | #if defined(__AVR__) 147 | uint8_t rd_spi(void); 148 | void wr_spi(uint8_t data); 149 | #endif 150 | }; 151 | extern ADS7846 TouchPanel; // The instance provided by the class itself 152 | 153 | #endif //_ADS7846_H 154 | -------------------------------------------------------------------------------- /src/LocalDisplay/HX8347D.h: -------------------------------------------------------------------------------- 1 | /* 2 | * HX8347D.h 3 | * 4 | * Copyright (C) 2012-2023 Armin Joachimsmeyer 5 | * armin.joachimsmeyer@gmail.com 6 | * 7 | * This file is part of BlueDisplay https://github.com/ArminJo/android-blue-display. 8 | * 9 | * BlueDisplay is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 17 | * See the GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef _HX8347D_H 25 | #define _HX8347D_H 26 | 27 | // Landscape format 28 | #define LOCAL_DISPLAY_HEIGHT 240 29 | #define LOCAL_DISPLAY_WIDTH 320 30 | // Portrait format 31 | //#define LOCAL_DISPLAY_HEIGHT 320 32 | //#define LOCAL_DISPLAY_WIDTH 240 33 | 34 | extern uint8_t sCurrentBacklightPercent; 35 | extern uint8_t sLastBacklightPercent; //! for state of backlight before dimming 36 | extern int sLCDDimDelay; //actual dim delay 37 | 38 | #define BACKLIGHT_START_BRIGHTNESS_VALUE 50 39 | #define BACKLIGHT_MAX_BRIGHTNESS_VALUE 100 40 | #define BACKLIGHT_DIM_VALUE 7 41 | #define BACKLIGHT_DIM_DEFAULT_DELAY_MILLIS 120000 // Two minutes 42 | 43 | class HX8347D { // @suppress("Class has a virtual method and non-virtual destructor") 44 | public: 45 | 46 | HX8347D(); 47 | void init(uint8_t aSPIClockDivider); //2 4 8 16 32 48 | void setBacklightBrightness(uint8_t aBrightnessPercent); //0-100 49 | 50 | void setOrientation(uint16_t o); //0 90 180 270 51 | uint16_t getRequestedDisplayWidth(); 52 | uint16_t getRequestedDisplayHeight(); 53 | void setCursor(uint16_t x, uint16_t y); 54 | 55 | /* 56 | * Basic hardware functions required for the text draw functions in LocalDisplayInterface 57 | */ 58 | void fillRect(uint16_t aStartX, uint16_t aStartY, uint16_t aEndX, uint16_t aEndY, color16_t aColor); 59 | void setArea(uint16_t aStartX, uint16_t aStartY, uint16_t aEndX, uint16_t aEndY); 60 | void drawStart(); 61 | void draw(color16_t aColor); 62 | void drawStop(); 63 | 64 | void clearDisplay(uint16_t aColor); 65 | void drawPixel(uint16_t x0, uint16_t y0, uint16_t color); 66 | void drawPixelFast(uint16_t x0, uint8_t y0, uint16_t color); 67 | void drawLine(uint16_t aStartX, uint16_t aStartY, uint16_t aEndX, uint16_t aEndY, color16_t aColor); 68 | void drawLineRel(uint16_t aStartX, uint16_t aStartY, int16_t aDeltaX, int16_t aDeltaY, color16_t aColor); 69 | void drawLineFastOneX(uint16_t aStartX, uint16_t aStartY, uint16_t aEndY, color16_t aColor); 70 | void drawRect(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color); 71 | void fillRectRel(uint16_t aStartX, uint16_t aStartY, uint16_t aWidth, uint16_t aHeight, uint16_t aColor); 72 | 73 | void drawCircle(uint16_t aCenterX, uint16_t aCenterY, uint16_t aRadius, uint16_t aColor); 74 | void fillCircle(uint16_t aCenterX, uint16_t aCenterY, uint16_t aRadius, uint16_t aColor); 75 | 76 | void printOptions(uint8_t size, uint16_t color, uint16_t bg_color); 77 | void printClear(void); 78 | void printXY(uint16_t x, uint16_t y); 79 | uint16_t printGetX(void); 80 | uint16_t printGetY(void); 81 | // void printPGM(PGM_P s); 82 | // virtual size_t write(uint8_t c); 83 | // virtual size_t write(const char *s); 84 | // virtual size_t write(const uint8_t *s, size_t size); 85 | 86 | static void reset(void); 87 | 88 | private: 89 | // for (untested) print functions 90 | uint8_t p_size; 91 | uint16_t p_fg, p_bg; 92 | uint16_t p_x, p_y; 93 | 94 | static void wr_cmd(uint8_t reg, uint8_t param); 95 | static void wr_data(uint16_t data); 96 | static void wr_spi(uint8_t data); 97 | }; 98 | 99 | #endif //_HX8347D_H 100 | -------------------------------------------------------------------------------- /src/LocalDisplay/LocalDisplayInterface.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LocalDisplayInterface.h 3 | * 4 | * 5 | * Copyright (C) 2023 Armin Joachimsmeyer 6 | * armin.joachimsmeyer@gmail.com 7 | * 8 | * This file is part of BlueDisplay https://github.com/ArminJo/android-blue-display. 9 | * 10 | * BlueDisplay is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | * See the GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | */ 24 | 25 | /* 26 | * Basic hardware functions required from the device driver for the draw functions 27 | * 28 | * void fillRect(uint16_t aStartX, uint16_t aStartY, uint16_t aEndX, uint16_t aEndY, color16_t aColor); 29 | * void fillRectRel(uint16_t aStartX, uint16_t aStartY, uint16_t aWidth, uint16_t aHeight, uint16_t aColor); 30 | * void setArea(uint16_t aStartX, uint16_t aStartY, uint16_t aEndX, uint16_t aEndY); 31 | * void drawStart(); 32 | * void draw(color16_t aColor); 33 | * void drawStop(); 34 | */ 35 | 36 | #ifndef _LOCAL_DISPLAY_INTERFACE_H 37 | #define _LOCAL_DISPLAY_INTERFACE_H 38 | 39 | #include "BlueDisplay.h" // for __FlashStringHelper, SUPPORT_REMOTE_AND_LOCAL_DISPLAY etc. 40 | 41 | #include "Colors.h" // for color16_t 42 | #include "GUIHelper.h" 43 | 44 | #include 45 | #include 46 | 47 | /** @addtogroup Gui_Library 48 | * @{ 49 | */ 50 | /** @addtogroup Display 51 | * @{ 52 | */ 53 | 54 | #if defined(USE_HX8347D) 55 | #include "HX8347D.h" // for LOCAL_DISPLAY_HEIGHT and LOCAL_DISPLAY_WIDTH 56 | class LocalDisplayInterface: public HX8347D // @suppress("Class has a virtual method and non-virtual destructor") 57 | #elif defined(USE_SSD1289) 58 | #include "SSD1289.h" // for LOCAL_DISPLAY_HEIGHT and LOCAL_DISPLAY_WIDTH 59 | class LocalDisplayInterface: public SSD1289 // @suppress("Class has a virtual method and non-virtual destructor") 60 | #else 61 | #error One of USE_HX8347D or USE_SSD1289 must be defined. Use e.g. #include "LocalHX8347DDisplay.hpp" 62 | #endif 63 | { 64 | public: 65 | 66 | /* 67 | * Using this class as an interface with virtual functions costs around 1 k of program space. 68 | * It is the overhead for accessing the virtual functions. 69 | * The compiler option -fdevirtualize -fdevirtualize-speculatively has no effect for the Arduino Compiler version used. 70 | */ 71 | LocalDisplayInterface(); 72 | #if !defined(ARDUINO) 73 | virtual ~LocalDisplayInterface(); // Destructor requires up to 600 additional bytes of program memory 74 | #endif 75 | 76 | uint16_t drawChar(uint16_t aPositionX, uint16_t aPositionY, char aChar, uint8_t aFontScaleFactor, color16_t aCharacterColor, 77 | color16_t aBackgroundColor); 78 | uint16_t drawText(uint16_t aPositionX, uint16_t aPositionY, const char *aText, uint8_t aFontSize, color16_t aTextColor, 79 | color16_t aBackgroundColor, uint16_t aNumberOfCharacters = 0xFFFF); 80 | uint16_t drawText(uint16_t aPositionX, uint16_t aPositionY, const __FlashStringHelper *aPGMString, uint16_t aFontSize, 81 | color16_t aTextColor, color16_t aBackgroundColor, uint16_t aNumberOfCharacters = 0xFFFF); 82 | uint16_t drawMLText(uint16_t aPositionX, uint16_t aPositionY, const char *aMultiLineText, uint8_t aFontSize, uint16_t aTextColor, 83 | uint16_t aBackgroundColor, bool isPGMText = false); 84 | uint16_t drawMLText(uint16_t aPositionX, uint16_t aPositionY, const __FlashStringHelper *aPGMMultiLineText, uint8_t aFontSize, 85 | uint16_t aTextColor, uint16_t aBackgroundColor); 86 | 87 | }; 88 | 89 | extern LocalDisplayInterface LocalDisplay; // The instance provided by the class itself 90 | 91 | /** @} */ 92 | /** @} */ 93 | 94 | #endif // _LOCAL_DISPLAY_INTERFACE_H 95 | -------------------------------------------------------------------------------- /src/LocalDisplay/LocalEventHelper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LocalEventHelper.h 3 | * 4 | * Support for event generation / handling of local touch events 5 | * 6 | * Copyright (C) 2023 Armin Joachimsmeyer 7 | * armin.joachimsmeyer@gmail.com 8 | * 9 | * This file is part of BlueDisplay https://github.com/ArminJo/android-blue-display. 10 | * 11 | * BlueDisplay is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 3 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 19 | * See the GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | * 24 | */ 25 | 26 | #ifndef _LOCAL_EVENT_HELPER_H 27 | #define _LOCAL_EVENT_HELPER_H 28 | 29 | #include 30 | 31 | /* 32 | * Local touch generates a local touch down or touch up event for BlueDisplay event handler, if not on button or slider. 33 | * I.e. localTouchEvent is then filled with data. 34 | */ 35 | //#define LOCAL_DISPLAY_GENERATES_BD_EVENTS 36 | /* 37 | * For basic touch detection 38 | */ 39 | #define NO_TOUCH 0 40 | #define BUTTON_TOUCHED 1 41 | #define SLIDER_TOUCHED 2 42 | #define PANEL_TOUCHED 3 // We have a touch down, but not on a touch object 43 | extern uint8_t sTouchObjectTouched; // On touch down, this changes from NO_TOUCH to one of BUTTON_TOUCHED, SLIDER_TOUCHED, PANEL_TOUCHED 44 | 45 | /* 46 | * Local long touch down detection 47 | */ 48 | #if defined(SUPPORT_LOCAL_LONG_TOUCH_DOWN_DETECTION) && !defined(USE_TIMER_FOR_PERIODIC_LOCAL_TOUCH_CHECKS) 49 | extern uint32_t sLastTouchDownMillis; // time of last touch down for detecting long touch down 50 | #endif 51 | 52 | // Local swipe detection 53 | #define TOUCH_SWIPE_THRESHOLD 10 // threshold for swipe detection to suppress long touch handler calling 54 | #define TOUCH_SWIPE_RESOLUTION_MILLIS 20 55 | void handleLocalTouchUp(void); 56 | 57 | /* 58 | * The event handler void handleTouchPanelEvents() can be called by main loop 59 | * or called by an ADS7846 interrupt and a periodic timer for detecting moves, long touch down and swipes. 60 | */ 61 | void checkAndHandleTouchPanelEvents(); 62 | void handleTouchPanelEvents(); 63 | 64 | #if defined(USE_TIMER_FOR_PERIODIC_LOCAL_TOUCH_CHECKS) 65 | 66 | // for local autorepeat button or color picker 67 | void registerPeriodicTouchCallback(bool (*aPeriodicTouchCallback)(int, int), uint32_t aCallbackPeriodMillis); 68 | void setPeriodicTouchCallbackPeriod(uint32_t aCallbackPeriod); 69 | 70 | void (*sPeriodicTouchCallback)(int, int) = nullptr; // return parameter not yet used 71 | void callbackHandlerForLongTouchDownTimeout(void); 72 | 73 | uint32_t sPeriodicCallbackPeriodMillis; 74 | #endif 75 | 76 | #endif //_LOCAL_EVENT_HELPER_H 77 | -------------------------------------------------------------------------------- /src/LocalDisplay/SSD1289.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SSD1289.h 3 | * 4 | * @date 14.02.2012 5 | * @author Armin Joachimsmeyer 6 | * armin.joachimsmeyer@gmail.com 7 | * @copyright LGPL v3 (http://www.gnu.org/licenses/lgpl.html) 8 | * @version 1.5.0 9 | * 10 | */ 11 | 12 | #ifndef SSD1289_h 13 | #define SSD1289_h 14 | 15 | /** @addtogroup Graphic_Library 16 | * @{ 17 | */ 18 | /** @addtogroup HY32D_basic 19 | * @{ 20 | */ 21 | 22 | // Landscape format 23 | #define LOCAL_DISPLAY_HEIGHT 240 24 | #define LOCAL_DISPLAY_WIDTH 320 25 | // Portrait format 26 | //#define LOCAL_DISPLAY_HEIGHT 320 27 | //#define LOCAL_DISPLAY_WIDTH 240 28 | 29 | extern uint8_t sCurrentBacklightPercent; 30 | extern uint8_t sLastBacklightPercentBeforeDimming; //! for state of backlight before dimming 31 | extern int sLCDDimDelay; //actual dim delay 32 | 33 | /* 34 | * Backlight values in percent 35 | */ 36 | #define BACKLIGHT_START_BRIGHTNESS_VALUE 50 37 | #define BACKLIGHT_MAX_BRIGHTNESS_VALUE 100 38 | #define BACKLIGHT_DIM_VALUE 7 39 | #define BACKLIGHT_DIM_DEFAULT_DELAY_MILLIS 120000 // Two minutes 40 | 41 | #ifdef __cplusplus 42 | class SSD1289 { // @suppress("Class has a virtual method and non-virtual destructor") 43 | 44 | public: 45 | SSD1289(); 46 | ~SSD1289(); 47 | void init(void); 48 | void setBacklightBrightness(uint8_t aBrightnessPercent); // 0-100 49 | 50 | void clearDisplay(uint16_t color); 51 | void drawPixel(uint16_t aXPos, uint16_t aYPos, color16_t aColor); 52 | void drawCircle(uint16_t aXCenter, uint16_t aYCenter, uint16_t aRadius, color16_t aColor); 53 | void fillCircle(uint16_t aXCenter, uint16_t aYCenter, uint16_t aRadius, color16_t aColor); 54 | void fillRectRel(uint16_t aXStart, uint16_t aYStart, uint16_t aWidth, uint16_t aHeight, color16_t aColor); 55 | void drawTextVertical(uint16_t aXPos, uint16_t aYPos, const char *aStringPointer, uint8_t aSize, color16_t aColor, 56 | uint16_t aBackgroundColor); 57 | void drawLine(uint16_t aXStart, uint16_t aYStart, uint16_t aXEnd, uint16_t aYEnd, color16_t aColor); 58 | void drawLineRel(uint16_t aStartX, uint16_t aStartY, int16_t aDeltaX, int16_t aDeltaY, color16_t aColor); 59 | void drawLineFastOneX(uint16_t x0, uint16_t y0, uint16_t y1, color16_t color); 60 | void drawRect(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, color16_t color); 61 | 62 | /* 63 | * Basic hardware functions required for the draw functions below 64 | */ 65 | void fillRect(uint16_t aStartX, uint16_t aStartY, uint16_t aEndX, uint16_t aEndY, color16_t aColor); 66 | void setArea(uint16_t aStartX, uint16_t aStartY, uint16_t aEndX, uint16_t aEndY); 67 | void drawStart(); 68 | void draw(color16_t aColor); 69 | void drawStop(); 70 | 71 | void setCursor(uint16_t aXStart, uint16_t aYStart); 72 | uint16_t getRequestedDisplayWidth(); 73 | uint16_t getRequestedDisplayHeight(); 74 | 75 | uint16_t readPixel(uint16_t aXPos, uint16_t aYPos); 76 | uint16_t* fillDisplayLineBuffer(uint16_t *aBufferPtr, uint16_t yLineNumber); 77 | 78 | private: 79 | 80 | }; 81 | 82 | #endif // __cplusplus 83 | 84 | extern bool isInitializedSSD1289; 85 | extern volatile uint32_t sDrawLock; 86 | 87 | void setDimdelay(int32_t aTimeMillis); 88 | void resetBacklightTimeout(void); 89 | void callbackLCDDimming(void); 90 | int clipBrightnessValue(int aBrightnessValue); 91 | 92 | uint16_t getRequestedDisplayWidth(void); 93 | uint16_t getRequestedDisplayHeight(void); 94 | 95 | int drawNText(uint16_t x, uint16_t y, const char *s, int aNumberOfCharacters, uint8_t size, uint16_t color, uint16_t bg_color); 96 | 97 | uint16_t drawInteger(uint16_t x, uint16_t y, int val, uint8_t base, uint8_t size, uint16_t color, uint16_t bg_color); 98 | 99 | extern "C" void storeScreenshot(void); 100 | /* 101 | * fast divide by 11 for SSD1289 driver arguments 102 | */ 103 | uint16_t getFontScaleFactorFromTextSize(uint16_t aTextSize); 104 | 105 | // Tests 106 | void initalizeDisplay2(void); 107 | void setGamma(int aIndex); 108 | void writeCommand(int aRegisterAddress, int aRegisterValue); 109 | 110 | /** @} */ 111 | /** @} */ 112 | 113 | #endif //SSD1289_h 114 | -------------------------------------------------------------------------------- /src/LocalDisplay/STM32TouchScreenDriver.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * STM32TouchScreenDriver.cpp 3 | * 4 | * Firmware for the TI ADS7846 resistive touch controller 5 | * 6 | * 7 | * Copyright (C) 2015-2023 Armin Joachimsmeyer 8 | * armin.joachimsmeyer@gmail.com 9 | * 10 | * This file is part of BlueDisplay https://github.com/ArminJo/android-blue-display. 11 | * 12 | * BlueDisplay is free software: you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation, either version 3 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * This program is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 20 | * See the GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | */ 25 | #if defined(STM32F10X) || defined(STM32F30X) 26 | #include "STM32TouchScreenDriver.h" 27 | 28 | #ifdef STM32F10X 29 | #include 30 | #endif 31 | #ifdef STM32F30X 32 | #include 33 | #endif 34 | 35 | TIM_HandleTypeDef TIM4Handle; 36 | 37 | /** 38 | * Init the HY32D CS, Control/Data, WR, RD, and port D data pins 39 | */ 40 | void SSD1289_IO_initalize(void) { 41 | GPIO_InitTypeDef GPIO_InitStructure; 42 | 43 | /* Enable the GPIO Clocks */ 44 | __GPIOB_CLK_ENABLE(); 45 | __GPIOD_CLK_ENABLE(); 46 | 47 | // CS pin, Register/Data select pin, WR pin, RD pin 48 | GPIO_InitStructure.Pin = HY32D_CS_PIN | HY32D_DATA_CONTROL_PIN | HY32D_WR_PIN | HY32D_RD_PIN; 49 | GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; 50 | GPIO_InitStructure.Pull = GPIO_NOPULL; 51 | GPIO_InitStructure.Speed = GPIO_SPEED_HIGH; 52 | HAL_GPIO_Init(HY32D_CS_GPIO_PORT, &GPIO_InitStructure); 53 | // set HIGH 54 | HAL_GPIO_WritePin(HY32D_CS_GPIO_PORT, HY32D_CS_PIN | HY32D_WR_PIN | HY32D_RD_PIN, GPIO_PIN_SET); 55 | 56 | // 16 data pins 57 | GPIO_InitStructure.Pin = GPIO_PIN_All; 58 | HAL_GPIO_Init(HY32D_DATA_GPIO_PORT, &GPIO_InitStructure); 59 | } 60 | 61 | /** 62 | * Pins for touch panel CS, PENINT 63 | */ 64 | // Interrupt in pin 65 | #define ADS7846_EXTI_IRQn EXTI1_IRQn 66 | 67 | void ADS7846_IO_initalize(void) { 68 | GPIO_InitTypeDef GPIO_InitStructure; 69 | 70 | /* Enable the GPIO Clock */ 71 | __GPIOB_CLK_ENABLE(); 72 | 73 | // CS pin 74 | GPIO_InitStructure.Pin = ADS7846_CS_PIN; 75 | GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP; 76 | GPIO_InitStructure.Pull = GPIO_NOPULL; 77 | GPIO_InitStructure.Speed = GPIO_SPEED_HIGH; 78 | HAL_GPIO_Init(ADS7846_CS_GPIO_PORT, &GPIO_InitStructure); 79 | // set HIGH 80 | HAL_GPIO_WritePin(ADS7846_CS_GPIO_PORT, ADS7846_CS_PIN, GPIO_PIN_SET); 81 | 82 | /* Configure pin as external interrupt */ 83 | GPIO_InitStructure.Pin = ADS7846_EXTI_PIN; 84 | GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING_FALLING; 85 | GPIO_InitStructure.Pull = GPIO_NOPULL; 86 | GPIO_InitStructure.Speed = GPIO_SPEED_HIGH; 87 | HAL_GPIO_Init(ADS7846_EXTI_GPIO_PORT, &GPIO_InitStructure); 88 | 89 | /* Enable and set Button EXTI Interrupt to low priority */ 90 | NVIC_SetPriority((IRQn_Type) (ADS7846_EXTI_IRQn), 12); 91 | HAL_NVIC_EnableIRQ((IRQn_Type) (ADS7846_EXTI_IRQn)); 92 | } 93 | 94 | /** 95 | * first clear pending interrupts 96 | */ 97 | void ADS7846_clearAndEnableInterrupt(void) { 98 | // // Enable interrupt 99 | // uint32_t tmp = (uint32_t) EXTI_BASE + EXTI_Mode_Interrupt 100 | // + (((STM32F3D_ADS7846_EXTI_LINE) >> 5) * 0x20); 101 | // /* Enable the selected external lines */ 102 | // *(__IO uint32_t *) tmp |= (uint32_t) (1 << (STM32F3D_ADS7846_EXTI_LINE & 0x1F)); 103 | 104 | __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_1); 105 | NVIC_ClearPendingIRQ(ADS7846_EXTI_IRQn); 106 | NVIC_EnableIRQ(ADS7846_EXTI_IRQn); 107 | } 108 | 109 | void ADS7846_disableInterrupt(void) { 110 | // // Disable interrupt 111 | // uint32_t tmp = (uint32_t) EXTI_BASE + EXTI_Mode_Interrupt 112 | // + (((STM32F3D_ADS7846_EXTI_LINE) >> 5) * 0x20); 113 | // /* Disable the selected external lines */ 114 | // *(__IO uint32_t *) tmp &= ~(uint32_t) (1 << (STM32F3D_ADS7846_EXTI_LINE & 0x1F)); 115 | // 116 | 117 | __HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_1); 118 | // Disable NVIC Int 119 | NVIC_DisableIRQ(ADS7846_EXTI_IRQn); 120 | NVIC_ClearPendingIRQ(ADS7846_EXTI_IRQn); 121 | } 122 | 123 | /** 124 | * PWM for display backlight with timer 4 125 | */ 126 | #define STM32F3D_PWM_BL_TIMER TIM4 127 | #define STM32F3D_PWM_BL_TIMER_CLOCK RCC_APB1Periph_TIM4 128 | 129 | // for pin F6 130 | #define STM32F3D_PWM_BL_GPIO_PIN GPIO_PIN_6 131 | #define STM32F3D_PWM_BL_GPIO_PORT GPIOF 132 | #define STM32F3D_PWM_BL_GPIO_CLK RCC_AHBPeriph_GPIOF 133 | #define STM32F3D_PWM_BL_SOURCE GPIO_PinSource6 134 | #define STM32F3D_PWM_BL_AF GPIO_AF_2 135 | #define STM32F3D_PWM_BL_CHANNEL TIM_Channel_4 136 | #define STM32F3D_PWM_BL_CHANNEL_INIT_COMMAND TIM_OC4Init 137 | #define STM32F3D_PWM_BL_CHANNEL_PRELOAD_COMMAND TIM_OC4PreloadConfig 138 | 139 | #define PWM_RESOLUTION_BACKLIGHT 0x100 // 0-255, 256 = constant-high 140 | void PWM_BL_initalize(void) { 141 | TIM4Handle.Instance = TIM4; 142 | 143 | /* TIM4 clock enable */ 144 | __TIM4_CLK_ENABLE(); 145 | 146 | /* Compute the prescaler value for 1 kHz period with 256 resolution*/ 147 | uint16_t PrescalerValue = (uint16_t) ((SystemCoreClock / 2) / (1000 * PWM_RESOLUTION_BACKLIGHT)) - 1; 148 | 149 | /* Time base configuration */ 150 | TIM4Handle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; 151 | TIM4Handle.Init.Period = PWM_RESOLUTION_BACKLIGHT - 1; 152 | TIM4Handle.Init.Prescaler = PrescalerValue; 153 | TIM4Handle.Init.CounterMode = TIM_COUNTERMODE_UP; 154 | HAL_TIM_Base_Init(&TIM4Handle); 155 | 156 | // Channel 4 for Pin F6 157 | TIM_OC_InitTypeDef TIM_OCInitStructure; 158 | /* PWM1 Mode configuration */ 159 | TIM_OCInitStructure.OCMode = TIM_OCMODE_PWM1; 160 | TIM_OCInitStructure.OCFastMode = TIM_OCFAST_DISABLE; 161 | TIM_OCInitStructure.Pulse = PWM_RESOLUTION_BACKLIGHT / 2; //TIM_OPMODE_REPETITIVE 162 | TIM_OCInitStructure.OCPolarity = TIM_OCPOLARITY_HIGH; 163 | TIM_OCInitStructure.OCIdleState = TIM_OCIDLESTATE_RESET; 164 | TIM_OCInitStructure.OCNPolarity = TIM_OCNPOLARITY_HIGH; 165 | TIM_OCInitStructure.OCNIdleState = TIM_OCNIDLESTATE_RESET; 166 | HAL_TIM_PWM_ConfigChannel(&TIM4Handle, &TIM_OCInitStructure, TIM_CHANNEL_4); 167 | 168 | GPIO_InitTypeDef GPIO_InitStructure; 169 | __GPIOF_CLK_ENABLE(); 170 | 171 | // Configure pin as alternate function for timer 172 | GPIO_InitStructure.Mode = GPIO_MODE_AF_PP; 173 | GPIO_InitStructure.Pull = GPIO_NOPULL; 174 | GPIO_InitStructure.Speed = GPIO_SPEED_HIGH; 175 | GPIO_InitStructure.Pin = STM32F3D_PWM_BL_GPIO_PIN; 176 | GPIO_InitStructure.Alternate = GPIO_AF2_TIM4; 177 | HAL_GPIO_Init(STM32F3D_PWM_BL_GPIO_PORT, &GPIO_InitStructure); 178 | 179 | // STM32F3D_PWM_BL_CHANNEL_PRELOAD_COMMAND(STM32F3D_PWM_BL_TIMER, TIM_OCPreload_Enable); 180 | // TIM_ARRPreloadConfig(STM32F3D_PWM_BL_TIMER, ENABLE); 181 | /* TIM4 enable counter */ 182 | // TIM_Cmd(STM32F3D_PWM_BL_TIMER, ENABLE); 183 | __HAL_TIM_ENABLE(&TIM4Handle); 184 | 185 | // Start channel 4 186 | HAL_TIM_PWM_Start(&TIM4Handle, TIM_CHANNEL_4); 187 | } 188 | 189 | void PWM_BL_setOnRatio(uint32_t aOnTimePercent) { 190 | if (aOnTimePercent >= 100) { 191 | aOnTimePercent = 100; 192 | } 193 | TIM4Handle.Instance->CCR4 = (uint32_t) aOnTimePercent * 256 / 100; 194 | // TIM_SetCompare4(STM32F3D_PWM_BL_TIMER, (uint32_t) aOnTimePercent * 256 / 100); 195 | } 196 | #endif 197 | -------------------------------------------------------------------------------- /src/LocalDisplay/STM32TouchScreenDriver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * STM32TouchScreenDriver.h 3 | * 4 | * Copyright (C) 2015-2023 Armin Joachimsmeyer 5 | * armin.joachimsmeyer@gmail.com 6 | * 7 | * This file is part of BlueDisplay https://github.com/ArminJo/android-blue-display. 8 | * 9 | * BlueDisplay is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 17 | * See the GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | * Port pin assignment 23 | * ------------------- 24 | * 25 | * Port |Pin|Device |Function 26 | * -----|---|-------|-------- 27 | * B |0 |HY32D |CS 28 | * B |1 |ADS7846 |INT input 29 | * B |2 |ADS7846 |CS 30 | * B |4 |HY32D |DATA 31 | * B |5 |HY32D |WR 32 | * B |10 |HY32D |RD 33 | * F |6 |HY32D |TIM4 PWM output 34 | * 35 | * 36 | * 37 | * Timer usage 38 | * ------------------- 39 | * 40 | * Timer |Function 41 | * ---------|-------- 42 | * 4 | PWM backlight led -> Pin F6 43 | 44 | * 45 | * Interrupt priority (lower value is higher priority) 46 | * --------------------- 47 | * 2 bits for pre-emption priority + 2 bits for subpriority 48 | * 49 | * Prio | ISR Nr| Name | Usage 50 | * -----|-------------------------------|------------- 51 | * 3 0 | 0x17 | EXTI1_IRQn | Touch 52 | * 53 | */ 54 | #ifndef _STM32TOUCHSCREENDRIVER_H 55 | #define _STM32TOUCHSCREENDRIVER_H 56 | 57 | #if defined(STM32F10X) || defined(STM32F30X) 58 | 59 | #include 60 | 61 | #define HY32D_CS_PIN GPIO_PIN_0 62 | #define HY32D_CS_GPIO_PORT GPIOB 63 | 64 | #define HY32D_DATA_CONTROL_PIN GPIO_PIN_4 65 | #define HY32D_DATA_CONTROL_GPIO_PORT GPIOB // dedicated Ports are needed by HY32D.cpp for single line setting 66 | #define HY32D_RD_PIN GPIO_PIN_10 67 | #define HY32D_RD_GPIO_PORT GPIOB 68 | 69 | #define HY32D_WR_PIN GPIO_PIN_5 70 | #define HY32D_WR_GPIO_PORT GPIOB 71 | 72 | #define HY32D_DATA_GPIO_PORT GPIOD 73 | 74 | #define ADS7846_CS_PIN GPIO_PIN_2 75 | #define ADS7846_CS_GPIO_PORT GPIOB 76 | 77 | #define ADS7846_EXTI_PIN GPIO_PIN_1 78 | #define ADS7846_EXTI_GPIO_PORT GPIOB 79 | 80 | typedef enum { 81 | LOW = 0, HIGH 82 | } IOLevel; 83 | 84 | void SSD1289_IO_initalize(void); 85 | 86 | void ADS7846_IO_initalize(void); 87 | void ADS7846_clearAndEnableInterrupt(void); 88 | void ADS7846_disableInterrupt(void); 89 | #define ADS7846_CSEnable() (ADS7846_CS_GPIO_PORT->BSRR = (uint32_t) ADS7846_CS_PIN << 16) 90 | #define ADS7846_CSDisable() (ADS7846_CS_GPIO_PORT->BSRR = ADS7846_CS_PIN) 91 | /** 92 | * @return true if line is NOT active 93 | */ 94 | #define ADS7846_getInteruptLineLevel() (HAL_GPIO_ReadPin(ADS7846_EXTI_GPIO_PORT, ADS7846_EXTI_PIN)) 95 | #define ADS7846_ClearITPendingBit() (__HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_1)) 96 | 97 | /* 98 | * PWM 99 | */ 100 | void PWM_BL_initalize(void); 101 | void PWM_BL_setOnRatio(uint32_t power); 102 | 103 | #endif 104 | 105 | #endif // _STM32TOUCHSCREENDRIVER_H 106 | -------------------------------------------------------------------------------- /src/LocalDisplay/fonts.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _FONTS_HPP 2 | #define _FONTS_HPP 3 | 4 | // All font data from Benedikt K. 5 | // http://www.mikrocontroller.net/topic/54860 6 | 7 | //Font selection (select only one font) 8 | //#define FONT_4X6 9 | //#define FONT_5X8 10 | //#define FONT_5X12 11 | //#define FONT_6X8 12 | //#define FONT_6X10 13 | //#define FONT_7X12 14 | //#define FONT_8X8 15 | //#define FONT_8X12 16 | //#define FONT_8X14 17 | //#define FONT_10X16 18 | //#define FONT_12X16 19 | //#define FONT_12X20 20 | //#define FONT_16X26 21 | 22 | //if defined char range 0x20-0x7F otherwise 0x20-0xFF 23 | //#define FONT_END7F 24 | 25 | #define FONT_START (0x20) //first character 26 | 27 | #if defined(FONT_4X6) 28 | #include "font_4x6.hpp" 29 | # define FONT_WIDTH (4) 30 | # define FONT_HEIGHT (6) 31 | #elif defined(FONT_5X8) 32 | #include "font_5x8.hpp" 33 | # define FONT_WIDTH (5) 34 | # define FONT_HEIGHT (8) 35 | #elif defined(FONT_5X12) 36 | #include "font_5x12.hpp" 37 | # define FONT_WIDTH (5) 38 | # define FONT_HEIGHT (12) 39 | #elif defined(FONT_6X8) 40 | #include "font_6x8.hpp" 41 | # define FONT_WIDTH (6) 42 | # define FONT_HEIGHT (8) 43 | #elif defined(FONT_6X10) 44 | #include "font_6x10.hpp" 45 | # define FONT_WIDTH (6) 46 | # define FONT_HEIGHT (10) 47 | #elif defined(FONT_7X12) 48 | #include "font_7x12.hpp" 49 | # define FONT_WIDTH (7) 50 | # define FONT_HEIGHT (12) 51 | #elif defined(FONT_8X8) 52 | #include "font_8x8.hpp" 53 | # define FONT_WIDTH (8) 54 | # define FONT_HEIGHT (8) 55 | #elif defined(FONT_8X12) 56 | #include "font_8x12.hpp" 57 | # define FONT_WIDTH (8) 58 | # define FONT_HEIGHT (12) 59 | #elif defined(FONT_8X14) 60 | #include "font_8x14.hpp" 61 | # define FONT_WIDTH (8) 62 | # define FONT_HEIGHT (14) 63 | #elif defined(FONT_10X16) 64 | #include "font_10x16.hpp" 65 | # define FONT_WIDTH (10) 66 | # define FONT_HEIGHT (16) 67 | #elif defined(FONT_12X16) 68 | #include "font_12x16.hpp" 69 | # define FONT_WIDTH (12) 70 | # define FONT_HEIGHT (16) 71 | #elif defined(FONT_12X20) 72 | #include "font_12x20.hpp" 73 | # define FONT_WIDTH (12) 74 | # define FONT_HEIGHT (20) 75 | #elif defined(FONT_16X26) 76 | #include "font_16x26.hpp" 77 | # define FONT_WIDTH (16) 78 | # define FONT_HEIGHT (26) 79 | #else 80 | # warning No font defined 81 | #endif 82 | 83 | #endif // _FONTS_HPP 84 | -------------------------------------------------------------------------------- /src/LocalDisplay/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For MI0283QT2 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | ADS7846 KEYWORD1 10 | MI0283QT2 KEYWORD1 11 | SSD1289 KEYWORD1 12 | 13 | ####################################### 14 | # Methods and Functions (KEYWORD2) 15 | ####################################### 16 | 17 | # from ADS7846 18 | init KEYWORD2 19 | setOrientation KEYWORD2 20 | setCalibration KEYWORD2 21 | writeCalibration KEYWORD2 22 | readCalibration KEYWORD2 23 | calibrate KEYWORD2 24 | getX KEYWORD2 25 | getY KEYWORD2 26 | getXraw KEYWORD2 27 | getYraw KEYWORD2 28 | getPressure KEYWORD2 29 | service KEYWORD2 30 | readChannel KEYWORD2 31 | 32 | # from MI0283QT2, SSD1289 33 | init KEYWORD2 34 | setBacklightBrightness KEYWORD2 35 | drawStart KEYWORD2 36 | draw KEYWORD2 37 | drawStop KEYWORD2 38 | setOrientation KEYWORD2 39 | getWidth KEYWORD2 40 | getHeight KEYWORD2 41 | setArea KEYWORD2 42 | setCursor KEYWORD2 43 | clear KEYWORD2 44 | drawPixel KEYWORD2 45 | drawPixelFast KEYWORD2 46 | drawLine KEYWORD2 47 | drawLineFastOneX KEYWORD2 48 | drawRect KEYWORD2 49 | fillRect KEYWORD2 50 | drawCircle KEYWORD2 51 | fillCircle KEYWORD2 52 | drawChar KEYWORD2 53 | drawInteger KEYWORD2 54 | drawText KEYWORD2 55 | drawTextPGM KEYWORD2 56 | drawMLText KEYWORD2 57 | drawMLTextPGM KEYWORD2 58 | printOptions KEYWORD2 59 | printClear KEYWORD2 60 | printXY KEYWORD2 61 | printPGM KEYWORD2 62 | print KEYWORD2 63 | 64 | ####################################### 65 | # Constants (LITERAL1) 66 | ####################################### 67 | -------------------------------------------------------------------------------- /src/LocalGUI.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * LocalGUI.hpp 3 | * 4 | * Helper for Arduino library detection phase to avoid to have an include of 5 | * type LocalGUI/LocalTouchButton.hpp in the sketch, which will not be found in this phase. 6 | * 7 | * 8 | * Copyright (C) 2023 Armin Joachimsmeyer 9 | * armin.joachimsmeyer@gmail.com 10 | * 11 | * This file is part of BlueDisplay https://github.com/ArminJo/android-blue-display. 12 | * 13 | * BlueDisplay is free software: you can redistribute it and/or modify 14 | * it under the terms of the GNU General Public License as published by 15 | * the Free Software Foundation, either version 3 of the License, or 16 | * (at your option) any later version. 17 | * 18 | * This program is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 21 | * See the GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with this program. If not, see . 25 | * 26 | */ 27 | #ifndef _LOCAL_GUI_HPP 28 | #define _LOCAL_GUI_HPP 29 | 30 | #if !defined(DISABLE_REMOTE_DISPLAY) 31 | #error Remote display is not disabled by #define DISABLE_REMOTE_DISPLAY and #include "LocalGUI.hpp" is used. This is most likely an error. You have to use #include "BlueDisplay.hpp" instead, it in turn includes the local GUI! 32 | #endif 33 | 34 | #include "GUIHelper.hpp" // Must be included before LocalGUI/*. For TEXT_SIZE_11, getLocalTextSize() etc. 35 | #include "LocalGUI/LocalTouchButton.hpp" 36 | #include "LocalGUI/LocalTouchSlider.hpp" 37 | #include "LocalGUI/LocalTouchButtonAutorepeat.hpp" 38 | #include "LocalGUI/LocalTinyPrint.hpp" 39 | #include "LocalGUI/ThickLine.hpp" 40 | 41 | #endif // _LOCAL_GUI_HPP 42 | -------------------------------------------------------------------------------- /src/LocalGUI/LocalTinyPrint.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LocalTinyPrint.h 3 | * 4 | * Copyright (C) 2014-2023 Armin Joachimsmeyer 5 | * armin.joachimsmeyer@gmail.com 6 | * 7 | * This file is part of BlueDisplay https://github.com/ArminJo/android-blue-display. 8 | * 9 | * BlueDisplay is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 17 | * See the GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | */ 23 | 24 | #ifndef _LOCAL_TINY_PRINT_H 25 | #define _LOCAL_TINY_PRINT_H 26 | 27 | #include 28 | #include 29 | 30 | void printSetOptions(uint8_t aPrintSize, uint16_t aPrintColor, uint16_t aPrintBackgroundColor, bool aClearOnNewScreen); 31 | int printNewline(void); 32 | void printClearScreen(void); 33 | void printSetPosition(int aPosX, int aPosY); 34 | void printSetPositionColumnLine(int aColumnNumber, int aLineNumber); 35 | int printNewline(void); 36 | //int myPrintf(const char *aFormat, ...); 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | void myPrint(const char *StringPointer, int aLength); 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif // _LOCAL_TINY_PRINT_H 47 | -------------------------------------------------------------------------------- /src/LocalGUI/LocalTinyPrint.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * LocalTinyPrint.hpp 3 | * Implementation of tinyPrint for local display 4 | * 5 | * Local display interface used: 6 | * LocalDisplay.clearDisplay() 7 | * LocalDisplay.drawChar() 8 | * LOCAL_DISPLAY_WIDTH 9 | * 10 | * Copyright (C) 2014-2023 Armin Joachimsmeyer 11 | * armin.joachimsmeyer@gmail.com 12 | * 13 | * This file is part of BlueDisplay https://github.com/ArminJo/android-blue-display. 14 | * 15 | * BlueDisplay is free software: you can redistribute it and/or modify 16 | * it under the terms of the GNU General Public License as published by 17 | * the Free Software Foundation, either version 3 of the License, or 18 | * (at your option) any later version. 19 | * 20 | * This program is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 23 | * See the GNU General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU General Public License 26 | * along with this program. If not, see . 27 | * 28 | */ 29 | 30 | #ifndef _LOCAL_TINY_PRINT_HPP 31 | #define _LOCAL_TINY_PRINT_HPP 32 | 33 | #include "LocalGUI/LocalTinyPrint.h" 34 | 35 | uint8_t sPrintSize = 1; 36 | uint16_t sPrintColor = COLOR16_WHITE; 37 | uint16_t sPrintBackgroundColor = COLOR16_BLACK; 38 | int sPrintX = 0; 39 | int sPrintY = 0; 40 | bool sClearOnNewScreen = true; 41 | 42 | void printSetOptions(uint8_t aPrintSize, uint16_t aPrintColor, uint16_t aPrintBackgroundColor, 43 | bool aClearOnNewScreen) { 44 | sPrintSize = aPrintSize; 45 | sPrintColor = aPrintColor; 46 | sPrintBackgroundColor = aPrintBackgroundColor; 47 | sClearOnNewScreen = aClearOnNewScreen; 48 | } 49 | 50 | void printClearScreen() { 51 | LocalDisplay.clearDisplay(sPrintBackgroundColor); 52 | sPrintX = 0; 53 | sPrintY = 0; 54 | } 55 | 56 | /** 57 | * 58 | * @param aPosX in pixel coordinates 59 | * @param aPosY in pixel coordinates 60 | */ 61 | void printSetPosition(int aPosX, int aPosY) { 62 | sPrintX = aPosX; 63 | sPrintY = aPosY; 64 | } 65 | 66 | void printSetPositionColumnLine(int aColumnNumber, int aLineNumber) { 67 | sPrintX = aColumnNumber * TEXT_SIZE_11_WIDTH; 68 | if (sPrintX >= (DISPLAY_DEFAULT_WIDTH - TEXT_SIZE_11_WIDTH)) { 69 | sPrintX = 0; 70 | } 71 | sPrintY = aLineNumber * TEXT_SIZE_11_HEIGHT; 72 | if (sPrintY >= (DISPLAY_DEFAULT_HEIGHT - TEXT_SIZE_11_HEIGHT)) { 73 | sPrintY = 0; 74 | } 75 | } 76 | 77 | int printNewline() { 78 | int tPrintY = sPrintY + TEXT_SIZE_11_HEIGHT; 79 | if (tPrintY >= DISPLAY_DEFAULT_HEIGHT) { 80 | // wrap around to top of screen 81 | tPrintY = 0; 82 | if (sClearOnNewScreen) { 83 | LocalDisplay.clearDisplay(sPrintBackgroundColor); 84 | } 85 | } 86 | sPrintX = 0; 87 | return tPrintY; 88 | } 89 | 90 | 91 | /** 92 | * draw aNumberOfCharacters from string and clip at display border 93 | * @return uint16_t start x for next character - next x Parameter 94 | */ 95 | int drawNText(uint16_t x, uint16_t y, const char *s, int aNumberOfCharacters, uint8_t aTextSize, uint16_t aTextColor, uint16_t bg_color) { 96 | while (*s != 0 && --aNumberOfCharacters > 0) { 97 | x = LocalDisplay.drawChar(x, y, (char) *s++, aTextSize, aTextColor, bg_color); 98 | if (x > LOCAL_DISPLAY_WIDTH) { 99 | break; 100 | } 101 | } 102 | return x; 103 | } 104 | 105 | // need external StringBuffer to save RAM space 106 | //extern char sStringBuffer[]; 107 | //int myPrintf(const char *aFormat, ...) { 108 | // va_list argp; 109 | // va_start(argp, aFormat); 110 | // int tLength = vsnprintf(sStringBuffer, sizeof sStringBuffer, aFormat, argp); 111 | // va_end(argp); 112 | // myPrint(sStringBuffer, tLength); 113 | // return tLength; 114 | //} 115 | 116 | /** 117 | * Prints string starting at actual display position and sets new position 118 | * Handles leading spaces, newlines and word wrap 119 | * @param StringPointer 120 | * @param aLength Maximal length of string to be printed 121 | */ 122 | extern "C" void myPrint(const char *StringPointer, int aLength) { 123 | char tChar; 124 | const char *tWordStart = StringPointer; 125 | const char *tPrintBufferStart = StringPointer; 126 | const char *tPrintBufferEnd = StringPointer + aLength; 127 | int tLineLengthInChars = DISPLAY_DEFAULT_WIDTH / (TEXT_SIZE_11_WIDTH * sPrintSize); 128 | bool doFlushAndNewline = false; 129 | int tColumn = sPrintX / TEXT_SIZE_11_WIDTH; 130 | while (true) { 131 | tChar = *StringPointer++; 132 | 133 | // check for terminate condition 134 | if (tChar == '\0' || StringPointer > tPrintBufferEnd) { 135 | // flush "buffer" 136 | sPrintX = drawNText(sPrintX, sPrintY, tPrintBufferStart, StringPointer - tPrintBufferStart, 0.6, sPrintColor, 137 | sPrintBackgroundColor); 138 | // handling of newline - after end of string 139 | if (sPrintX >= DISPLAY_DEFAULT_WIDTH) { 140 | sPrintY = printNewline(); 141 | } 142 | break; 143 | } 144 | if (tChar == '\n') { 145 | // new line -> start of a new word 146 | tWordStart = StringPointer; 147 | // signal flush and newline 148 | doFlushAndNewline = true; 149 | } else if (tChar == '\r') { 150 | // skip but start of a new word 151 | tWordStart = StringPointer; 152 | } else if (tChar == ' ') { 153 | // start of a new word 154 | tWordStart = StringPointer; 155 | if (tColumn == 0) { 156 | // skip from printing if first character in line 157 | tPrintBufferStart = StringPointer; 158 | } 159 | } else { 160 | if (tColumn >= (DISPLAY_DEFAULT_WIDTH / TEXT_SIZE_11_WIDTH)) { 161 | // character does not fit in line -> print it at next line 162 | doFlushAndNewline = true; 163 | int tWordlength = (StringPointer - tWordStart); 164 | if (tWordlength > tLineLengthInChars) { 165 | //word too long for a line just print char on next line 166 | // just draw "buffer" to old line, make newline and process character again 167 | StringPointer--; 168 | } else { 169 | // draw buffer till word start, make newline and process word again 170 | StringPointer = tWordStart; 171 | } 172 | } 173 | } 174 | if (doFlushAndNewline) { 175 | drawNText(sPrintX, sPrintY, tPrintBufferStart, StringPointer - tPrintBufferStart, sPrintSize, sPrintColor, 176 | sPrintBackgroundColor); 177 | tPrintBufferStart = StringPointer; 178 | sPrintY = printNewline(); 179 | sPrintX = 0; // set it explicitly since compiler may hold sPrintX in register 180 | tColumn = 0; 181 | doFlushAndNewline = false; 182 | } 183 | tColumn += sPrintSize; 184 | } 185 | } 186 | 187 | #endif // _LOCAL_TINY_PRINT_HPP 188 | -------------------------------------------------------------------------------- /src/LocalGUI/LocalTouchButtonAutorepeat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LocalTouchButtonAutorepeat.h 3 | * 4 | * Extension of ToucButton 5 | * implements autorepeat feature for touch buttons 6 | * 7 | * Copyright (C) 2012-2023 Armin Joachimsmeyer 8 | * armin.joachimsmeyer@gmail.com 9 | * 10 | * This file is part of BlueDisplay https://github.com/ArminJo/android-blue-display. 11 | * 12 | * BlueDisplay is free software: you can redistribute it and/or modify 13 | * it under the terms of the GNU General Public License as published by 14 | * the Free Software Foundation, either version 3 of the License, or 15 | * (at your option) any later version. 16 | * 17 | * This program is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 20 | * See the GNU General Public License for more details. 21 | * 22 | * You should have received a copy of the GNU General Public License 23 | * along with this program. If not, see . 24 | * 25 | */ 26 | 27 | #ifndef _TOUCHBUTTON_AUTOREPEAT_H 28 | #define _TOUCHBUTTON_AUTOREPEAT_H 29 | 30 | #include "LocalGUI/LocalTouchButton.h" 31 | 32 | /** @addtogroup Gui_Library 33 | * @{ 34 | */ 35 | /** @addtogroup Button 36 | * @{ 37 | */ 38 | 39 | class LocalTouchButtonAutorepeat: public LocalTouchButton { 40 | public: 41 | 42 | LocalTouchButtonAutorepeat(); 43 | 44 | #if !defined(ARDUINO) 45 | ~LocalTouchButtonAutorepeat(); 46 | #endif 47 | 48 | #if !defined(DISABLE_REMOTE_DISPLAY) 49 | LocalTouchButtonAutorepeat(BDButton *aBDButtonPtr); 50 | #endif 51 | 52 | /* 53 | * Static functions 54 | */ 55 | static int checkAllButtons(int aTouchPositionX, int aTouchPositionY, bool doCallback); 56 | static void autorepeatTouchHandler(LocalTouchButtonAutorepeat *aTheTouchedButton, int16_t aButtonValue); 57 | static void autorepeatButtonTimerHandler(int aTouchPositionX, int aTouchPositionY); 58 | void setButtonAutorepeatTiming(uint16_t aMillisFirstDelay, uint16_t aMillisFirstRate, uint16_t aFirstCount, 59 | uint16_t aMillisSecondRate); 60 | static void disableAutorepeatUntilEndOfTouch(); 61 | 62 | /* 63 | * The autorepeat characteristic of this button 64 | */ 65 | uint16_t mMillisFirstDelay; 66 | uint16_t mMillisFirstRate; 67 | uint16_t mFirstCount; 68 | uint16_t mMillisSecondRate; 69 | 70 | void (*mOriginalButtonOnTouchHandler)(LocalTouchButton*, int16_t); 71 | 72 | // Static values for currently touched/active button because only one touch to any autorepeat button possible 73 | static uint8_t sState; 74 | static uint16_t sCount; 75 | static unsigned long sCurrentCallbackDelayMillis; // The current period delay value. Can be mMillisFirstDelay, mMillisFirstRate or mMillisSecondRate 76 | static unsigned long sMillisOfLastCallOfCallback; // millis() value of last call to the buttons callback function 77 | 78 | }; 79 | /** @} */ 80 | /** @} */ 81 | #endif // _TOUCHBUTTON_AUTOREPEAT_H 82 | -------------------------------------------------------------------------------- /src/LocalGUI/LocalTouchButtonAutorepeat.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * LocalTouchButtonAutorepeat.hpp 3 | * 4 | * Extension of TouchButton 5 | * implements autorepeat feature for touch buttons 6 | * 7 | * 52 Byte per autorepeat button on 32Bit ARM 8 | * 9 | * Copyright (C) 2012-2023 Armin Joachimsmeyer 10 | * armin.joachimsmeyer@gmail.com 11 | * 12 | * This file is part of BlueDisplay https://github.com/ArminJo/android-blue-display. 13 | * 14 | * BlueDisplay is free software: you can redistribute it and/or modify 15 | * it under the terms of the GNU General Public License as published by 16 | * the Free Software Foundation, either version 3 of the License, or 17 | * (at your option) any later version. 18 | * 19 | * This program is distributed in the hope that it will be useful, 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 22 | * See the GNU General Public License for more details. 23 | * 24 | * You should have received a copy of the GNU General Public License 25 | * along with this program. If not, see . 26 | * 27 | */ 28 | 29 | #ifndef _TOUCHBUTTON_AUTOREPEAT_HPP 30 | #define _TOUCHBUTTON_AUTOREPEAT_HPP 31 | #include "LocalGUI/LocalTouchButtonAutorepeat.h" 32 | 33 | /** @addtogroup Gui_Library 34 | * @{ 35 | */ 36 | /** @addtogroup Button 37 | * @{ 38 | */ 39 | 40 | #define AUTOREPEAT_BUTTON_STATE_AFTER_FIRST_DELAY 0 41 | #define AUTOREPEAT_BUTTON_STATE_FIRST_PERIOD 1 42 | #define AUTOREPEAT_BUTTON_STATE_SECOND_PERIOD 3 43 | #define AUTOREPEAT_BUTTON_STATE_DISABLED_UNTIL_END_OF_TOUCH 4 44 | 45 | uint8_t LocalTouchButtonAutorepeat::sState; 46 | uint16_t LocalTouchButtonAutorepeat::sCount; 47 | 48 | unsigned long LocalTouchButtonAutorepeat::sCurrentCallbackDelayMillis; 49 | unsigned long LocalTouchButtonAutorepeat::sMillisOfLastCallOfCallback; 50 | extern bool isFirstTouchOfButtonOrSlider(); // must be provided by main program 51 | 52 | LocalTouchButtonAutorepeat::LocalTouchButtonAutorepeat() { // @suppress("Class members should be properly initialized") 53 | // List handling is done in the base class 54 | } 55 | 56 | #if !defined(ARDUINO) 57 | LocalTouchButtonAutorepeat::~LocalTouchButtonAutorepeat() { 58 | // List handling is done in the base class 59 | } 60 | #endif 61 | 62 | #if !defined(DISABLE_REMOTE_DISPLAY) 63 | /* 64 | * Required for creating a local autorepeat button for an existing aBDButton at BDButton::init 65 | */ 66 | LocalTouchButtonAutorepeat::LocalTouchButtonAutorepeat(BDButton *aBDButtonPtr) : // @suppress("Class members should be properly initialized") 67 | LocalTouchButton(aBDButtonPtr) { 68 | } 69 | #endif 70 | /** 71 | * after aMillisFirstDelay milliseconds a callback is done every aMillisFirstRate milliseconds for aFirstCount times 72 | * after this a callback is done every aMillisSecondRate milliseconds 73 | */ 74 | void LocalTouchButtonAutorepeat::setButtonAutorepeatTiming(uint16_t aMillisFirstDelay, uint16_t aMillisFirstRate, 75 | uint16_t aFirstCount, uint16_t aMillisSecondRate) { 76 | mMillisFirstDelay = aMillisFirstDelay; 77 | mMillisFirstRate = aMillisFirstRate; 78 | if (aFirstCount < 1) { 79 | aFirstCount = 1; 80 | } 81 | mFirstCount = aFirstCount; 82 | mMillisSecondRate = aMillisSecondRate; 83 | // do it here since flags are initialized by init() 84 | mFlags |= FLAG_BUTTON_TYPE_AUTOREPEAT; 85 | 86 | // Replace standard button handler with autorepeatTouchHandler 87 | mOriginalButtonOnTouchHandler = mOnTouchHandler; 88 | mOnTouchHandler = ((void (*)(LocalTouchButton*, int16_t)) &autorepeatTouchHandler); 89 | } 90 | 91 | void LocalTouchButtonAutorepeat::disableAutorepeatUntilEndOfTouch() { 92 | sState = AUTOREPEAT_BUTTON_STATE_DISABLED_UNTIL_END_OF_TOUCH; 93 | } 94 | 95 | /** 96 | * Touch handler for button object called at touch down, which in turn implements the autorepeat functionality 97 | * by enabling the autorepeatButtonTimerHandler to be called with the initial delay 98 | */ 99 | void LocalTouchButtonAutorepeat::autorepeatTouchHandler(LocalTouchButtonAutorepeat *aTheTouchedButton, int16_t aButtonValue) { 100 | (void)aButtonValue; // not required here 101 | /* 102 | * Autorepeat is implemented by periodic calls of checkAllButtons() by main loop, which ends up here 103 | * We know that touch is still in the button area 104 | */ 105 | bool tDoCallback = false; 106 | # if defined(TRACE) 107 | Serial.print(F("First=")); 108 | Serial.print(isFirstTouchOfButtonOrSlider()); 109 | Serial.print(F(" State=")); 110 | Serial.println(sState); 111 | # endif 112 | /* 113 | * Check if we are called initially on touch down 114 | * sTouchPanelButtonOrSliderTouched is set to true just after the successful call of checkAllButtons() 115 | * which means that it is false at the time of first call of checkAllButtons() which in turn calls autorepeatTouchHandler(). 116 | */ 117 | if (sTouchObjectTouched == NO_TOUCH) { 118 | sState = AUTOREPEAT_BUTTON_STATE_AFTER_FIRST_DELAY; 119 | sCurrentCallbackDelayMillis = aTheTouchedButton->mMillisFirstDelay; 120 | sCount = aTheTouchedButton->mFirstCount; 121 | tDoCallback = true; 122 | 123 | } else if (sState != AUTOREPEAT_BUTTON_STATE_DISABLED_UNTIL_END_OF_TOUCH 124 | && (millis() - sMillisOfLastCallOfCallback > sCurrentCallbackDelayMillis)) { 125 | /* 126 | * Period has expired 127 | */ 128 | 129 | switch (sState) { 130 | case AUTOREPEAT_BUTTON_STATE_AFTER_FIRST_DELAY: 131 | // register delay for first autorepeat rate 132 | sCurrentCallbackDelayMillis = aTheTouchedButton->mMillisFirstRate; 133 | sState = AUTOREPEAT_BUTTON_STATE_FIRST_PERIOD; 134 | sCount--; 135 | break; 136 | case AUTOREPEAT_BUTTON_STATE_FIRST_PERIOD: 137 | if (sCount == 0) { 138 | // register delay for second and last autorepeat rate 139 | sCurrentCallbackDelayMillis = aTheTouchedButton->mMillisSecondRate; 140 | sState = AUTOREPEAT_BUTTON_STATE_SECOND_PERIOD; 141 | } else { 142 | sCount--; 143 | } 144 | break; 145 | case AUTOREPEAT_BUTTON_STATE_SECOND_PERIOD: 146 | // here we stay as long as button is pressed 147 | sCount++; // just for fun 148 | break; 149 | } 150 | tDoCallback = true; 151 | } 152 | 153 | if (tDoCallback) { 154 | if (aTheTouchedButton->mFlags & FLAG_BUTTON_DO_BEEP_ON_TOUCH) { 155 | playFeedbackTone(); 156 | } 157 | 158 | #if defined(DISABLE_REMOTE_DISPLAY) 159 | aTheTouchedButton->mOriginalButtonOnTouchHandler(aTheTouchedButton, aTheTouchedButton->mValue); 160 | #else // SUPPORT_REMOTE_AND_LOCAL_DISPLAY is defined here 161 | aTheTouchedButton->mOriginalButtonOnTouchHandler((LocalTouchButton*) aTheTouchedButton->mBDButtonPtr, aTheTouchedButton->mValue); 162 | #endif 163 | sMillisOfLastCallOfCallback = millis(); 164 | } 165 | } 166 | 167 | /** @} */ 168 | /** @} */ 169 | #endif // _TOUCHBUTTON_AUTOREPEAT_HPP 170 | -------------------------------------------------------------------------------- /src/LocalGUI/ThickLine.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ThickLine.h 3 | * 4 | * @date 25.03.2013 5 | * @author Armin Joachimsmeyer 6 | * armin.joachimsmeyer@gmail.com 7 | * @copyright LGPL v3 (http://www.gnu.org/licenses/lgpl.html) 8 | * @version 1.5.0 9 | */ 10 | 11 | #ifndef _THICKLINE_H 12 | #define _THICKLINE_H 13 | 14 | #include 15 | 16 | /* 17 | * Overlap means drawing additional pixel when changing minor direction 18 | * Needed for drawThickLine, otherwise some pixels will be missing in the thick line 19 | */ 20 | #define LINE_OVERLAP_NONE 0 // No line overlap, like in standard Bresenham 21 | #define LINE_OVERLAP_MAJOR 0x01 // Overlap - first go major then minor direction. Pixel is drawn as extension after actual line 22 | #define LINE_OVERLAP_MINOR 0x02 // Overlap - first go minor then major direction. Pixel is drawn as extension before next line 23 | #define LINE_OVERLAP_BOTH 0x03 // Overlap - both 24 | 25 | #define LINE_THICKNESS_MIDDLE 0 // Start point is on the line at center of the thick line 26 | #define LINE_THICKNESS_DRAW_CLOCKWISE 1 // Start point is on the counter clockwise border line 27 | #define LINE_THICKNESS_DRAW_COUNTERCLOCKWISE 2 // Start point is on the clockwise border line 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | void drawLineOverlap(unsigned int aXStart, unsigned int aYStart, unsigned int aXEnd, unsigned int aYEnd, uint8_t aOverlap, uint16_t aColor); 34 | void drawThickLine(unsigned int aXStart, unsigned int aYStart, unsigned int aXEnd, unsigned int aYEnd, unsigned int aThickness, uint8_t aThicknessMode, 35 | uint16_t aColor); 36 | void drawThickLineSimple(unsigned int aXStart, unsigned int aYStart, unsigned int aXEnd, unsigned int aYEnd, unsigned int aThickness, uint8_t aThicknessMode, 37 | uint16_t aColor); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif // _THICKLINE_H 44 | -------------------------------------------------------------------------------- /src/LocalGUI/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax coloring map for LocalTouchButton, 3 | # LocalTouchButtonAutorepeat 4 | # and LocalTouchSlider 5 | ####################################### 6 | 7 | ####################################### 8 | # Datatypes (KEYWORD1) 9 | ####################################### 10 | 11 | LocalTouchButton KEYWORD1 12 | LocalTouchSlider KEYWORD1 13 | LocalTouchButtonAutorepeat KEYWORD1 14 | Chart KEYWORD1 15 | 16 | ####################################### 17 | # Methods and Functions (KEYWORD2) 18 | ####################################### 19 | 20 | # from LocalTouchButton 21 | init KEYWORD2 22 | setDefaultTouchBorder KEYWORD2 23 | setDefaultButtonColor KEYWORD2 24 | setDefaultCaptionColor KEYWORD2 25 | checkAllButtons KEYWORD2 26 | activateAllButtons KEYWORD2 27 | deactivateAllButtons KEYWORD2 28 | initSimpleButton KEYWORD2 29 | initButton KEYWORD2 30 | checkButton KEYWORD2 31 | drawButton KEYWORD2 32 | setPosition KEYWORD2 33 | setCaption KEYWORD2 34 | setCaptionColor KEYWORD2 35 | setColor KEYWORD2 36 | setValue KEYWORD2 37 | getCaption KEYWORD2 38 | getPositionXRight KEYWORD2 39 | getPositionX KEYWORD2 40 | getPositionYBottom KEYWORD2 41 | getPositionY KEYWORD2 42 | activate KEYWORD2 43 | deactivate KEYWORD2 44 | toString KEYWORD2 45 | 46 | # from LocalTouchButtonAutorepeat 47 | setButtonAutorepeatTiming KEYWORD2 48 | 49 | # from LocalTouchSlider 50 | init KEYWORD2 51 | setDefaults KEYWORD2 52 | checkAllSliders KEYWORD2 53 | deactivateAllSliders KEYWORD2 54 | initSimpleSlider KEYWORD2 55 | initSlider KEYWORD2 56 | initSliderColors KEYWORD2 57 | initValueAndCaptionBackgroundColor KEYWORD2 58 | drawSlider KEYWORD2 59 | checkSlider KEYWORD2 60 | drawBar KEYWORD2 61 | setBarColor KEYWORD2 62 | setDefaultSliderColor KEYWORD2 63 | setDefaultBarColor KEYWORD2 64 | setSliderColor KEYWORD2 65 | setBarColor KEYWORD2 66 | setBarThresholdColor KEYWORD2 67 | getActualValue KEYWORD2 68 | setActualValue KEYWORD2 69 | getPositionXRight KEYWORD2 70 | getPositionYBottom KEYWORD2 71 | activate KEYWORD2 72 | deactivate KEYWORD2 73 | 74 | 75 | ####################################### 76 | # Constants (LITERAL1) 77 | ####################################### 78 | -------------------------------------------------------------------------------- /src/LocalHX8347DDisplay.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * LocalDisplay.hpp 3 | * 4 | * 5 | * Copyright (C) 2023 Armin Joachimsmeyer 6 | * armin.joachimsmeyer@gmail.com 7 | * 8 | * This file is part of BlueDisplay https://github.com/ArminJo/android-blue-display. 9 | * 10 | * BlueDisplay is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | * See the GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | */ 24 | #ifndef _LOCAL_DISPLAY_HPP 25 | #define _LOCAL_DISPLAY_HPP 26 | 27 | #define USE_HX8347D 28 | #include "LocalDisplay/fonts.hpp" 29 | #include "LocalDisplay/LocalDisplayInterface.hpp" // The implementation of the local display must be included first since it defines LOCAL_DISPLAY_HEIGHT etc. 30 | #include "LocalDisplay/ADS7846.hpp" // Must be after the local display implementation since it uses e.g. LOCAL_DISPLAY_HEIGHT 31 | #include "LocalDisplay/LocalEventHelper.hpp" 32 | 33 | #if defined(SUPPORT_LOCAL_LONG_TOUCH_DOWN_DETECTION) || defined(LOCAL_DISPLAY_GENERATES_BD_EVENTS) 34 | #include "EventHandler.hpp" 35 | #endif 36 | 37 | #endif // _LOCAL_DISPLAY_HPP 38 | -------------------------------------------------------------------------------- /src/LocalSSD1289Display.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * LocalDisplay.hpp 3 | * 4 | * 5 | * Copyright (C) 2023 Armin Joachimsmeyer 6 | * armin.joachimsmeyer@gmail.com 7 | * 8 | * This file is part of BlueDisplay https://github.com/ArminJo/android-blue-display. 9 | * 10 | * BlueDisplay is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18 | * See the GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | * 23 | */ 24 | #ifndef _LOCAL_DISPLAY_HPP 25 | #define _LOCAL_DISPLAY_HPP 26 | 27 | #define USE_SSD1289 28 | #include "LocalDisplay/fonts.hpp" 29 | #include "LocalDisplay/LocalDisplayInterface.hpp" // The implementation of the local display must be included first since it defines LOCAL_DISPLAY_HEIGHT etc. 30 | #include "LocalDisplay/ADS7846.hpp" // Must be after the local display implementation since it uses e.g. LOCAL_DISPLAY_HEIGHT 31 | #include "LocalDisplay/LocalEventHelper.hpp" 32 | 33 | #if defined(SUPPORT_LOCAL_LONG_TOUCH_DOWN_DETECTION) || defined(LOCAL_DISPLAY_GENERATES_BD_EVENTS) 34 | #include "EventHandler.hpp" 35 | #endif 36 | #endif // _LOCAL_DISPLAY_HPP 37 | --------------------------------------------------------------------------------