mirror of
https://github.com/sunwoods/EPaperLoader-esp32.git
synced 2026-08-13 14:38:18 -07:00
inital upload
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
.pio
|
||||||
|
.vscode/.browse.c_cpp.db*
|
||||||
|
.vscode/c_cpp_properties.json
|
||||||
|
.vscode/launch.json
|
||||||
|
.vscode/ipch
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
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 convention is to give header files names that end with `.h'.
|
||||||
|
|
||||||
|
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
|
||||||
+46
@@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
This directory is intended for project specific (private) libraries.
|
||||||
|
PlatformIO will compile them to static libraries and link into the executable file.
|
||||||
|
|
||||||
|
The source code of each library should be placed in a separate directory
|
||||||
|
("lib/your_library_name/[Code]").
|
||||||
|
|
||||||
|
For example, see the structure of the following example libraries `Foo` and `Bar`:
|
||||||
|
|
||||||
|
|--lib
|
||||||
|
| |
|
||||||
|
| |--Bar
|
||||||
|
| | |--docs
|
||||||
|
| | |--examples
|
||||||
|
| | |--src
|
||||||
|
| | |- Bar.c
|
||||||
|
| | |- Bar.h
|
||||||
|
| | |- library.json (optional. for 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
|
||||||
|
|
||||||
|
Example contents of `src/main.c` using Foo and Bar:
|
||||||
|
```
|
||||||
|
#include <Foo.h>
|
||||||
|
#include <Bar.h>
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
The PlatformIO Library Dependency Finder will find automatically dependent
|
||||||
|
libraries by scanning project source files.
|
||||||
|
|
||||||
|
More information about PlatformIO Library Dependency Finder
|
||||||
|
- https://docs.platformio.org/page/librarymanager/ldf.html
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
; 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-s3-devkitc-1]
|
||||||
|
platform = espressif32
|
||||||
|
board = esp32-s3-devkitc-1
|
||||||
|
framework = arduino
|
||||||
|
monitor_speed = 115200
|
||||||
|
board_build.arduino.partitions = app3M_fat9M_16MB.csv
|
||||||
|
board_build.arduino.memory_type = qio_opi
|
||||||
|
build_flags = -DBOARD_HAS_PSRAM
|
||||||
|
board_upload.flash_size = 16MB
|
||||||
|
lib_deps = bblanchon/ArduinoJson@^7.3.1
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#include "buff_wifi.h"
|
||||||
|
#include "buff_bt.h"
|
||||||
|
#include "epd_driver/epd_conf.h"
|
||||||
|
|
||||||
|
|
||||||
|
JsonDocument document;
|
||||||
|
|
||||||
|
int Buff__bufInd;
|
||||||
|
char* Buff__bufArr = NULL;
|
||||||
|
|
||||||
|
// init buffer
|
||||||
|
void Buff__init() {
|
||||||
|
Buff__bufArr = (char*)malloc(Buff__SIZE);
|
||||||
|
if (Buff__bufArr == NULL) {
|
||||||
|
Serial.println("malloc for Buff__bufArr failed. exit!");
|
||||||
|
exit(-2);
|
||||||
|
}
|
||||||
|
memset(Buff__bufArr, 0, Buff__SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reads a word from the buffer at specified position ------------------------*/
|
||||||
|
int Buff__getByte(int index)
|
||||||
|
{
|
||||||
|
if (loadMode == LOAD_MODE_BT) {
|
||||||
|
return myBUFFBt.Buff__getByte(index);
|
||||||
|
} else if (loadMode == LOAD_MODE_WIFI) {
|
||||||
|
return myBUFFWifi.Buff__getByte(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reads a byte from the buffer at specified position ------------------------*/
|
||||||
|
int Buff__getWord(int index)
|
||||||
|
{
|
||||||
|
if (loadMode == LOAD_MODE_BT) {
|
||||||
|
return myBUFFBt.Buff__getWord(index);
|
||||||
|
} else if (loadMode == LOAD_MODE_WIFI) {
|
||||||
|
return myBUFFWifi.Buff__getWord(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reads a byte from the buffer at specified position ------------------------*/
|
||||||
|
int Buff__getN3(int index)
|
||||||
|
{
|
||||||
|
if (loadMode == LOAD_MODE_BT) {
|
||||||
|
return myBUFFBt.Buff__getN3(index);
|
||||||
|
} else if (loadMode == LOAD_MODE_WIFI) {
|
||||||
|
return myBUFFWifi.Buff__getN3(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Checks if the buffer's data ends with specified string --------------------*/
|
||||||
|
int Buff__signature(int index, char*str)
|
||||||
|
{
|
||||||
|
if (loadMode == LOAD_MODE_BT) {
|
||||||
|
return myBUFFBt.Buff__signature(index, str);
|
||||||
|
} else if (loadMode == LOAD_MODE_WIFI) {
|
||||||
|
return myBUFFWifi.Buff__signature(index, str);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file buff.h
|
||||||
|
* @author Waveshare Team
|
||||||
|
* @version V1.0.0
|
||||||
|
* @date 23-January-2018
|
||||||
|
* @brief ESP8266 WiFi server.
|
||||||
|
* This file provides firmware functions:
|
||||||
|
* + Sending web page of the tool to a client's browser
|
||||||
|
* + Uploading images from client part by part
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
/* Size, current position index and byte array of the buffer -----------------*/
|
||||||
|
#define Buff__SIZE 800*480 // may need increase
|
||||||
|
|
||||||
|
#define JSON_BUFF_SIZE 256
|
||||||
|
|
||||||
|
extern JsonDocument document;
|
||||||
|
|
||||||
|
extern int Buff__bufInd;
|
||||||
|
extern char* Buff__bufArr;
|
||||||
|
|
||||||
|
void Buff__init();
|
||||||
|
|
||||||
|
/* Reads a word from the buffer at specified position ------------------------*/
|
||||||
|
int Buff__getByte(int index);
|
||||||
|
/* Reads a byte from the buffer at specified position ------------------------*/
|
||||||
|
int Buff__getWord(int index);
|
||||||
|
|
||||||
|
/* Reads a byte from the buffer at specified position ------------------------*/
|
||||||
|
int Buff__getN3(int index);
|
||||||
|
|
||||||
|
/* Checks if the buffer's data ends with specified string --------------------*/
|
||||||
|
int Buff__signature(int index, char*str);
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
#include "buff_bt.h"
|
||||||
|
|
||||||
|
BUFFBt myBUFFBt;
|
||||||
|
|
||||||
|
/* Reads a word from the buffer at specified position ------------------------*/
|
||||||
|
int BUFFBt::Buff__getByte(int index)
|
||||||
|
{
|
||||||
|
return Buff__bufArr[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reads a byte from the buffer at specified position ------------------------*/
|
||||||
|
int BUFFBt::Buff__getWord(int index)
|
||||||
|
{
|
||||||
|
if (index + 1 >= Buff__SIZE) return -1;
|
||||||
|
return Buff__bufArr[index] + (Buff__bufArr[index + 1] << 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reads a byte from the buffer at specified position ------------------------*/
|
||||||
|
int BUFFBt::Buff__getN3(int index)
|
||||||
|
{
|
||||||
|
return (index + 3 > Buff__SIZE) ? 0 :
|
||||||
|
(Buff__bufArr[index ] ) +
|
||||||
|
(Buff__bufArr[index + 1] << 8) +
|
||||||
|
(Buff__bufArr[index + 2] << 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Checks if the buffer's data ends with specified string --------------------*/
|
||||||
|
int BUFFBt::Buff__signature(int index, char*str)
|
||||||
|
{
|
||||||
|
// characters of the string to the end of the string
|
||||||
|
while (*str != 0)
|
||||||
|
{
|
||||||
|
// If the correspondent character in the buffer isn't equal
|
||||||
|
// to the string's character, return false
|
||||||
|
if (Buff__bufArr[index++] != *str) return false;
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise return true
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
|
||||||
|
#ifndef WIFI_BT_H_
|
||||||
|
#define WIFI_BT_H_
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "buff.h"
|
||||||
|
|
||||||
|
class BUFFBt {
|
||||||
|
public:
|
||||||
|
/* Reads a word from the buffer at specified position ------------------------*/
|
||||||
|
static int Buff__getByte(int index);
|
||||||
|
|
||||||
|
/* Reads a byte from the buffer at specified position ------------------------*/
|
||||||
|
static int Buff__getWord(int index);
|
||||||
|
|
||||||
|
/* Reads a byte from the buffer at specified position ------------------------*/
|
||||||
|
static int Buff__getN3(int index);
|
||||||
|
|
||||||
|
/* Checks if the buffer's data ends with specified string --------------------*/
|
||||||
|
static int Buff__signature(int index, char*str);
|
||||||
|
}; // class BUFFBt
|
||||||
|
|
||||||
|
extern BUFFBt myBUFFBt;
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
#include "buff_wifi.h"
|
||||||
|
|
||||||
|
BUFFWifi myBUFFWifi;
|
||||||
|
|
||||||
|
/* Reads a word from the buffer at specified position ------------------------*/
|
||||||
|
int BUFFWifi::Buff__getByte(int index)
|
||||||
|
{
|
||||||
|
// The first and second characters of the byte stored in the buffer
|
||||||
|
// are supposed to be in range ['a'; 'p'], otherwise it isn't a image data's byte
|
||||||
|
if ((Buff__bufArr[index ] < 'a') || (Buff__bufArr[index ] > 'p')) return -1;
|
||||||
|
if ((Buff__bufArr[index + 1] < 'a') || (Buff__bufArr[index + 1] > 'p')) return -1;
|
||||||
|
|
||||||
|
// The character 'a' means 0, the character 'p' means 15 consequently,
|
||||||
|
// The 1st character describes 4 low bits if the byte and the 2nd one - 4 high bits
|
||||||
|
// return ((int)Buff__bufArr[index] - 'a') + (((int)Buff__bufArr[index + 1] - 'a') << 4);
|
||||||
|
return (((int)Buff__bufArr[index] - 'a') << 4) + (((int)Buff__bufArr[index + 1] - 'a') & 0x0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reads a byte from the buffer at specified position ------------------------*/
|
||||||
|
int BUFFWifi::Buff__getWord(int index)
|
||||||
|
{
|
||||||
|
// Read low byte of the word
|
||||||
|
int a = Buff__getByte(index);
|
||||||
|
|
||||||
|
// If it is not a image data byte, then exit
|
||||||
|
if (a == -1) return -1;
|
||||||
|
|
||||||
|
// Read high byte of the word
|
||||||
|
int b = Buff__getByte(index + 2);
|
||||||
|
|
||||||
|
// If it is not a image data byte, then exit
|
||||||
|
if (b == -1) return -1;
|
||||||
|
|
||||||
|
// Return the word's value
|
||||||
|
return a + (b << 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reads a byte from the buffer at specified position ------------------------*/
|
||||||
|
int BUFFWifi::Buff__getN3(int index)
|
||||||
|
{
|
||||||
|
return (index + 3 > Buff__SIZE) ? 0 :
|
||||||
|
(Buff__bufArr[index ] ) +
|
||||||
|
(Buff__bufArr[index + 1] << 8) +
|
||||||
|
(Buff__bufArr[index + 2] << 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Checks if the buffer's data ends with specified string --------------------*/
|
||||||
|
int BUFFWifi::Buff__signature(int index, char*str)
|
||||||
|
{
|
||||||
|
index = 0; // temp add
|
||||||
|
// characters of the string to the end of the string
|
||||||
|
while (*str != 0)
|
||||||
|
{
|
||||||
|
// If the correspondent character in the buffer isn't equal
|
||||||
|
// to the string's character, return false
|
||||||
|
if (Buff__bufArr[index++] != *str) return false;
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise return true
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file buff.h
|
||||||
|
* @author Waveshare Team
|
||||||
|
* @version V1.0.0
|
||||||
|
* @date 23-January-2018
|
||||||
|
* @brief ESP8266 WiFi server.
|
||||||
|
* This file provides firmware functions:
|
||||||
|
* + Sending web page of the tool to a client's browser
|
||||||
|
* + Uploading images from client part by part
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef WIFI_BUFF_H_
|
||||||
|
#define WIFI_BUFF_H_
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "buff.h"
|
||||||
|
|
||||||
|
class BUFFWifi {
|
||||||
|
public:
|
||||||
|
/* Reads a word from the buffer at specified position ------------------------*/
|
||||||
|
static int Buff__getByte(int index);
|
||||||
|
|
||||||
|
/* Reads a byte from the buffer at specified position ------------------------*/
|
||||||
|
static int Buff__getWord(int index);
|
||||||
|
|
||||||
|
/* Reads a byte from the buffer at specified position ------------------------*/
|
||||||
|
static int Buff__getN3(int index);
|
||||||
|
|
||||||
|
/* Checks if the buffer's data ends with specified string --------------------*/
|
||||||
|
static int Buff__signature(int index, char*str);
|
||||||
|
}; // class BUFFWifi
|
||||||
|
|
||||||
|
extern BUFFWifi myBUFFWifi;
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
|
#include "buff/buff.h"
|
||||||
|
#include "epd_driver/epd.h"
|
||||||
|
|
||||||
|
#include "config/wifi_config.h"
|
||||||
|
#include "config/ble_config.h"
|
||||||
|
|
||||||
|
|
||||||
|
BLEServer *pServer = NULL;
|
||||||
|
BLECharacteristic *pReadCharacteristic;
|
||||||
|
|
||||||
|
esp_bd_addr_t connectedAddress; // destination device address
|
||||||
|
|
||||||
|
char json_buff[JSON_BUFF_SIZE];
|
||||||
|
|
||||||
|
class MyServerCallbacks: public BLEServerCallbacks {
|
||||||
|
void onConnect(BLEServer* pServer, esp_ble_gatts_cb_param_t* param) {
|
||||||
|
Serial.println("Try connecting..");
|
||||||
|
|
||||||
|
// update connection params
|
||||||
|
memcpy(connectedAddress, param->connect.remote_bda, sizeof(esp_bd_addr_t));
|
||||||
|
|
||||||
|
Serial.printf("connId:%d, mtu=%d\n", param->mtu.conn_id, param->mtu.mtu);
|
||||||
|
|
||||||
|
pServer->updateConnParams(connectedAddress,6,6,0,500);
|
||||||
|
};
|
||||||
|
|
||||||
|
void onDisconnect(BLEServer* pServer) {
|
||||||
|
Serial.println("Disconnected..");
|
||||||
|
pServer->getAdvertising()->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
// // Maximum Transmission Unit allowed in GATT
|
||||||
|
// #define ESP_GATT_MAX_MTU_SIZE 517 /* relate to GATT_MAX_MTU_SIZE in stack/gatt_api.h */
|
||||||
|
void onMtuChanged(BLEServer* pServer, esp_ble_gatts_cb_param_t* param) {
|
||||||
|
Serial.printf(">>> onMtuChanged: connId=%d, mtu=%d\n", param->mtu.conn_id, param->mtu.mtu);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class MsgCallbacks: public BLECharacteristicCallbacks {
|
||||||
|
void onWrite(BLECharacteristic *pCharacteristic) {
|
||||||
|
std::string rxValue = pCharacteristic->getValue();
|
||||||
|
|
||||||
|
if (rxValue.length() > 0) {
|
||||||
|
Serial.println("*********");
|
||||||
|
|
||||||
|
// receive data
|
||||||
|
Buff__bufInd = 0;
|
||||||
|
Serial.print("Received Value: ");
|
||||||
|
for (int i = 0; i < rxValue.length(); i++){
|
||||||
|
Buff__bufArr[Buff__bufInd++] = rxValue[i];
|
||||||
|
Serial.print(rxValue[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println();
|
||||||
|
Serial.println("*********");
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class DataCallbacks: public BLECharacteristicCallbacks {
|
||||||
|
void onWrite(BLECharacteristic *pCharacteristic) {
|
||||||
|
uint8_t* rxValue = pCharacteristic->getData();
|
||||||
|
size_t rxLength = pCharacteristic->getLength();
|
||||||
|
|
||||||
|
if (rxLength > 0) {
|
||||||
|
|
||||||
|
// receive data
|
||||||
|
Buff__bufInd = 0;
|
||||||
|
memset(Buff__bufArr, 0, Buff__SIZE);
|
||||||
|
|
||||||
|
for (int i = 0; i < rxLength; i++){
|
||||||
|
Buff__bufArr[Buff__bufInd++] = (byte)rxValue[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
Srvr__rcvProc();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void my_ble_init() {
|
||||||
|
Serial.println("1- Download and install an BLE scanner app in your phone");
|
||||||
|
Serial.println("2- Scan for BLE devices in the app");
|
||||||
|
Serial.println("3- Connect to MyESP32");
|
||||||
|
Serial.println("4- Go to CUSTOM CHARACTERISTIC in CUSTOM SERVICE and write something");
|
||||||
|
Serial.println("5- See the magic =)");
|
||||||
|
|
||||||
|
// init ble device
|
||||||
|
BLEDevice::init("MyESP32");
|
||||||
|
|
||||||
|
// create server for ble device
|
||||||
|
pServer = BLEDevice::createServer();
|
||||||
|
pServer->setCallbacks(new MyServerCallbacks());
|
||||||
|
|
||||||
|
// create service based on SERVICE_UUID
|
||||||
|
BLEService *pService = pServer->createService(SERVICE_UUID);
|
||||||
|
pReadCharacteristic = pService->createCharacteristic(
|
||||||
|
CHARACTERISTIC_UUID_READ,
|
||||||
|
BLECharacteristic::PROPERTY_READ
|
||||||
|
);
|
||||||
|
pReadCharacteristic->addDescriptor(new BLE2902());
|
||||||
|
|
||||||
|
|
||||||
|
document["ip_address"] = get_local_ip();
|
||||||
|
document["host_name"] = get_host_name();
|
||||||
|
|
||||||
|
// serialize data and prepare to send
|
||||||
|
serializeJson(document, json_buff);
|
||||||
|
Serial.println(json_buff);
|
||||||
|
|
||||||
|
pReadCharacteristic->setValue(json_buff);
|
||||||
|
|
||||||
|
|
||||||
|
BLECharacteristic * pWriteCharacteristic = pService->createCharacteristic(
|
||||||
|
CHARACTERISTIC_UUID_WRITE,
|
||||||
|
BLECharacteristic::PROPERTY_WRITE
|
||||||
|
);
|
||||||
|
pWriteCharacteristic->setCallbacks(new MsgCallbacks());
|
||||||
|
|
||||||
|
BLECharacteristic * pWriteDataCharacteristic = pService->createCharacteristic(
|
||||||
|
CHARACTERISTIC_UUID_WRITE_DATA,
|
||||||
|
BLECharacteristic::PROPERTY_WRITE
|
||||||
|
);
|
||||||
|
pWriteDataCharacteristic->setCallbacks(new DataCallbacks());
|
||||||
|
|
||||||
|
// start service
|
||||||
|
pService->start();
|
||||||
|
|
||||||
|
pServer->getAdvertising()->start();
|
||||||
|
|
||||||
|
Serial.println("Waiting a client connection to notify...");
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
#ifndef __BLE_CONFIG_H
|
||||||
|
#define __BLE_CONFIG_H
|
||||||
|
|
||||||
|
#include <BLEDevice.h>
|
||||||
|
#include <BLEServer.h>
|
||||||
|
#include <BLEUtils.h>
|
||||||
|
#include <BLE2902.h>
|
||||||
|
|
||||||
|
// define service UUID
|
||||||
|
#define SERVICE_UUID "6E400001-B5A3-F393-E0A9-E50E24DCCA9E"
|
||||||
|
// notify
|
||||||
|
#define CHARACTERISTIC_UUID_NOTIFY "6E400002-B5A3-F393-E0A9-E50E24DCCA9E"
|
||||||
|
// read
|
||||||
|
#define CHARACTERISTIC_UUID_READ "6E400003-B5A3-F393-E0A9-E50E24DCCA9E"
|
||||||
|
// write_msg
|
||||||
|
#define CHARACTERISTIC_UUID_WRITE "6E400004-B5A3-F393-E0A9-E50E24DCCA9E"
|
||||||
|
// write_data
|
||||||
|
#define CHARACTERISTIC_UUID_WRITE_DATA "6E400005-B5A3-F393-E0A9-E50E24DCCA9E"
|
||||||
|
|
||||||
|
void my_ble_init();
|
||||||
|
|
||||||
|
|
||||||
|
extern esp_bd_addr_t connectedAddress; // destination device addresss
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <WebServer.h>
|
||||||
|
|
||||||
|
#include "epd_driver/epd.h"
|
||||||
|
//web
|
||||||
|
#include "web/Web_Scripts.h" // JavaScript code
|
||||||
|
#include "web/Web_CSS.h" // Cascading Style Sheets
|
||||||
|
#include "web/Web_HTML.h" // HTML page of the tool
|
||||||
|
|
||||||
|
#include "config/wifi_config.h"
|
||||||
|
|
||||||
|
/* Server and IP address ------------------------------------------------------*/
|
||||||
|
WebServer server(80);
|
||||||
|
IPAddress myIP;
|
||||||
|
|
||||||
|
void handleNotFound() {
|
||||||
|
// digitalWrite(led, 1);
|
||||||
|
String message = "File Not Found\n\n";
|
||||||
|
message += "URI: ";
|
||||||
|
message += server.uri();
|
||||||
|
message += "\nMethod: ";
|
||||||
|
message += (server.method() == HTTP_GET) ? "GET" : "POST";
|
||||||
|
message += "\nArguments: ";
|
||||||
|
message += server.args();
|
||||||
|
message += "\n";
|
||||||
|
for (uint8_t i = 0; i < server.args(); i++) {
|
||||||
|
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
|
||||||
|
}
|
||||||
|
server.send(404, "text/plain", message);
|
||||||
|
// digitalWrite(led, 0);
|
||||||
|
Serial.println(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void my_wifi_init() {
|
||||||
|
Serial.println("start to config network.");
|
||||||
|
Serial.printf("Connecting to %s\n", WIFI_SSID);
|
||||||
|
|
||||||
|
WiFi.mode(WIFI_MODE_STA);
|
||||||
|
|
||||||
|
// Applying SSID and password
|
||||||
|
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
||||||
|
|
||||||
|
// Waiting the connection to a router
|
||||||
|
int try_count = 0;
|
||||||
|
int wait = WiFi.waitForConnectResult(10000);
|
||||||
|
Serial.println(wait);
|
||||||
|
if (wait != WL_CONNECTED) {
|
||||||
|
Serial.println("wifi connected failed.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
myIP = WiFi.localIP();
|
||||||
|
Serial.print("Local IP: ");
|
||||||
|
Serial.println(myIP);
|
||||||
|
|
||||||
|
// Connection is complete
|
||||||
|
Serial.println("");
|
||||||
|
|
||||||
|
Serial.println("WiFi connected");
|
||||||
|
server.on("/", Web_SendHTML);
|
||||||
|
server.on("/index.css", Web_SendCSS);
|
||||||
|
server.on("/Web_SendJS_A.js", Web_SendJS_A);
|
||||||
|
|
||||||
|
server.on("/EPD", Srvr__postProc);
|
||||||
|
server.on("/LOADA", Srvr__postProc);
|
||||||
|
server.on("/LOADB", Srvr__postProc);
|
||||||
|
server.on("/SHOW", Srvr__postProc);
|
||||||
|
|
||||||
|
server.onNotFound(handleNotFound);
|
||||||
|
|
||||||
|
// Start the server
|
||||||
|
server.begin();
|
||||||
|
Serial.println("Server started");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
String get_local_ip() {
|
||||||
|
return WiFi.localIP().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
String get_host_name() {
|
||||||
|
return WiFi.getHostname();
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#ifndef __WIFI_CONFIG_H
|
||||||
|
#define __WIFI_CONFIG_H
|
||||||
|
|
||||||
|
#define WIFI_SSID "WIFI_SSID"
|
||||||
|
#define WIFI_PASSWORD "WIFI_PASSWORD"
|
||||||
|
|
||||||
|
void my_wifi_init();
|
||||||
|
|
||||||
|
String get_local_ip();
|
||||||
|
String get_host_name();
|
||||||
|
|
||||||
|
#endif
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,126 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @file epd.h
|
||||||
|
* @author Waveshare Team
|
||||||
|
* @version V1.0.0
|
||||||
|
* @date 23-January-2018
|
||||||
|
* @brief This file provides e-Paper driver functions
|
||||||
|
* void EPD_SendCommand(byte command);
|
||||||
|
* void EPD_SendData(byte data);
|
||||||
|
* void EPD_WaitUntilIdle();
|
||||||
|
* void EPD_Send_1(byte c, byte v1);
|
||||||
|
* void EPD_Send_2(byte c, byte v1, byte v2);
|
||||||
|
* void EPD_Send_3(byte c, byte v1, byte v2, byte v3);
|
||||||
|
* void EPD_Send_4(byte c, byte v1, byte v2, byte v3, byte v4);
|
||||||
|
* void EPD_Send_5(byte c, byte v1, byte v2, byte v3, byte v4, byte v5);
|
||||||
|
* void EPD_Reset();
|
||||||
|
* void EPD_dispInit();
|
||||||
|
*
|
||||||
|
* varualbes:
|
||||||
|
* EPD_dispLoad; - pointer on current loading function
|
||||||
|
* EPD_dispIndex; - index of current e-Paper
|
||||||
|
* EPD_dispInfo EPD_dispMass[]; - array of e-Paper properties
|
||||||
|
*
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
#ifndef EPD_H_
|
||||||
|
#define EPD_H_
|
||||||
|
// #include "epd_wifi.h"
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
void EPD_SPISetCfg(
|
||||||
|
int din,
|
||||||
|
int sck,
|
||||||
|
int cs,
|
||||||
|
int dc,
|
||||||
|
int rst,
|
||||||
|
int busy
|
||||||
|
);
|
||||||
|
void EPD_initSPI();
|
||||||
|
|
||||||
|
/* The procedure of sending a byte to e-Paper by SPI -------------------------*/
|
||||||
|
void EpdSpiTransferCallback(byte data);
|
||||||
|
|
||||||
|
/* Sending a byte as a command -----------------------------------------------*/
|
||||||
|
void EPD_SendCommand(byte command);
|
||||||
|
|
||||||
|
/* Sending a byte as a data --------------------------------------------------*/
|
||||||
|
void EPD_SendData(byte data);
|
||||||
|
|
||||||
|
/* Waiting the e-Paper is ready for further instructions ---------------------*/
|
||||||
|
void EPD_WaitUntilIdle();
|
||||||
|
|
||||||
|
/* Waiting the e-Paper is ready for further instructions ---------------------*/
|
||||||
|
void EPD_WaitUntilIdle_high();
|
||||||
|
|
||||||
|
/* Send a one-argument command -----------------------------------------------*/
|
||||||
|
void EPD_Send_1(byte c, byte v1);
|
||||||
|
|
||||||
|
/* Send a two-arguments command ----------------------------------------------*/
|
||||||
|
void EPD_Send_2(byte c, byte v1, byte v2);
|
||||||
|
|
||||||
|
/* Send a three-arguments command --------------------------------------------*/
|
||||||
|
void EPD_Send_3(byte c, byte v1, byte v2, byte v3);
|
||||||
|
|
||||||
|
/* Send a four-arguments command ---------------------------------------------*/
|
||||||
|
void EPD_Send_4(byte c, byte v1, byte v2, byte v3, byte v4);
|
||||||
|
|
||||||
|
/* Send a five-arguments command ---------------------------------------------*/
|
||||||
|
void EPD_Send_5(byte c, byte v1, byte v2, byte v3, byte v4, byte v5);
|
||||||
|
|
||||||
|
/* Writting lut-data into the e-Paper ----------------------------------------*/
|
||||||
|
void EPD_lut(byte c, byte l, byte*p);
|
||||||
|
|
||||||
|
/* Writting lut-data of the black-white channel ------------------------------*/
|
||||||
|
void EPD_SetLutBw(byte*c20, byte*c21, byte*c22, byte*c23, byte*c24);
|
||||||
|
|
||||||
|
/* Writting lut-data of the red channel --------------------------------------*/
|
||||||
|
void EPD_SetLutRed(byte*c25, byte*c26, byte*c27);
|
||||||
|
|
||||||
|
/* This function is used to 'wake up" the e-Paper from the deep sleep mode ---*/
|
||||||
|
void EPD_Reset();
|
||||||
|
|
||||||
|
/* Image data loading function for a-type e-Paper ----------------------------*/
|
||||||
|
void EPD_loadA();
|
||||||
|
void EPD_loadAFilp();
|
||||||
|
|
||||||
|
/* Image data loading function for b-type e-Paper ----------------------------*/
|
||||||
|
void EPD_loadB();
|
||||||
|
|
||||||
|
/* Image data loading function for 2.13 e-Paper ------------------------------*/
|
||||||
|
void EPD_loadC();
|
||||||
|
|
||||||
|
/* Image data loading function for 7.5 e-Paper -------------------------------*/
|
||||||
|
void EPD_loadD();
|
||||||
|
/* Image data loading function for 7.5b e-Paper ------------------------------*/
|
||||||
|
void EPD_loadE();
|
||||||
|
|
||||||
|
/* Image data loading function for 5.83b e-Paper -----------------------------*/
|
||||||
|
void EPD_loadF();
|
||||||
|
/* Image data loading function for 5.65f e-Paper -----------------------------*/
|
||||||
|
void EPD_loadG();
|
||||||
|
|
||||||
|
/* Show image and turn to deep sleep mode (a-type, 4.2 and 2.7 e-Paper) ------*/
|
||||||
|
void EPD_showA();
|
||||||
|
|
||||||
|
/* Show image and turn to deep sleep mode (b-type, e-Paper) ------------------*/
|
||||||
|
void EPD_showB();
|
||||||
|
|
||||||
|
/* Show image and turn to deep sleep mode (7.5 and 7.5b e-Paper) -------------*/
|
||||||
|
void EPD_showC();
|
||||||
|
|
||||||
|
/* Show image and turn to deep sleep mode (2.13 e-Paper) ---------------------*/
|
||||||
|
void EPD_showD();
|
||||||
|
|
||||||
|
/* Initialization of an e-Paper ----------------------------------------------*/
|
||||||
|
void EPD_dispInit();
|
||||||
|
|
||||||
|
bool Srvr__loop();
|
||||||
|
bool Srvr__init();
|
||||||
|
|
||||||
|
void Srvr__rcvProc();
|
||||||
|
void Srvr__postProc();
|
||||||
|
|
||||||
|
void reboot_device();
|
||||||
|
|
||||||
|
#endif /* EPD_H_ */
|
||||||
@@ -0,0 +1,346 @@
|
|||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/queue.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
#include "esp_task_wdt.h"
|
||||||
|
|
||||||
|
#include "buff/buff.h"
|
||||||
|
#include "epd_conf.h"
|
||||||
|
#include "epd.h"
|
||||||
|
#include "config/ble_config.h"
|
||||||
|
#include "epd_bt.h"
|
||||||
|
|
||||||
|
EPDBt myEPDBt;
|
||||||
|
QueueHandle_t btQueue;
|
||||||
|
TaskHandle_t btTask;
|
||||||
|
|
||||||
|
bt_data_t btInBuf;
|
||||||
|
bt_data_t btOutBuf;
|
||||||
|
|
||||||
|
/* Image data loading function for a-type e-Paper ----------------------------*/
|
||||||
|
void EPDBt::EPD_loadA()
|
||||||
|
{
|
||||||
|
if (is_compress) {
|
||||||
|
EPD_loadCompressA(false);
|
||||||
|
} else {
|
||||||
|
EPD_loadUncompressA(false);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EPDBt::EPD_loadAFilp()
|
||||||
|
{
|
||||||
|
if (is_compress) {
|
||||||
|
EPD_loadCompressA(true);
|
||||||
|
} else {
|
||||||
|
EPD_loadUncompressA(true);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Image data loading function for 5.65f e-Paper -----------------------------*/
|
||||||
|
void EPDBt::EPD_loadG()
|
||||||
|
{
|
||||||
|
if (is_compress) {
|
||||||
|
EPD_loadCompressG(false);
|
||||||
|
} else {
|
||||||
|
EPD_loadUncompressG(false);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void EPDBt::msgProc() {
|
||||||
|
|
||||||
|
char *pBuf = btOutBuf.Buff__bufArr;
|
||||||
|
int data_len = btOutBuf.data_len;
|
||||||
|
|
||||||
|
int width = 0;
|
||||||
|
int height = 0;
|
||||||
|
|
||||||
|
// Initialization
|
||||||
|
if (pBuf[0] == 'I' && data_len == 13)
|
||||||
|
{
|
||||||
|
// config load mode
|
||||||
|
loadMode = LOAD_MODE_BT;
|
||||||
|
|
||||||
|
// Getting of e-Paper's type
|
||||||
|
// 1 -> index
|
||||||
|
EPD_dispIndex = pBuf[1];
|
||||||
|
|
||||||
|
// 2 -> is_compress
|
||||||
|
if (pBuf[2] != 0) {
|
||||||
|
is_compress = true;
|
||||||
|
} else {
|
||||||
|
is_compress = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.printf("is_compress: %d\n", is_compress);
|
||||||
|
// Print log message: initialization of e-Paper (e-Paper's type)
|
||||||
|
Serial.printf("<<<EPD %d, %s\n", EPD_dispIndex, EPD_dispMass[EPD_dispIndex].title);
|
||||||
|
|
||||||
|
// 3~8 -> spi pin
|
||||||
|
if (data_len > 3) {
|
||||||
|
EPD_SPISetCfg(pBuf[3], pBuf[4], pBuf[5], pBuf[6], pBuf[7], pBuf[8]);
|
||||||
|
width = (pBuf[9] << 8) + pBuf[10];
|
||||||
|
height = (pBuf[11] << 8) + pBuf[12];
|
||||||
|
Serial.printf("width=%d, height=%d\n", width, height);
|
||||||
|
}
|
||||||
|
EPD_initSPI();
|
||||||
|
|
||||||
|
// alloc image buffer
|
||||||
|
if (rcv_image_data == NULL) {
|
||||||
|
rcv_image_data = (uint8_t*)malloc(width*height);
|
||||||
|
image_data = (uint8_t*)malloc(width*height*2);
|
||||||
|
if (rcv_image_data == NULL || image_data == NULL) {
|
||||||
|
Serial.println("malloc failed.");
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
Serial.printf("rcv_image_data=%p, image_data=%p\n", rcv_image_data, image_data);
|
||||||
|
}
|
||||||
|
rcv_image_data_size = 0;
|
||||||
|
image_data_size = 0;
|
||||||
|
|
||||||
|
esp_gap_conn_params_t connParams;
|
||||||
|
esp_ble_conn_update_params_t updateParams;
|
||||||
|
memcpy(updateParams.bda, connectedAddress, sizeof(esp_bd_addr_t));
|
||||||
|
updateParams.min_int = 6;
|
||||||
|
updateParams.max_int = 6;
|
||||||
|
updateParams.latency = 0;
|
||||||
|
updateParams.timeout = 500;
|
||||||
|
esp_ble_gap_update_conn_params(&updateParams);
|
||||||
|
|
||||||
|
esp_ble_get_current_conn_params(connectedAddress, &connParams);
|
||||||
|
Serial.printf("interval=%d, latency=%d, timeout=%d\n", connParams.interval, connParams.latency, connParams.timeout);
|
||||||
|
|
||||||
|
// Initialization
|
||||||
|
EPD_dispInit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loading of pixels' data
|
||||||
|
else if (pBuf[0] == 'L' && data_len == 1)
|
||||||
|
{
|
||||||
|
// Print log message: image loading
|
||||||
|
Serial.print("<<<LOAD");
|
||||||
|
load_stage = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize next channel
|
||||||
|
else if (pBuf[0] == 'N' && data_len == 1)
|
||||||
|
{
|
||||||
|
// Print log message: next data channel
|
||||||
|
Serial.print("<<<NEXT");
|
||||||
|
|
||||||
|
// load first batch data
|
||||||
|
Serial.printf("rcv_image_data_size=%d\n", rcv_image_data_size);
|
||||||
|
if (is_compress) {
|
||||||
|
decompress_image_data();
|
||||||
|
}
|
||||||
|
EPD_dispLoad();
|
||||||
|
load_stage = false;
|
||||||
|
next_stage = true;
|
||||||
|
rcv_image_data_size = 0;
|
||||||
|
|
||||||
|
// Instruction code for for writting data into
|
||||||
|
// e-Paper's memory
|
||||||
|
int code = EPD_dispMass[EPD_dispIndex].next;
|
||||||
|
|
||||||
|
// e-Paper '2.7' (index 8) needs inverting of image data bits
|
||||||
|
EPD_invert = (EPD_dispIndex == 8);
|
||||||
|
|
||||||
|
// If the instruction code isn't '-1', then...
|
||||||
|
if (code != -1)
|
||||||
|
{
|
||||||
|
// Print log message: instruction code
|
||||||
|
Serial.printf(" %d", code);
|
||||||
|
|
||||||
|
// Do the selection of the next data channel
|
||||||
|
EPD_SendCommand(code);
|
||||||
|
delay(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup the function for loading choosen channel's data
|
||||||
|
EPD_dispLoad = EPD_dispMass[EPD_dispIndex].chRd;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show loaded picture
|
||||||
|
else if (pBuf[0] == 'S' && data_len == 1)
|
||||||
|
{
|
||||||
|
Serial.print("<<<SHOW_START");
|
||||||
|
|
||||||
|
Serial.printf("rcv_image_data_size=%d\n", rcv_image_data_size);
|
||||||
|
if (is_compress) {
|
||||||
|
decompress_image_data();
|
||||||
|
}
|
||||||
|
// EPD_loadCompress();
|
||||||
|
if (EPD_dispLoad) {
|
||||||
|
EPD_dispLoad();
|
||||||
|
}
|
||||||
|
|
||||||
|
// reinit after show
|
||||||
|
rcv_image_data_size = 0;
|
||||||
|
load_stage = false;
|
||||||
|
next_stage = false;
|
||||||
|
|
||||||
|
EPD_dispMass[EPD_dispIndex].show();
|
||||||
|
|
||||||
|
//Print log message: show
|
||||||
|
Serial.print("<<<SHOW");
|
||||||
|
}
|
||||||
|
// json
|
||||||
|
else if (pBuf[0] == '{' && !load_stage) {
|
||||||
|
document.clear();
|
||||||
|
deserializeJson(document, pBuf);
|
||||||
|
// for example: {"COMMAND":"reboot_device"}
|
||||||
|
if (document.containsKey("COMMAND")) {
|
||||||
|
String cmd_type = document["COMMAND"].as<String>();
|
||||||
|
Serial.println("CMD: " + cmd_type);
|
||||||
|
if (cmd_type == "reboot_device") {
|
||||||
|
reboot_device();
|
||||||
|
} else {
|
||||||
|
Serial.println("unknown command - failed!>>>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!load_stage) {
|
||||||
|
Serial.print("unknown header - failed!>>>");
|
||||||
|
} else {
|
||||||
|
Serial.printf(".");
|
||||||
|
// Load data into the e-Paper
|
||||||
|
// if there is loading function for current channel (black or red)
|
||||||
|
memcpy(&rcv_image_data[rcv_image_data_size], pBuf, data_len);
|
||||||
|
rcv_image_data_size += (data_len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Buff__bufInd = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// process msg
|
||||||
|
void btRcvTask(void *pvParameters) {
|
||||||
|
while (1) {
|
||||||
|
xQueueReceive(btQueue, &btOutBuf, portMAX_DELAY);
|
||||||
|
|
||||||
|
myEPDBt.msgProc();
|
||||||
|
|
||||||
|
esp_task_wdt_reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EPDBt::Srvr__init() {
|
||||||
|
int queLen = 100;
|
||||||
|
|
||||||
|
btQueue = xQueueCreate(queLen, sizeof(bt_data_t));
|
||||||
|
|
||||||
|
xTaskCreate(btRcvTask, "BT_RCV", 20480, NULL, tskIDLE_PRIORITY, &btTask);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type A: each value represents 8 pixels
|
||||||
|
void EPDBt::EPD_loadCompressA(bool flip) {
|
||||||
|
int pos = 0;
|
||||||
|
// Enumerate all of image data
|
||||||
|
for (pos = 0; pos < image_data_size; pos++)
|
||||||
|
{
|
||||||
|
// Get current byte
|
||||||
|
// int value = Buff__getByte(pos);
|
||||||
|
int value = image_data[pos];
|
||||||
|
|
||||||
|
// Invert byte's bits in case of '2.7' e-Paper
|
||||||
|
if (EPD_invert) value = ~value;
|
||||||
|
|
||||||
|
// Write the byte into e-Paper's
|
||||||
|
// if (next_stage && (EPD_dispMass[EPD_dispIndex].chBk != EPD_dispMass[EPD_dispIndex].chRd)) {
|
||||||
|
if (flip) {
|
||||||
|
EPD_SendData(~(byte)value);
|
||||||
|
} else {
|
||||||
|
EPD_SendData((byte)value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EPDBt::EPD_loadUncompressA(bool flip) {
|
||||||
|
int pos = 0;
|
||||||
|
// Enumerate all of image data
|
||||||
|
for (pos = 0; pos < rcv_image_data_size; pos++)
|
||||||
|
{
|
||||||
|
// Get current byte
|
||||||
|
// int value = Buff__getByte(pos);
|
||||||
|
int value = rcv_image_data[pos];
|
||||||
|
|
||||||
|
// Invert byte's bits in case of '2.7' e-Paper
|
||||||
|
if (EPD_invert) value = ~value;
|
||||||
|
|
||||||
|
// Write the byte into e-Paper's
|
||||||
|
if (flip) {
|
||||||
|
EPD_SendData(~(byte)value);
|
||||||
|
} else {
|
||||||
|
EPD_SendData((byte)value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type G: each value represents 2 pixels
|
||||||
|
void EPDBt::EPD_loadCompressG(bool flip) {
|
||||||
|
int pos = 0;
|
||||||
|
// Enumerate all of image data
|
||||||
|
for (pos = 0; pos < image_data_size; pos++)
|
||||||
|
{
|
||||||
|
// Get current byte
|
||||||
|
// int value = Buff__getByte(pos);
|
||||||
|
int value = image_data[pos];
|
||||||
|
|
||||||
|
// Switch the positions of the two 4-bits pixels
|
||||||
|
// Black:0b000;White:0b001;Green:0b010;Blue:0b011;Red:0b100;Yellow:0b101;Orange:0b110;
|
||||||
|
int A = (value ) & 0x07;
|
||||||
|
int B = (value >> 4) & 0x07;
|
||||||
|
|
||||||
|
// Write the data into e-Paper's memory
|
||||||
|
EPD_SendData((byte)(A << 4) + B);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EPDBt::EPD_loadUncompressG(bool flip) {
|
||||||
|
int pos = 0;
|
||||||
|
// Enumerate all of image data
|
||||||
|
for (pos = 0; pos < rcv_image_data_size; pos++)
|
||||||
|
{
|
||||||
|
// Get current byte
|
||||||
|
// int value = Buff__getByte(pos);
|
||||||
|
int value = rcv_image_data[pos];
|
||||||
|
|
||||||
|
// Switch the positions of the two 4-bits pixels
|
||||||
|
// Black:0b000;White:0b001;Green:0b010;Blue:0b011;Red:0b100;Yellow:0b101;Orange:0b110;
|
||||||
|
int A = (value ) & 0x07;
|
||||||
|
int B = (value >> 4) & 0x07;
|
||||||
|
|
||||||
|
// Write the data into e-Paper's memory
|
||||||
|
EPD_SendData((byte)(A << 4) + B);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EPDBt::EPD_loadCompress(bool flip) {
|
||||||
|
if (EPD_dispIndex == 43) {
|
||||||
|
EPD_loadCompressG(flip);
|
||||||
|
} else {
|
||||||
|
EPD_loadCompressA(flip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EPDBt::EPD_loadUncompress(bool flip) {
|
||||||
|
if (EPD_dispIndex == 43) {
|
||||||
|
EPD_loadUncompressG(flip);
|
||||||
|
} else {
|
||||||
|
EPD_loadUncompressA(flip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EPDBt::Srvr__rcvProc() {
|
||||||
|
memcpy(btInBuf.Buff__bufArr, Buff__bufArr, Buff__bufInd);
|
||||||
|
btInBuf.data_len = Buff__bufInd;
|
||||||
|
|
||||||
|
xQueueSend(btQueue, &btInBuf, portMAX_DELAY);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
#ifndef EPD_BT_H_
|
||||||
|
#define EPD_BT_H_
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <BLEServer.h>
|
||||||
|
|
||||||
|
#define BT_BUFFER_SIZE 512
|
||||||
|
|
||||||
|
// define bluetooth async data structure
|
||||||
|
typedef struct {
|
||||||
|
int data_len;
|
||||||
|
char Buff__bufArr[BT_BUFFER_SIZE];
|
||||||
|
} bt_data_t;
|
||||||
|
|
||||||
|
class EPDBt {
|
||||||
|
public:
|
||||||
|
|
||||||
|
void EPD_loadA();
|
||||||
|
void EPD_loadAFilp();
|
||||||
|
void EPD_loadG();
|
||||||
|
|
||||||
|
void EPD_loadCompress(bool flip);
|
||||||
|
void EPD_loadCompressA(bool flip);
|
||||||
|
void EPD_loadCompressG(bool flip);
|
||||||
|
|
||||||
|
void EPD_loadUncompress(bool flip);
|
||||||
|
void EPD_loadUncompressA(bool flip);
|
||||||
|
void EPD_loadUncompressG(bool flip);
|
||||||
|
|
||||||
|
void Srvr__rcvProc();
|
||||||
|
bool Srvr__init();
|
||||||
|
void msgProc();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
}; // class EPDBt
|
||||||
|
|
||||||
|
extern EPDBt myEPDBt;
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
#ifndef EPD_CONF_H_
|
||||||
|
#define EPD_CONF_H_
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
/* SPI pin definition --------------------------------------------------------*/
|
||||||
|
#define DEFAULT_PIN_SPI_SCK 13
|
||||||
|
#define DEFAULT_PIN_SPI_DIN 14
|
||||||
|
#define DEFAULT_PIN_SPI_CS 15
|
||||||
|
#define DEFAULT_PIN_SPI_BUSY 25//19
|
||||||
|
#define DEFAULT_PIN_SPI_RST 26//21
|
||||||
|
#define DEFAULT_PIN_SPI_DC 27//22
|
||||||
|
|
||||||
|
/* Pin level definition ------------------------------------------------------*/
|
||||||
|
#define GPIO_PIN_SET 1
|
||||||
|
#define GPIO_PIN_RESET 0
|
||||||
|
|
||||||
|
#define UBYTE uint8_t
|
||||||
|
#define UWORD uint16_t
|
||||||
|
#define UDOUBLE uint32_t
|
||||||
|
|
||||||
|
#define LOAD_MODE_BT 1
|
||||||
|
#define LOAD_MODE_WIFI 2
|
||||||
|
|
||||||
|
/* The set of pointers on 'init', 'load' and 'show' functions, title and code */
|
||||||
|
struct EPD_dispInfo
|
||||||
|
{
|
||||||
|
int(*init)(); // Initialization
|
||||||
|
void(*chBk)();// Black channel loading
|
||||||
|
int next; // Change channel code
|
||||||
|
void(*chRd)();// Red channel loading
|
||||||
|
void(*show)();// Show and sleep
|
||||||
|
char*title; // Title of an e-Paper
|
||||||
|
};
|
||||||
|
|
||||||
|
extern int loadMode;
|
||||||
|
|
||||||
|
extern bool EPD_invert; // If true, then image data bits must be inverted
|
||||||
|
extern int EPD_dispIndex; // The index of the e-Paper's type
|
||||||
|
extern int EPD_dispX, EPD_dispY; // Current pixel's coordinates (for 2.13 only)
|
||||||
|
extern void(*EPD_dispLoad)(); // Pointer on a image data writting function
|
||||||
|
|
||||||
|
extern EPD_dispInfo EPD_dispMass[];
|
||||||
|
|
||||||
|
extern bool is_compress;
|
||||||
|
extern uint8_t *rcv_image_data;
|
||||||
|
extern uint32_t rcv_image_data_size;
|
||||||
|
extern uint8_t *image_data;
|
||||||
|
extern uint32_t image_data_size;
|
||||||
|
extern bool load_stage;
|
||||||
|
extern bool next_stage;
|
||||||
|
|
||||||
|
extern int PIN_SPI_SCK;
|
||||||
|
extern int PIN_SPI_DIN;
|
||||||
|
extern int PIN_SPI_CS;
|
||||||
|
extern int PIN_SPI_BUSY;
|
||||||
|
extern int PIN_SPI_RST;
|
||||||
|
extern int PIN_SPI_DC;
|
||||||
|
|
||||||
|
// /* Lut mono ------------------------------------------------------------------*/
|
||||||
|
extern byte lut_full_mono[];
|
||||||
|
extern byte lut_partial_mono[];
|
||||||
|
|
||||||
|
extern byte lut_vcom0[];
|
||||||
|
extern byte lut_w [];
|
||||||
|
extern byte lut_b [];
|
||||||
|
extern byte lut_g1 [];
|
||||||
|
extern byte lut_g2 [];
|
||||||
|
extern byte lut_vcom1[];
|
||||||
|
extern byte lut_red0 [];
|
||||||
|
extern byte lut_red1 [];
|
||||||
|
|
||||||
|
void decompress_image_data();
|
||||||
|
|
||||||
|
#endif
|
||||||
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user