mirror of
https://github.com/RoCry/blozi-etag.git
synced 2025-12-06 09:02:49 +08:00
feat: add scripts/web tools
This commit is contained in:
Binary file not shown.
@@ -91,6 +91,7 @@ static const u8 my_EPD_BLEUUID[16] = { EPD_BLE_CHAR_UUID };
|
||||
#define EPD_BLE_SERVICE_UUID 0x38, 0x9a, 0x7d, 0x21, 0xd3, 0x83, 0x4e, 0x04, 0xba, 0xa3, 0xa9, 0xeb, 0x10, 0x7b, 0x18, 0x13
|
||||
static const u8 my_EPD_BLE_ServiceUUID[16] = { EPD_BLE_SERVICE_UUID };
|
||||
static u8 my_EPD_BLE_Data = 0x00;
|
||||
static u8 my_EPD_BLEInCCC[2];
|
||||
|
||||
// Include attribute (Battery service)
|
||||
static const u16 include[3] = {BATT_PS_H, BATT_LEVEL_INPUT_CCB_H, SERVICE_UUID_BATTERY};
|
||||
@@ -150,7 +151,7 @@ static const u8 my_RxTxCharVal[5] = {
|
||||
|
||||
//// EPD_BLE attribute values
|
||||
static const u8 my_EPD_BLECharVal[19] = {
|
||||
CHAR_PROP_READ | CHAR_PROP_WRITE,
|
||||
CHAR_PROP_NOTIFY | CHAR_PROP_WRITE,
|
||||
U16_LO(EPD_BLE_CMD_OUT_DP_H), U16_HI(EPD_BLE_CMD_OUT_DP_H),
|
||||
EPD_BLE_CHAR_UUID,
|
||||
};
|
||||
@@ -196,9 +197,10 @@ static const attribute_t my_Attributes[] = {
|
||||
{0,ATT_PERMISSIONS_WRITE, 2,sizeof(my_RxTx_Data),(u8*)(&my_RxTxUUID), (&my_RxTx_Data), &RxTxWrite}, //value
|
||||
{0,ATT_PERMISSIONS_RDWR,2,sizeof(RxTxValueInCCC),(u8*)(&clientCharacterCfgUUID), (u8*)(RxTxValueInCCC), 0}, //value
|
||||
////////////////////////////////////// EPD_BLE ////////////////////////////////////////////////////
|
||||
{3,ATT_PERMISSIONS_READ, 2, 16,(u8*)(&my_primaryServiceUUID), (u8*)(&my_EPD_BLE_ServiceUUID), 0},
|
||||
{4,ATT_PERMISSIONS_READ, 2, 16,(u8*)(&my_primaryServiceUUID), (u8*)(&my_EPD_BLE_ServiceUUID), 0},
|
||||
{0,ATT_PERMISSIONS_READ, 2, sizeof(my_EPD_BLECharVal), (u8*)(&my_characterUUID), (u8*)(my_EPD_BLECharVal), 0},
|
||||
{0,ATT_PERMISSIONS_WRITE, 16, sizeof(my_EPD_BLE_Data), (u8*)(&my_EPD_BLEUUID), (&my_EPD_BLE_Data), (att_readwrite_callback_t) &epd_ble_handle_write},
|
||||
{0,ATT_PERMISSIONS_RDWR, 2, sizeof(my_EPD_BLEInCCC),(u8*)(&clientCharacterCfgUUID), (u8*)(my_EPD_BLEInCCC), 0}, //value
|
||||
};
|
||||
|
||||
void my_att_init(void)
|
||||
|
||||
@@ -240,6 +240,8 @@ _attribute_ram_code_ void epd_display_tiff(uint8_t *pData, int iSize)
|
||||
extern uint8_t mac_public[6];
|
||||
_attribute_ram_code_ void epd_display(uint32_t time_is, uint16_t battery_mv, int16_t temperature, uint8_t full_or_partial)
|
||||
{
|
||||
uint8_t battery_level;
|
||||
|
||||
if (epd_update_state)
|
||||
return;
|
||||
|
||||
@@ -279,6 +281,7 @@ _attribute_ram_code_ void epd_display(uint32_t time_is, uint16_t battery_mv, int
|
||||
obdFill(&obd, 0, 0); // fill with white
|
||||
|
||||
char buff[100];
|
||||
battery_level = get_battery_level(battery_mv);
|
||||
sprintf(buff, "S24_%02X%02X%02X %s", mac_public[2], mac_public[1], mac_public[0], epd_model_string[epd_model]);
|
||||
obdWriteStringCustom(&obd, (GFXfont *)&Dialog_plain_16, 1, 17, (char *)buff, 1);
|
||||
sprintf(buff, "%s", BLE_conn_string[ble_get_connected()]);
|
||||
@@ -287,7 +290,7 @@ _attribute_ram_code_ void epd_display(uint32_t time_is, uint16_t battery_mv, int
|
||||
obdWriteStringCustom(&obd, (GFXfont *)&DSEG14_Classic_Mini_Regular_40, 75, 65, (char *)buff, 1);
|
||||
sprintf(buff, "-----%d'C-----", EPD_read_temp());
|
||||
obdWriteStringCustom(&obd, (GFXfont *)&Special_Elite_Regular_30, 10, 95, (char *)buff, 1);
|
||||
sprintf(buff, "Battery %dmV", battery_mv);
|
||||
sprintf(buff, "Battery %dmV %d%%", battery_mv, battery_level);
|
||||
obdWriteStringCustom(&obd, (GFXfont *)&Dialog_plain_16, 10, 120, (char *)buff, 1);
|
||||
FixBuffer(epd_temp, epd_buffer, resolution_w, resolution_h);
|
||||
EPD_Display(epd_buffer, resolution_w * resolution_h / 8, full_or_partial);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#define epd_height 200
|
||||
#define epd_width 200
|
||||
#define epd_height 128
|
||||
#define epd_width 296
|
||||
#define epd_buffer_size ((epd_height/8) * epd_width)
|
||||
|
||||
void set_EPD_model(uint8_t model_nr);
|
||||
|
||||
@@ -23,6 +23,7 @@ int epd_ble_handle_write(void *p)
|
||||
rf_packet_att_write_t *req = (rf_packet_att_write_t *)p;
|
||||
uint8_t *payload = &req->value;
|
||||
unsigned int payload_len = req->l2capLen - 3;
|
||||
uint8_t out_buffer[20] = {0};
|
||||
|
||||
ASSERT_MIN_LEN(payload_len, 1);
|
||||
|
||||
@@ -46,12 +47,20 @@ int epd_ble_handle_write(void *p)
|
||||
return 0;
|
||||
// Write data to image buffer.
|
||||
case 0x03:
|
||||
if (byte_pos + payload_len - 1 >= sizeof(epd_buffer) + 1)
|
||||
if (byte_pos + payload_len - 1 >= epd_buffer_size + 1)
|
||||
{
|
||||
out_buffer[0] = 0x00;
|
||||
out_buffer[1] = 0x00;
|
||||
bls_att_pushNotifyData(EPD_BLE_CMD_OUT_DP_H, out_buffer, 2);
|
||||
return 0;
|
||||
}
|
||||
memcpy(epd_buffer + byte_pos, payload + 1, payload_len - 1);
|
||||
|
||||
byte_pos += payload_len - 1;
|
||||
|
||||
out_buffer[0] = payload_len >> 8;
|
||||
out_buffer[1] = payload_len & 0xff;
|
||||
bls_att_pushNotifyData(EPD_BLE_CMD_OUT_DP_H, out_buffer, 2);
|
||||
return 0;
|
||||
case 0x04: // decode & display a TIFF image
|
||||
epd_display_tiff(epd_buffer, byte_pos);
|
||||
|
||||
@@ -60,7 +60,7 @@ _attribute_ram_code_ uint8_t EPD_BWR_296_detect(void)
|
||||
_attribute_ram_code_ uint8_t EPD_BWR_296_read_temp(void)
|
||||
{
|
||||
uint8_t epd_temperature = 0 ;
|
||||
|
||||
|
||||
// SW Reset
|
||||
EPD_WriteCmd(0x12);
|
||||
|
||||
@@ -118,7 +118,7 @@ _attribute_ram_code_ uint8_t EPD_BWR_296_read_temp(void)
|
||||
// Display update control
|
||||
EPD_WriteCmd(0x22);
|
||||
EPD_WriteData(0xB1);
|
||||
|
||||
|
||||
// Master Activation
|
||||
EPD_WriteCmd(0x20);
|
||||
|
||||
@@ -126,11 +126,11 @@ _attribute_ram_code_ uint8_t EPD_BWR_296_read_temp(void)
|
||||
|
||||
// Temperature sensor read from register
|
||||
EPD_WriteCmd(0x1B);
|
||||
epd_temperature = EPD_SPI_read();
|
||||
epd_temperature = EPD_SPI_read();
|
||||
EPD_SPI_read();
|
||||
|
||||
WaitMs(5);
|
||||
|
||||
|
||||
// deep sleep
|
||||
EPD_WriteCmd(0x10);
|
||||
EPD_WriteData(0x01);
|
||||
@@ -138,10 +138,9 @@ _attribute_ram_code_ uint8_t EPD_BWR_296_read_temp(void)
|
||||
return epd_temperature;
|
||||
}
|
||||
|
||||
_attribute_ram_code_ uint8_t EPD_BWR_296_Display(unsigned char *image, int size, uint8_t full_or_partial)
|
||||
{
|
||||
_attribute_ram_code_ uint8_t EPD_BWR_296_Display(unsigned char *image, int size, uint8_t full_or_partial) {
|
||||
uint8_t epd_temperature = 0 ;
|
||||
|
||||
|
||||
// SW Reset
|
||||
EPD_WriteCmd(0x12);
|
||||
|
||||
@@ -178,7 +177,7 @@ _attribute_ram_code_ uint8_t EPD_BWR_296_Display(unsigned char *image, int size,
|
||||
|
||||
// Set RAM Y- Address Start/End
|
||||
EPD_WriteCmd(0x45);
|
||||
EPD_WriteData(0x27); //0x0127-->(295+1)=296
|
||||
EPD_WriteData(0x28); //0x0127-->(295+1)=296
|
||||
EPD_WriteData(0x01);
|
||||
EPD_WriteData(0x00);
|
||||
EPD_WriteData(0x00);
|
||||
@@ -199,7 +198,7 @@ _attribute_ram_code_ uint8_t EPD_BWR_296_Display(unsigned char *image, int size,
|
||||
// Display update control
|
||||
EPD_WriteCmd(0x22);
|
||||
EPD_WriteData(0xB1);
|
||||
|
||||
|
||||
// Master Activation
|
||||
EPD_WriteCmd(0x20);
|
||||
|
||||
@@ -207,7 +206,7 @@ _attribute_ram_code_ uint8_t EPD_BWR_296_Display(unsigned char *image, int size,
|
||||
|
||||
// Temperature sensor read from register
|
||||
EPD_WriteCmd(0x1B);
|
||||
epd_temperature = EPD_SPI_read();
|
||||
epd_temperature = EPD_SPI_read();
|
||||
EPD_SPI_read();
|
||||
|
||||
WaitMs(5);
|
||||
@@ -232,7 +231,7 @@ _attribute_ram_code_ uint8_t EPD_BWR_296_Display(unsigned char *image, int size,
|
||||
EPD_WriteData(0x28);
|
||||
EPD_WriteData(0x01);
|
||||
|
||||
EPD_WriteCmd(0x26);// RED Color TODO make something out of it :)
|
||||
EPD_WriteCmd(0x26);
|
||||
int i;
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
@@ -247,11 +246,11 @@ _attribute_ram_code_ uint8_t EPD_BWR_296_Display(unsigned char *image, int size,
|
||||
EPD_WriteData(LUT_bwr_296_part[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Display update control
|
||||
EPD_WriteCmd(0x22);
|
||||
EPD_WriteData(0xC7);
|
||||
|
||||
|
||||
// Master Activation
|
||||
EPD_WriteCmd(0x20);
|
||||
|
||||
|
||||
15
readme.md
15
readme.md
@@ -6,7 +6,7 @@
|
||||
|
||||

|
||||
|
||||
- 2. 焊接 GND, VCC, RX, TX四根线。 RST 可不焊。
|
||||
- 2. 焊接 GND, VCC, RX, RTS四根线。 RTS 可不焊。
|
||||
- 3. 使用usb2ttl模块(CH340)链接焊接的四根线。其中rx 链接 tx, tx链接 rx, vcc链接3.3v, GND链接 GND
|
||||
- 4. 打开https://atc1441.github.io/ATC_TLSR_Paper_UART_Flasher.html, 波特率选择默认 460800,Atime默认,文件选择Firmware/ATC_Paper.bin
|
||||
- 5. 先点击unlock,再点击write to flush,等待完成。成功后,屏幕会自动刷新。
|
||||
@@ -42,9 +42,15 @@ Firmware CRC32: 0xe62d501e
|
||||
```
|
||||
|
||||
### 蓝牙链接和OTA升级
|
||||
- 1. 必须先断开TTL,不然蓝牙链接不上。
|
||||
- 1. 必须先断开TTL TX线,不然蓝牙链接不上。
|
||||
- 2. OTA升级: https://atc1441.github.io/ATC_TLSR_Paper_OTA_writing.html
|
||||
- 3. 上传图片: https://atc1441.github.io/ATC_TLSR_Paper_Image_Upload.html
|
||||
|
||||
### 上传图片
|
||||
- 1. 运行 `cd web_tools && python -m http.server`
|
||||
- 2. 打开 http://127.0.0.1:8000 后在页面上链接蓝牙
|
||||
- 3. 使用 tools/scripts/image2hex.py 生成图片的16进制字符串,复制到上面页面的输入框里
|
||||
- 4. 发送到设备,等待屏幕刷新
|
||||
|
||||
|
||||
### 已解决/未解决问题
|
||||
- [x] 编译报错
|
||||
@@ -52,6 +58,9 @@ Firmware CRC32: 0xe62d501e
|
||||
- [x] 屏幕区域不对/异常
|
||||
- [x] 蓝牙无法链接/蓝牙OTA升级
|
||||
- [ ] 自动识别型号
|
||||
- [x] python 图片生成脚本
|
||||
- [x] 蓝牙发送图片, 显示大小不对问题解决
|
||||
- [x] 添加蓝牙上传图片后notify
|
||||
|
||||
### 计划新增
|
||||
- [ ] 安卓端控制器
|
||||
|
||||
BIN
tools/data/images/test-01.bmp
Normal file
BIN
tools/data/images/test-01.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
0
tools/requriments.txt
Normal file
0
tools/requriments.txt
Normal file
0
tools/scripts/__init__.py
Normal file
0
tools/scripts/__init__.py
Normal file
5
tools/scripts/hex2image.py
Normal file
5
tools/scripts/hex2image.py
Normal file
File diff suppressed because one or more lines are too long
8
tools/scripts/image2hex.py
Normal file
8
tools/scripts/image2hex.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from PIL import Image
|
||||
|
||||
from tools.utils import image2hex, load_test_image
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# print(image2hex(load_test_image('test-01.bmp')))
|
||||
print(image2hex(load_test_image('mao.bmp'), steinberg=True))
|
||||
46
tools/utils.py
Normal file
46
tools/utils.py
Normal file
@@ -0,0 +1,46 @@
|
||||
import os
|
||||
|
||||
from PIL import Image
|
||||
|
||||
|
||||
def hex2bytes(hex_string):
|
||||
return bytes([int(hex_string[index:index+2], 16) for index in range(0,len(hex_string), 2)])
|
||||
|
||||
|
||||
def hex2bits(hex_string):
|
||||
_bytes = []
|
||||
for index in range(0, len(hex_string), 2):
|
||||
for char in hex_string[index:index+2]:
|
||||
for c in bin(int(char, 16))[2:].zfill(8):
|
||||
_bytes.append(int(c))
|
||||
|
||||
return bytes(_bytes)
|
||||
|
||||
|
||||
def bytes2hex(_bytes):
|
||||
return ''.join(hex(item)[2:].zfill(2) for item in _bytes)
|
||||
|
||||
|
||||
def hex2image(hex_string, width, height):
|
||||
data = hex2bits(hex_string)
|
||||
image = Image.new('1', (width, height), (1))
|
||||
image.frombytes(data[:width*height], )
|
||||
|
||||
image.show('test')
|
||||
|
||||
|
||||
def image2hex(image, width=296, height=128, steinberg=False):
|
||||
if isinstance(image, str):
|
||||
image = Image.open(image)
|
||||
|
||||
mode = None
|
||||
if steinberg:
|
||||
mode = Image.FLOYDSTEINBERG
|
||||
|
||||
return bytes2hex(image.resize((width, height)).rotate(90, expand=True).resize((height, width)).convert('1', dither=mode).tobytes())
|
||||
|
||||
|
||||
def load_test_image(name):
|
||||
path = os.path.join(os.path.dirname(__file__), 'data', 'images', name)
|
||||
print(f'open image: {path}')
|
||||
return Image.open(path)
|
||||
295
web_tools/index.html
Normal file
295
web_tools/index.html
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user