- added new bluetooth project
- some things work, many not, needs some work
This commit is contained in:
parent
67ee3963a6
commit
6fbae42867
16 changed files with 909 additions and 0 deletions
5
vscode/OmobiLEDdisplayBluetooth/.gitignore
vendored
Normal file
5
vscode/OmobiLEDdisplayBluetooth/.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
.pio
|
||||||
|
.vscode/.browse.c_cpp.db*
|
||||||
|
.vscode/c_cpp_properties.json
|
||||||
|
.vscode/launch.json
|
||||||
|
.vscode/ipch
|
67
vscode/OmobiLEDdisplayBluetooth/.travis.yml
Normal file
67
vscode/OmobiLEDdisplayBluetooth/.travis.yml
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
# Continuous Integration (CI) is the practice, in software
|
||||||
|
# engineering, of merging all developer working copies with a shared mainline
|
||||||
|
# several times a day < https://docs.platformio.org/page/ci/index.html >
|
||||||
|
#
|
||||||
|
# Documentation:
|
||||||
|
#
|
||||||
|
# * Travis CI Embedded Builds with PlatformIO
|
||||||
|
# < https://docs.travis-ci.com/user/integration/platformio/ >
|
||||||
|
#
|
||||||
|
# * PlatformIO integration with Travis CI
|
||||||
|
# < https://docs.platformio.org/page/ci/travis.html >
|
||||||
|
#
|
||||||
|
# * User Guide for `platformio ci` command
|
||||||
|
# < https://docs.platformio.org/page/userguide/cmd_ci.html >
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Please choose one of the following templates (proposed below) and uncomment
|
||||||
|
# it (remove "# " before each line) or use own configuration according to the
|
||||||
|
# Travis CI documentation (see above).
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Template #1: General project. Test it using existing `platformio.ini`.
|
||||||
|
#
|
||||||
|
|
||||||
|
# language: python
|
||||||
|
# python:
|
||||||
|
# - "2.7"
|
||||||
|
#
|
||||||
|
# sudo: false
|
||||||
|
# cache:
|
||||||
|
# directories:
|
||||||
|
# - "~/.platformio"
|
||||||
|
#
|
||||||
|
# install:
|
||||||
|
# - pip install -U platformio
|
||||||
|
# - platformio update
|
||||||
|
#
|
||||||
|
# script:
|
||||||
|
# - platformio run
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Template #2: The project is intended to be used as a library with examples.
|
||||||
|
#
|
||||||
|
|
||||||
|
# language: python
|
||||||
|
# python:
|
||||||
|
# - "2.7"
|
||||||
|
#
|
||||||
|
# sudo: false
|
||||||
|
# cache:
|
||||||
|
# directories:
|
||||||
|
# - "~/.platformio"
|
||||||
|
#
|
||||||
|
# env:
|
||||||
|
# - PLATFORMIO_CI_SRC=path/to/test/file.c
|
||||||
|
# - PLATFORMIO_CI_SRC=examples/file.ino
|
||||||
|
# - PLATFORMIO_CI_SRC=path/to/test/directory
|
||||||
|
#
|
||||||
|
# install:
|
||||||
|
# - pip install -U platformio
|
||||||
|
# - platformio update
|
||||||
|
#
|
||||||
|
# script:
|
||||||
|
# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N
|
7
vscode/OmobiLEDdisplayBluetooth/.vscode/extensions.json
vendored
Normal file
7
vscode/OmobiLEDdisplayBluetooth/.vscode/extensions.json
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||||
|
// for the documentation about the extensions.json format
|
||||||
|
"recommendations": [
|
||||||
|
"platformio.platformio-ide"
|
||||||
|
]
|
||||||
|
}
|
10
vscode/OmobiLEDdisplayBluetooth/.vscode/settings.json
vendored
Normal file
10
vscode/OmobiLEDdisplayBluetooth/.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"functional": "cpp",
|
||||||
|
"array": "cpp",
|
||||||
|
"deque": "cpp",
|
||||||
|
"string": "cpp",
|
||||||
|
"vector": "cpp",
|
||||||
|
"unordered_map": "cpp"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
#ifndef BLUETOOTH_LE_UART_SERVER
|
||||||
|
#define BLUETOOTH_LE_UART_SERVER
|
||||||
|
|
||||||
|
#include <BLEDevice.h>
|
||||||
|
#include <BLEServer.h>
|
||||||
|
#include <BLEUtils.h>
|
||||||
|
#include <BLE2902.h>
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
class BluetoothLeUartServerCallbacks;
|
||||||
|
|
||||||
|
class BluetoothLeUartServer : protected BLEServerCallbacks, protected BLECharacteristicCallbacks
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit BluetoothLeUartServer(String deviceName, const char uartServiceUUID[36], const char rxUUID[36], const char txUUID[36]);
|
||||||
|
|
||||||
|
// befriend for callbacks
|
||||||
|
friend class BLEServer;
|
||||||
|
friend class BLECharacteristic;
|
||||||
|
|
||||||
|
// public functions
|
||||||
|
void setCallbacks(BluetoothLeUartServerCallbacks *callbacks);
|
||||||
|
void sendData(String data);
|
||||||
|
|
||||||
|
bool getDeviceConnected();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// callbacks for BLEServer
|
||||||
|
void onConnect(BLEServer *pServer) override;
|
||||||
|
void onDisconnect(BLEServer *pServer) override;
|
||||||
|
|
||||||
|
// callback for BLECharacteristic
|
||||||
|
void onWrite(BLECharacteristic *rxCharacteristic) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const char *uartServiceUUID;
|
||||||
|
const char *rxUUID;
|
||||||
|
const char *txUUID;
|
||||||
|
|
||||||
|
BLEServer *bleServer;
|
||||||
|
BLEService *bleService;
|
||||||
|
BLECharacteristic *txCharacteristic;
|
||||||
|
BLECharacteristic *rxCharacteristic;
|
||||||
|
|
||||||
|
bool deviceConnected = false;
|
||||||
|
BluetoothLeUartServerCallbacks *callbacks;
|
||||||
|
};
|
||||||
|
|
||||||
|
class BluetoothLeUartServerCallbacks
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~BluetoothLeUartServerCallbacks(){};
|
||||||
|
|
||||||
|
const char* test = "testlol";
|
||||||
|
|
||||||
|
virtual void onDeviceConnectedChanged(bool deviceConnected);
|
||||||
|
virtual void onDataReceived(String data);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // BLUETOOTH_LE_UART_SERVER
|
|
@ -0,0 +1,98 @@
|
||||||
|
#ifndef LED_DISPLAY_CONTROLLER
|
||||||
|
#define LED_DISPLAY_CONTROLLER
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <Adafruit_GFX.h>
|
||||||
|
#include <Adafruit_NeoMatrix.h>
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
#include "esp_task_wdt.h"
|
||||||
|
#include <EEPROM.h>
|
||||||
|
|
||||||
|
class LedDisplayController
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit LedDisplayController(const byte pin);
|
||||||
|
~LedDisplayController();
|
||||||
|
|
||||||
|
enum text_align_t
|
||||||
|
{
|
||||||
|
TEXTLEFT,
|
||||||
|
TEXTCENTER,
|
||||||
|
TEXTRIGHT
|
||||||
|
};
|
||||||
|
|
||||||
|
enum set_param_index_t
|
||||||
|
{
|
||||||
|
PTEXT,
|
||||||
|
PTIME,
|
||||||
|
PCOLOR,
|
||||||
|
PALIGN,
|
||||||
|
PSCROLL,
|
||||||
|
PSCROLL_RUNS,
|
||||||
|
PACTIVE
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint16_t text_nr_sets = 2;
|
||||||
|
static const uint16_t MAX_TXT_LENGTH = 256;
|
||||||
|
static const int nr_param_names = 7;
|
||||||
|
|
||||||
|
typedef struct text_set_t
|
||||||
|
{
|
||||||
|
char text[MAX_TXT_LENGTH];
|
||||||
|
uint16_t time_ms;
|
||||||
|
uint16_t color;
|
||||||
|
text_align_t align;
|
||||||
|
bool text_scroll;
|
||||||
|
uint16_t text_scroll_pass;
|
||||||
|
bool active;
|
||||||
|
} text_set_t;
|
||||||
|
|
||||||
|
typedef struct sets_t
|
||||||
|
{
|
||||||
|
text_set_t sets[text_nr_sets];
|
||||||
|
char valid[3];
|
||||||
|
} sets_t;
|
||||||
|
|
||||||
|
void disp_update();
|
||||||
|
|
||||||
|
void setTexts(sets_t texts);
|
||||||
|
sets_t getTexts();
|
||||||
|
|
||||||
|
uint16_t Color(uint8_t r, uint8_t g, uint8_t b);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
TaskHandle_t displayUpdateTask;
|
||||||
|
|
||||||
|
Adafruit_NeoMatrix* matrix;
|
||||||
|
|
||||||
|
const String set_param_name[nr_param_names] = {"text_", "time_", "color_", "align_", "scroll_", "scroll_runs_", "active_"};
|
||||||
|
const uint16_t DISP_STRUCT_SIZE = sizeof(sets_t);
|
||||||
|
sets_t text_sets;
|
||||||
|
|
||||||
|
uint16_t text_curr_nr;
|
||||||
|
uint32_t text_set_starttime;
|
||||||
|
|
||||||
|
int text_pos;
|
||||||
|
unsigned int text_pass;
|
||||||
|
unsigned int textpixel;
|
||||||
|
|
||||||
|
bool disp_show;
|
||||||
|
|
||||||
|
void storeDisplaySet();
|
||||||
|
bool loadDisplaySet();
|
||||||
|
|
||||||
|
void disp_scroll_text();
|
||||||
|
void disp_switch_text();
|
||||||
|
void disp_start_set();
|
||||||
|
void disp_init();
|
||||||
|
void show_matrix(const char *text, int pos, uint16_t color);
|
||||||
|
String get_paramstring_from_struct(String name);
|
||||||
|
void set_param_to_struct(String name, String value);
|
||||||
|
String getset_param_at_struct(String name, String value, bool set);
|
||||||
|
};
|
||||||
|
|
||||||
|
void updateDisplayGlobal(void*);
|
||||||
|
extern LedDisplayController *ledDisplayControllerGlobal;
|
||||||
|
|
||||||
|
#endif // LED_DISPLAY_CONTROLLER
|
27
vscode/OmobiLEDdisplayBluetooth/include/OmobiLedDisplay.h
Normal file
27
vscode/OmobiLEDdisplayBluetooth/include/OmobiLedDisplay.h
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
#ifndef OMOBI_LED_DISPLAY
|
||||||
|
#define OMOBI_LED_DISPLAY
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
#include "BluetoothLeUartServer.h"
|
||||||
|
#include "LedDisplayController.h"
|
||||||
|
|
||||||
|
class OmobiLedDisplay : protected BluetoothLeUartServerCallbacks {
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit OmobiLedDisplay(String deviceName, const byte ledPin);
|
||||||
|
|
||||||
|
// befriend for callbacks
|
||||||
|
friend class BluetoothLeUartServer;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// calbacks for BluetoothLeUartServerCallbacks
|
||||||
|
void onDeviceConnectedChanged(bool deviceConnected) override;
|
||||||
|
void onDataReceived(String data) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
LedDisplayController* ledDisplayController;
|
||||||
|
BluetoothLeUartServer * bleServer;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // OMOBI_LED_DISPLAY
|
39
vscode/OmobiLEDdisplayBluetooth/include/README
Normal file
39
vscode/OmobiLEDdisplayBluetooth/include/README
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
|
||||||
|
This directory is intended for project header files.
|
||||||
|
|
||||||
|
A header file is a file containing C declarations and macro definitions
|
||||||
|
to be shared between several project source files. You request the use of a
|
||||||
|
header file in your project source file (C, C++, etc) located in `src` folder
|
||||||
|
by including it, with the C preprocessing directive `#include'.
|
||||||
|
|
||||||
|
```src/main.c
|
||||||
|
|
||||||
|
#include "header.h"
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Including a header file produces the same results as copying the header file
|
||||||
|
into each source file that needs it. Such copying would be time-consuming
|
||||||
|
and error-prone. With a header file, the related declarations appear
|
||||||
|
in only one place. If they need to be changed, they can be changed in one
|
||||||
|
place, and programs that include the header file will automatically use the
|
||||||
|
new version when next recompiled. The header file eliminates the labor of
|
||||||
|
finding and changing all the copies as well as the risk that a failure to
|
||||||
|
find one copy will result in inconsistencies within a program.
|
||||||
|
|
||||||
|
In C, the usual convention is to give header files names that end with `.h'.
|
||||||
|
It is most portable to use only letters, digits, dashes, and underscores in
|
||||||
|
header file names, and at most one dot.
|
||||||
|
|
||||||
|
Read more about using header files in official GCC documentation:
|
||||||
|
|
||||||
|
* Include Syntax
|
||||||
|
* Include Operation
|
||||||
|
* Once-Only Headers
|
||||||
|
* Computed Includes
|
||||||
|
|
||||||
|
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
2
vscode/OmobiLEDdisplayBluetooth/include/omobi_html.h
Normal file
2
vscode/OmobiLEDdisplayBluetooth/include/omobi_html.h
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
|
46
vscode/OmobiLEDdisplayBluetooth/lib/README
Normal file
46
vscode/OmobiLEDdisplayBluetooth/lib/README
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
|
||||||
|
This directory is intended for project specific (private) libraries.
|
||||||
|
PlatformIO will compile them to static libraries and link into executable file.
|
||||||
|
|
||||||
|
The source code of each library should be placed in a an own separate directory
|
||||||
|
("lib/your_library_name/[here are source files]").
|
||||||
|
|
||||||
|
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
||||||
|
|
||||||
|
|--lib
|
||||||
|
| |
|
||||||
|
| |--Bar
|
||||||
|
| | |--docs
|
||||||
|
| | |--examples
|
||||||
|
| | |--src
|
||||||
|
| | |- Bar.c
|
||||||
|
| | |- Bar.h
|
||||||
|
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||||
|
| |
|
||||||
|
| |--Foo
|
||||||
|
| | |- Foo.c
|
||||||
|
| | |- Foo.h
|
||||||
|
| |
|
||||||
|
| |- README --> THIS FILE
|
||||||
|
|
|
||||||
|
|- platformio.ini
|
||||||
|
|--src
|
||||||
|
|- main.c
|
||||||
|
|
||||||
|
and a contents of `src/main.c`:
|
||||||
|
```
|
||||||
|
#include <Foo.h>
|
||||||
|
#include <Bar.h>
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
PlatformIO Library Dependency Finder will find automatically dependent
|
||||||
|
libraries scanning project source files.
|
||||||
|
|
||||||
|
More information about PlatformIO Library Dependency Finder
|
||||||
|
- https://docs.platformio.org/page/librarymanager/ldf.html
|
24
vscode/OmobiLEDdisplayBluetooth/platformio.ini
Normal file
24
vscode/OmobiLEDdisplayBluetooth/platformio.ini
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
; PlatformIO Project Configuration File
|
||||||
|
;
|
||||||
|
; Build options: build flags, source filter
|
||||||
|
; Upload options: custom upload port, speed and extra flags
|
||||||
|
; Library options: dependencies, extra library storages
|
||||||
|
; Advanced options: extra scripting
|
||||||
|
;
|
||||||
|
; Please visit documentation for the other options and examples
|
||||||
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
|
[env:esp32]
|
||||||
|
platform = espressif32
|
||||||
|
board = esp32doit-devkit-v1
|
||||||
|
framework = arduino
|
||||||
|
lib_deps =
|
||||||
|
Wire
|
||||||
|
SPI
|
||||||
|
adafruit/Adafruit GFX Library@^1.10.1
|
||||||
|
adafruit/Adafruit BusIO@1.4.1
|
||||||
|
adafruit/Adafruit NeoPixel@^1.6.0
|
||||||
|
adafruit/Adafruit NeoMatrix@^1.1.5
|
||||||
|
bblanchon/ArduinoJson@^6.16.1
|
||||||
|
monitor_filters = esp32_exception_decoder
|
||||||
|
monitor_speed = 115200
|
|
@ -0,0 +1,81 @@
|
||||||
|
#include "BluetoothLeUartServer.h"
|
||||||
|
|
||||||
|
BluetoothLeUartServer::BluetoothLeUartServer(String deviceName, const char uartServiceUUID[36], const char rxUUID[36], const char txUUID[36])
|
||||||
|
{
|
||||||
|
this->uartServiceUUID = uartServiceUUID;
|
||||||
|
this->rxUUID = rxUUID;
|
||||||
|
this->txUUID = txUUID;
|
||||||
|
|
||||||
|
this->callbacks = nullptr;
|
||||||
|
|
||||||
|
// Create the BLE Device
|
||||||
|
BLEDevice::init(deviceName.c_str()); // Give it a name
|
||||||
|
|
||||||
|
// Create the BLE Server
|
||||||
|
bleServer = BLEDevice::createServer();
|
||||||
|
bleServer->setCallbacks(this);
|
||||||
|
|
||||||
|
// Create the BLE Service
|
||||||
|
bleService = bleServer->createService(this->uartServiceUUID);
|
||||||
|
|
||||||
|
// Create a BLE Characteristic
|
||||||
|
txCharacteristic = bleService->createCharacteristic(
|
||||||
|
this->txUUID,
|
||||||
|
BLECharacteristic::PROPERTY_NOTIFY);
|
||||||
|
|
||||||
|
txCharacteristic->addDescriptor(new BLE2902());
|
||||||
|
|
||||||
|
rxCharacteristic = bleService->createCharacteristic(
|
||||||
|
this->rxUUID,
|
||||||
|
BLECharacteristic::PROPERTY_READ |
|
||||||
|
BLECharacteristic::PROPERTY_WRITE);
|
||||||
|
|
||||||
|
rxCharacteristic->setCallbacks(this);
|
||||||
|
|
||||||
|
// Start the service
|
||||||
|
bleService->start();
|
||||||
|
|
||||||
|
// Start advertising
|
||||||
|
bleServer->getAdvertising()->addServiceUUID(bleService->getUUID());
|
||||||
|
bleServer->getAdvertising()->setScanResponse(true);
|
||||||
|
bleServer->getAdvertising()->setMinPreferred(0x06); // functions that help with iPhone connections issue
|
||||||
|
bleServer->getAdvertising()->setMinPreferred(0x12);
|
||||||
|
bleServer->getAdvertising()->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BluetoothLeUartServer::setCallbacks(BluetoothLeUartServerCallbacks *callbacks)
|
||||||
|
{
|
||||||
|
this->callbacks = callbacks;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BluetoothLeUartServer::sendData(String data)
|
||||||
|
{
|
||||||
|
txCharacteristic->setValue(data.c_str());
|
||||||
|
txCharacteristic->notify();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BluetoothLeUartServer::onConnect(BLEServer *pServer)
|
||||||
|
{
|
||||||
|
this->deviceConnected = true;
|
||||||
|
if (this->callbacks != nullptr) {
|
||||||
|
this->callbacks->onDeviceConnectedChanged(this->deviceConnected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BluetoothLeUartServer::onDisconnect(BLEServer *pServer)
|
||||||
|
{
|
||||||
|
this->deviceConnected = false;
|
||||||
|
if (this->callbacks != nullptr)
|
||||||
|
this->callbacks->onDeviceConnectedChanged(this->deviceConnected);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BluetoothLeUartServer::onWrite(BLECharacteristic *rxCharacteristic)
|
||||||
|
{
|
||||||
|
if (this->callbacks != nullptr)
|
||||||
|
this->callbacks->onDataReceived(rxCharacteristic->getValue().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BluetoothLeUartServer::getDeviceConnected()
|
||||||
|
{
|
||||||
|
return this->deviceConnected;
|
||||||
|
}
|
258
vscode/OmobiLEDdisplayBluetooth/src/LedDisplayController.cpp
Normal file
258
vscode/OmobiLEDdisplayBluetooth/src/LedDisplayController.cpp
Normal file
|
@ -0,0 +1,258 @@
|
||||||
|
#include "LedDisplayController.h"
|
||||||
|
|
||||||
|
LedDisplayController *ledDisplayControllerGlobal = nullptr;
|
||||||
|
|
||||||
|
LedDisplayController::LedDisplayController(const byte pin)
|
||||||
|
{
|
||||||
|
ledDisplayControllerGlobal = this;
|
||||||
|
|
||||||
|
this->matrix = new Adafruit_NeoMatrix(8, 8, 1, 1, pin,
|
||||||
|
NEO_TILE_TOP + NEO_TILE_LEFT + NEO_TILE_ROWS + NEO_TILE_PROGRESSIVE +
|
||||||
|
NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_TILE_PROGRESSIVE,
|
||||||
|
NEO_GRB + NEO_KHZ800);
|
||||||
|
|
||||||
|
this->matrix->begin();
|
||||||
|
this->matrix->setTextWrap(false);
|
||||||
|
this->matrix->setBrightness(40);
|
||||||
|
|
||||||
|
text_curr_nr = 0;
|
||||||
|
text_set_starttime = 0;
|
||||||
|
text_pass = 0;
|
||||||
|
textpixel = 0;
|
||||||
|
disp_show = false;
|
||||||
|
|
||||||
|
this->disp_init();
|
||||||
|
|
||||||
|
// create updater task
|
||||||
|
xTaskCreatePinnedToCore(updateDisplayGlobal, "DisplayUpdateTask", 10000, NULL, 1, &displayUpdateTask, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LedDisplayController::disp_update()
|
||||||
|
{
|
||||||
|
if (this->disp_show)
|
||||||
|
{
|
||||||
|
disp_start_set();
|
||||||
|
if (true == text_sets.sets[text_curr_nr].active)
|
||||||
|
{
|
||||||
|
if (text_sets.sets[text_curr_nr].text != '\0')
|
||||||
|
{
|
||||||
|
if (text_sets.sets[text_curr_nr].text_scroll)
|
||||||
|
{
|
||||||
|
disp_scroll_text();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LedDisplayController::disp_init()
|
||||||
|
{
|
||||||
|
text_curr_nr = 0;
|
||||||
|
text_set_starttime = 0;
|
||||||
|
text_pass = 0;
|
||||||
|
text_pos = this->matrix->width();
|
||||||
|
disp_show = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LedDisplayController::disp_scroll_text()
|
||||||
|
{
|
||||||
|
this->matrix->fillScreen(0);
|
||||||
|
show_matrix(text_sets.sets[text_curr_nr].text, text_pos, text_sets.sets[text_curr_nr].color);
|
||||||
|
(int)text_pos--;
|
||||||
|
if (int(text_pos + textpixel) < 0)
|
||||||
|
{
|
||||||
|
text_pos = this->matrix->width();
|
||||||
|
text_pass++;
|
||||||
|
Serial.printf("Pass[%d] - set nr %d, Text: '%s' \n", text_pass, text_curr_nr, text_sets.sets[text_curr_nr].text);
|
||||||
|
}
|
||||||
|
delay(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LedDisplayController::disp_start_set()
|
||||||
|
{
|
||||||
|
if ((0 == text_set_starttime) ||
|
||||||
|
(text_sets.sets[text_curr_nr].text == '\0') ||
|
||||||
|
text_sets.sets[text_curr_nr].active == false ||
|
||||||
|
((text_sets.sets[text_curr_nr].text_scroll == false) && (text_sets.sets[text_curr_nr].time_ms > 0) && ((millis() - text_set_starttime) >= text_sets.sets[text_curr_nr].time_ms)) ||
|
||||||
|
((text_sets.sets[text_curr_nr].text_scroll == true) && (text_sets.sets[text_curr_nr].text_scroll_pass > 0) && (text_pass >= text_sets.sets[text_curr_nr].text_scroll_pass)) ||
|
||||||
|
(((text_sets.sets[text_curr_nr].text_scroll_pass == 0) || text_sets.sets[text_curr_nr].text_scroll == false) && (text_sets.sets[text_curr_nr].time_ms == 0) && ((millis() - text_set_starttime) >= 10000)))
|
||||||
|
{
|
||||||
|
//Serial.printf("[%lu] Meet start set condition. Curr set is %d. \n", millis(), text_curr_nr);
|
||||||
|
if (0 < text_set_starttime || text_sets.sets[text_curr_nr].text == '\0' || text_sets.sets[text_curr_nr].active == false)
|
||||||
|
text_curr_nr++;
|
||||||
|
if (text_curr_nr == text_nr_sets)
|
||||||
|
text_curr_nr = 0;
|
||||||
|
text_pass = 0;
|
||||||
|
if (text_sets.sets[text_curr_nr].text != '\0' && text_sets.sets[text_curr_nr].active == true)
|
||||||
|
{
|
||||||
|
Serial.printf("[%lu] Set %d. Runtime %d. Text:'%s'\n", millis(), text_curr_nr, text_sets.sets[text_curr_nr].time_ms, text_sets.sets[text_curr_nr].text);
|
||||||
|
this->matrix->fillScreen(0);
|
||||||
|
textpixel = 6 * strlen(text_sets.sets[text_curr_nr].text);
|
||||||
|
switch (text_sets.sets[text_curr_nr].align)
|
||||||
|
{
|
||||||
|
case TEXTLEFT:
|
||||||
|
text_pos = 0;
|
||||||
|
break;
|
||||||
|
case TEXTRIGHT:
|
||||||
|
text_pos = this->matrix->width();
|
||||||
|
break;
|
||||||
|
case TEXTCENTER:
|
||||||
|
text_pos = this->matrix->width() - textpixel;
|
||||||
|
text_pos = text_pos / 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
show_matrix(text_sets.sets[text_curr_nr].text, text_pos, text_sets.sets[text_curr_nr].color);
|
||||||
|
text_set_starttime = millis();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//Serial.printf("[%lu] Don't meet start set condition. Text is: %s. Active is: %d\n", millis(), text_sets.sets[text_curr_nr].text, text_sets.sets[text_curr_nr].active);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LedDisplayController::show_matrix(const char *text, int pos, uint16_t color)
|
||||||
|
{
|
||||||
|
Serial.printf("TEXT: %s (pos=%d, color=%d)\n", text, pos, color);
|
||||||
|
this->matrix->setTextColor(color);
|
||||||
|
this->matrix->setCursor(pos, 0);
|
||||||
|
this->matrix->print(text);
|
||||||
|
portDISABLE_INTERRUPTS();
|
||||||
|
this->matrix->show();
|
||||||
|
portENABLE_INTERRUPTS();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LedDisplayController::storeDisplaySet()
|
||||||
|
{
|
||||||
|
// write conf to EEPROM
|
||||||
|
EEPROM.begin(DISP_STRUCT_SIZE);
|
||||||
|
//for (size_t i = 0 ; i < DISP_STRUCT_SIZE ; i++)
|
||||||
|
//{
|
||||||
|
// EEPROM.write(i, 0);
|
||||||
|
//}
|
||||||
|
strncpy(text_sets.valid, "OK", sizeof(text_sets.valid));
|
||||||
|
EEPROM.put(0, text_sets);
|
||||||
|
EEPROM.commit();
|
||||||
|
EEPROM.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LedDisplayController::loadDisplaySet()
|
||||||
|
{
|
||||||
|
bool rc = false;
|
||||||
|
sets_t buf = {};
|
||||||
|
// read conf from EEPROM
|
||||||
|
EEPROM.begin(DISP_STRUCT_SIZE);
|
||||||
|
EEPROM.get(0, buf);
|
||||||
|
EEPROM.end();
|
||||||
|
if (strcmp(buf.valid, "OK") == 0)
|
||||||
|
{
|
||||||
|
rc = true;
|
||||||
|
memcpy(&text_sets, &buf, sizeof(text_sets));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memset(&text_sets, 0, sizeof(text_sets));
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
String LedDisplayController::get_paramstring_from_struct(String name)
|
||||||
|
{
|
||||||
|
return (getset_param_at_struct(name, "", false));
|
||||||
|
}
|
||||||
|
|
||||||
|
void LedDisplayController::set_param_to_struct(String name, String value)
|
||||||
|
{
|
||||||
|
getset_param_at_struct(name, value, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
String LedDisplayController::getset_param_at_struct(String name, String value, bool set)
|
||||||
|
{
|
||||||
|
String name_value = "";
|
||||||
|
int name_setnr_index = name.lastIndexOf("_");
|
||||||
|
int name_setnr = -1;
|
||||||
|
int name_index = -1;
|
||||||
|
String name_name = "unknown";
|
||||||
|
if (name_setnr_index > 0)
|
||||||
|
{
|
||||||
|
name_setnr = name.substring(name_setnr_index + 1).toInt();
|
||||||
|
name_name = name.substring(0, name_setnr_index + 1);
|
||||||
|
|
||||||
|
for (int pnr = 0; pnr < nr_param_names; pnr++)
|
||||||
|
{
|
||||||
|
if (name_name == set_param_name[pnr])
|
||||||
|
{
|
||||||
|
name_index = pnr;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Serial.printf("Param: (name=%s,set=%d, index=%d) %s = %s \n", name_name.c_str(), name_setnr, name_index, name.c_str(), value.c_str());
|
||||||
|
if (name_index != -1 && name_setnr != -1 && name_name != "unknown")
|
||||||
|
{
|
||||||
|
name_value += name_name + String(name_setnr) + "=";
|
||||||
|
switch (name_index)
|
||||||
|
{
|
||||||
|
case PCOLOR:
|
||||||
|
//if (true == set)
|
||||||
|
//text_sets.sets[name_setnr].color = (unint16_t)value.toInt();
|
||||||
|
name_value += String(text_sets.sets[name_setnr].color);
|
||||||
|
break;
|
||||||
|
case PTEXT:
|
||||||
|
if (true == set)
|
||||||
|
snprintf((char *)text_sets.sets[name_setnr].text, MAX_TXT_LENGTH, value.c_str());
|
||||||
|
name_value += String(text_sets.sets[name_setnr].text);
|
||||||
|
break;
|
||||||
|
case PTIME:
|
||||||
|
if (true == set)
|
||||||
|
text_sets.sets[name_setnr].time_ms = value.toInt() * 1000;
|
||||||
|
name_value += String(text_sets.sets[name_setnr].time_ms / 1000);
|
||||||
|
break;
|
||||||
|
case PSCROLL:
|
||||||
|
if (true == set)
|
||||||
|
text_sets.sets[name_setnr].text_scroll = (value == "true") ? true : false;
|
||||||
|
name_value += String(text_sets.sets[name_setnr].text_scroll);
|
||||||
|
break;
|
||||||
|
case PACTIVE:
|
||||||
|
if (true == set)
|
||||||
|
text_sets.sets[name_setnr].active = (value == "true") ? true : false;
|
||||||
|
name_value += String(text_sets.sets[name_setnr].active);
|
||||||
|
break;
|
||||||
|
case PALIGN:
|
||||||
|
if (true == set)
|
||||||
|
text_sets.sets[name_setnr].align = (text_align_t)value.toInt();
|
||||||
|
name_value += String(text_sets.sets[name_setnr].align);
|
||||||
|
break;
|
||||||
|
case PSCROLL_RUNS:
|
||||||
|
if (true == set)
|
||||||
|
text_sets.sets[name_setnr].text_scroll_pass = value.toInt();
|
||||||
|
name_value += String(text_sets.sets[name_setnr].text_scroll_pass);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//Serial.printf("get/set %s\n", name_value.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (name_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LedDisplayController::setTexts(sets_t texts) {
|
||||||
|
this->text_sets = texts;
|
||||||
|
this->storeDisplaySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
LedDisplayController::sets_t LedDisplayController::getTexts() {
|
||||||
|
return this->text_sets;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t LedDisplayController::Color(uint8_t r, uint8_t g, uint8_t b) {
|
||||||
|
return this->matrix->Color(r,g,b);
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateDisplayGlobal(void *)
|
||||||
|
{
|
||||||
|
for(;;) {
|
||||||
|
esp_task_wdt_reset();
|
||||||
|
delay(1);
|
||||||
|
ledDisplayControllerGlobal->disp_update();
|
||||||
|
}
|
||||||
|
}
|
140
vscode/OmobiLEDdisplayBluetooth/src/OmobiLedDisplay.cpp
Normal file
140
vscode/OmobiLEDdisplayBluetooth/src/OmobiLedDisplay.cpp
Normal file
|
@ -0,0 +1,140 @@
|
||||||
|
|
||||||
|
#include "OmobiLedDisplay.h"
|
||||||
|
|
||||||
|
OmobiLedDisplay::OmobiLedDisplay(String deviceName, const byte ledPin)
|
||||||
|
{
|
||||||
|
this->ledDisplayController = new LedDisplayController(ledPin);
|
||||||
|
|
||||||
|
this->ledDisplayController->setTexts(LedDisplayController::sets_t{
|
||||||
|
{// TEXT , SHOWTIME, COLOR, ALIGNMENT, SCROLL, SCROLLNR, ACTIVE
|
||||||
|
{"itsblue", 5000, ledDisplayController->Color(0, 0, 255), LedDisplayController::TEXTCENTER, false, 1, true},
|
||||||
|
{"", 0, ledDisplayController->Color(0, 0, 255), LedDisplayController::TEXTCENTER, false, 4, false}
|
||||||
|
},
|
||||||
|
"OK"});
|
||||||
|
|
||||||
|
this->bleServer = new BluetoothLeUartServer(deviceName, "6e400001-b5a3-f393-e0a9-e50e24dcca9e", "6e400002-b5a3-f393-e0a9-e50e24dcca9e", "6e400003-b5a3-f393-e0a9-e50e24dcca9e");
|
||||||
|
this->bleServer->setCallbacks(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OmobiLedDisplay::onDeviceConnectedChanged(bool deviceConnected)
|
||||||
|
{
|
||||||
|
if (deviceConnected)
|
||||||
|
Serial.println("Device connected");
|
||||||
|
}
|
||||||
|
|
||||||
|
void OmobiLedDisplay::onDataReceived(String data)
|
||||||
|
{
|
||||||
|
if (data.startsWith("GET_TEXTS"))
|
||||||
|
{
|
||||||
|
const size_t capacity = JSON_ARRAY_SIZE(LedDisplayController::text_nr_sets) + LedDisplayController::text_nr_sets * (JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(8));
|
||||||
|
DynamicJsonDocument doc(capacity);
|
||||||
|
|
||||||
|
for (int i = 0; i < LedDisplayController::text_nr_sets; i++)
|
||||||
|
{
|
||||||
|
LedDisplayController::text_set_t textSet = this->ledDisplayController->getTexts().sets[i];
|
||||||
|
JsonObject doc_0 = doc.createNestedObject();
|
||||||
|
doc_0["active"] = textSet.active;
|
||||||
|
doc_0["alignment"] = textSet.align;
|
||||||
|
|
||||||
|
JsonObject doc_0_color = doc_0.createNestedObject("color");
|
||||||
|
doc_0_color["r"] = 0;
|
||||||
|
doc_0_color["g"] = 0;
|
||||||
|
doc_0_color["b"] = 0;
|
||||||
|
|
||||||
|
doc_0["runtime"] = textSet.time_ms;
|
||||||
|
doc_0["scroll"] = textSet.text_scroll;
|
||||||
|
doc_0["scrollCount"] = textSet.text_scroll_pass;
|
||||||
|
doc_0["scrollSpeed"] = 5;
|
||||||
|
doc_0["text"] = textSet.text;
|
||||||
|
}
|
||||||
|
|
||||||
|
String json;
|
||||||
|
serializeJson(doc, json);
|
||||||
|
this->bleServer->sendData("GET_TEXTS:" + json);
|
||||||
|
}
|
||||||
|
else if (data.startsWith("SET_TEXTS:"))
|
||||||
|
{
|
||||||
|
const size_t capacity = JSON_ARRAY_SIZE(LedDisplayController::text_nr_sets) + LedDisplayController::text_nr_sets * JSON_OBJECT_SIZE(8) + 270;
|
||||||
|
DynamicJsonDocument doc(capacity);
|
||||||
|
|
||||||
|
data.replace("SET_TEXTS:", "");
|
||||||
|
Serial.println("Got new SET TEXT:" + data);
|
||||||
|
// TODO: handle Error!
|
||||||
|
DeserializationError err = deserializeJson(doc, data);
|
||||||
|
|
||||||
|
Serial.println("deserialization result: " + String(err.c_str()));
|
||||||
|
|
||||||
|
if(err != DeserializationError::Ok)
|
||||||
|
return;
|
||||||
|
|
||||||
|
JsonArray textsArray = doc.as<JsonArray>();
|
||||||
|
|
||||||
|
LedDisplayController::sets_t textSets;
|
||||||
|
strncpy(textSets.valid, "OK", sizeof(textSets.valid));
|
||||||
|
|
||||||
|
for (int i = 0; i < textsArray.size(); i++)
|
||||||
|
{
|
||||||
|
Serial.println(" | Processing index " + String(i));
|
||||||
|
|
||||||
|
if (i >= LedDisplayController::text_nr_sets)
|
||||||
|
break;
|
||||||
|
|
||||||
|
JsonObject textObject = textsArray[i].as<JsonObject>();
|
||||||
|
|
||||||
|
if(
|
||||||
|
!textObject.containsKey("text") ||
|
||||||
|
!textObject.containsKey("runtime") ||
|
||||||
|
//!textObject.containsKey("color") ||
|
||||||
|
!textObject.containsKey("scroll") ||
|
||||||
|
!textObject.containsKey("scrollCount") ||
|
||||||
|
!textObject.containsKey("active") ||
|
||||||
|
!textObject.containsKey("alignment")
|
||||||
|
)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
LedDisplayController::text_set_t textSet;
|
||||||
|
|
||||||
|
const char* text = textObject["text"];
|
||||||
|
strncpy(textSet.text, text, sizeof(textSet.text));
|
||||||
|
|
||||||
|
uint16_t runtime = textObject["runtime"];
|
||||||
|
textSet.time_ms = runtime;
|
||||||
|
|
||||||
|
//JsonObject colorObject = textObject["color"].as<JsonObject>();
|
||||||
|
//uint16_t color = this->ledDisplayController->Color(colorObject["r"], colorObject["color"]["g"], colorObject["color"]["b"]);
|
||||||
|
//textSet.color = color;
|
||||||
|
|
||||||
|
bool scroll = textObject["scroll"];
|
||||||
|
textSet.text_scroll = scroll;
|
||||||
|
|
||||||
|
uint16_t scrollCount = textObject["scrollCount"];
|
||||||
|
textSet.text_scroll_pass = scrollCount;
|
||||||
|
|
||||||
|
bool active = textObject["active"];
|
||||||
|
textSet.active = active;
|
||||||
|
|
||||||
|
int alignment = textObject["alignment"];
|
||||||
|
textSet.align = LedDisplayController::text_align_t(alignment);
|
||||||
|
|
||||||
|
Serial.println(
|
||||||
|
" | Got set: text: " + String(textSet.text) +
|
||||||
|
" time: " + String(textSet.time_ms) +
|
||||||
|
" color: " + String(textSet.color) +
|
||||||
|
" scroll: " + String(textSet.text_scroll) +
|
||||||
|
" scrollCount: " + String(textSet.text_scroll_pass) +
|
||||||
|
" active: " + String(textSet.active)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
textSets.sets[i] = textSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->ledDisplayController->setTexts(textSets);
|
||||||
|
|
||||||
|
this->bleServer->sendData("SET_TEXTS:OK");
|
||||||
|
}
|
||||||
|
else if (data.startsWith("GET_BRIGHTNESS"))
|
||||||
|
this->bleServer->sendData("GET_BRIGHTNESS:5");
|
||||||
|
else if (data.startsWith("SET_BRIGHTNESS:"))
|
||||||
|
this->bleServer->sendData("SET_BRIGHTNESS:OK");
|
||||||
|
}
|
33
vscode/OmobiLEDdisplayBluetooth/src/main.cpp
Normal file
33
vscode/OmobiLEDdisplayBluetooth/src/main.cpp
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
//#include "BluetoothLeUartServer.h"
|
||||||
|
#include "OmobiLedDisplay.h"
|
||||||
|
|
||||||
|
#define PIN 4
|
||||||
|
|
||||||
|
OmobiLedDisplay* display;
|
||||||
|
|
||||||
|
class MyCallbacks : public BluetoothLeUartServerCallbacks {
|
||||||
|
virtual void onDeviceConnectedChanged(bool deviceConnected) {
|
||||||
|
Serial.println("Device connected changed");
|
||||||
|
};
|
||||||
|
virtual void onDataReceived(String data) {
|
||||||
|
Serial.println("Got some data: " + data);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
//BluetoothLeUartServer* server;
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.printf("Los\n");
|
||||||
|
|
||||||
|
display = new OmobiLedDisplay("OmobiLedDisplay1", PIN);
|
||||||
|
//server = new BluetoothLeUartServer("OmobiLedDisplay1", "6e400001-b5a3-f393-e0a9-e50e24dcca9e", "6e400002-b5a3-f393-e0a9-e50e24dcca9e", "6e400003-b5a3-f393-e0a9-e50e24dcca9e");
|
||||||
|
//server->setCallbacks(new MyCallbacks());
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
delay(1000);
|
||||||
|
}
|
11
vscode/OmobiLEDdisplayBluetooth/test/README
Normal file
11
vscode/OmobiLEDdisplayBluetooth/test/README
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
|
||||||
|
This directory is intended for PIO Unit Testing and project tests.
|
||||||
|
|
||||||
|
Unit Testing is a software testing method by which individual units of
|
||||||
|
source code, sets of one or more MCU program modules together with associated
|
||||||
|
control data, usage procedures, and operating procedures, are tested to
|
||||||
|
determine whether they are fit for use. Unit testing finds problems early
|
||||||
|
in the development cycle.
|
||||||
|
|
||||||
|
More information about PIO Unit Testing:
|
||||||
|
- https://docs.platformio.org/page/plus/unit-testing.html
|
Loading…
Reference in a new issue