mirror of
https://github.com/RoCry/blozi-etag.git
synced 2026-03-15 23:13:16 +08:00
Hacky BLE service for drawing
This commit is contained in:
@@ -25,6 +25,12 @@ RAM bool show_batt_or_humi;
|
||||
// Settings
|
||||
extern settings_struct settings;
|
||||
|
||||
// All black.
|
||||
// static unsigned char image[epd_buffer_size] = {0x00};
|
||||
|
||||
unsigned char image[epd_buffer_size];
|
||||
// unsigned char image2[epd_buffer_size];
|
||||
|
||||
void user_init_normal(void)
|
||||
{ // this will get executed one time after power up
|
||||
random_generator_init(); // must
|
||||
@@ -33,6 +39,19 @@ void user_init_normal(void)
|
||||
battery_mv = get_battery_mv();
|
||||
battery_level = get_battery_level(battery_mv);
|
||||
epd_display_tiff();
|
||||
|
||||
// image[1 * epd_height/8 + 0] = 0xff;
|
||||
// image[1 * epd_height/8 + 1] = 0xff;
|
||||
// image[1 * epd_height/8 + 2] = 0xff;
|
||||
// image[1 * epd_height/8 + 3] = 0xff;
|
||||
|
||||
// Rectangle in the middle of the screen.
|
||||
for (int x = 0; x < 50; x++) {
|
||||
for (int y = 0; y < 12; y++) {
|
||||
image[(x + 100) * epd_height / 8 + y + 2] = 0xff;
|
||||
}
|
||||
}
|
||||
EPD_Display(image, sizeof(image));
|
||||
}
|
||||
|
||||
_attribute_ram_code_ void user_init_deepRetn(void)
|
||||
@@ -64,7 +83,7 @@ _attribute_ram_code_ void main_loop()
|
||||
if (current_unix_time - last_update > 30)
|
||||
{
|
||||
last_update = current_unix_time;
|
||||
epd_display(current_unix_time);
|
||||
// epd_display(current_unix_time);
|
||||
}
|
||||
if (epd_state_handler()) // if epd_update is ongoing enable gpio wakeup to put the display to sleep as fast as possible
|
||||
{
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include "main.h"
|
||||
#include "stack/ble/ble.h"
|
||||
#include "uart.h"
|
||||
#include "epd.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -81,6 +83,11 @@ static const u16 my_RxTx_ServiceUUID = 0x1f10;
|
||||
static u8 my_RxTx_Data = 0x00;
|
||||
static u8 RxTxValueInCCC[2];
|
||||
|
||||
// DrawPixel Char
|
||||
static const u16 my_DrawPixelUUID = 0xabab;
|
||||
static const u16 my_DrawPixel_ServiceUUID = 0xabaa;
|
||||
static u8 my_DrawPixel_Data = 0x00;
|
||||
|
||||
// Include attribute (Battery service)
|
||||
static const u16 include[3] = {BATT_PS_H, BATT_LEVEL_INPUT_CCB_H, SERVICE_UUID_BATTERY};
|
||||
|
||||
@@ -138,9 +145,43 @@ static const u8 my_RxTxCharVal[5] = {
|
||||
U16_LO(0x1f1f), U16_HI(0x1f1f)
|
||||
};
|
||||
|
||||
//// DrawPixel attribute values
|
||||
static const u8 my_DrawPixelCharVal[5] = {
|
||||
CHAR_PROP_WRITE_WITHOUT_RSP,
|
||||
U16_LO(DrawPixel_CMD_OUT_DP_H), U16_HI(DrawPixel_CMD_OUT_DP_H),
|
||||
U16_LO(0xabab), U16_HI(0xabab)
|
||||
};
|
||||
|
||||
extern int otaWritePre(void * p);
|
||||
extern int otaReadPre(void * p);
|
||||
extern int RxTxWrite(void * p);
|
||||
|
||||
unsigned char image[epd_buffer_size];
|
||||
unsigned int byte_pos = 0;
|
||||
|
||||
int DrawPixels(void * p) {
|
||||
rf_packet_att_write_t *req = (rf_packet_att_write_t*)p;
|
||||
char buf[64];
|
||||
sprintf(buf, "Size: %d\n", req->l2capLen);
|
||||
uart_write(buf);
|
||||
uint8_t *v = &req->value;
|
||||
memcpy(image + byte_pos, (uint8_t *) &req->value, req->l2capLen - 3);
|
||||
byte_pos += req->l2capLen - 3;
|
||||
|
||||
if (byte_pos > 2047) {
|
||||
EPD_Display(image, epd_buffer_size);
|
||||
memset(image, 0xff, epd_buffer_size);
|
||||
byte_pos = 0;
|
||||
}
|
||||
for (int i = 0; i < 20; i++) {
|
||||
// sprintf(buf, "0x%02x ", req->dat[i]);
|
||||
sprintf(buf, "0x%02x ", *(v + i));
|
||||
uart_write(buf);
|
||||
}
|
||||
uart_write("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TM : to modify
|
||||
static const attribute_t my_Attributes[] = {
|
||||
{ATT_END_H - 1, 0,0,0,0,0}, // total num of attribute
|
||||
@@ -181,6 +222,10 @@ static const attribute_t my_Attributes[] = {
|
||||
{0,ATT_PERMISSIONS_READ, 2, sizeof(my_RxTxCharVal),(u8*)(&my_characterUUID), (u8*)(my_RxTxCharVal), 0}, //prop
|
||||
{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
|
||||
////////////////////////////////////// DrawPixels ////////////////////////////////////////////////////
|
||||
{4,ATT_PERMISSIONS_READ, 2,2,(u8*)(&my_primaryServiceUUID), (u8*)(&my_DrawPixel_ServiceUUID), 0},
|
||||
{0,ATT_PERMISSIONS_READ, 2, sizeof(my_DrawPixelCharVal),(u8*)(&my_characterUUID), (u8*)(my_DrawPixelCharVal), 0}, //prop
|
||||
{0,ATT_PERMISSIONS_WRITE, 2,sizeof(my_DrawPixel_Data),(u8*)(&my_DrawPixelUUID), (&my_DrawPixel_Data), (att_readwrite_callback_t)&DrawPixels}, //value
|
||||
};
|
||||
|
||||
void my_att_init(void)
|
||||
|
||||
@@ -66,7 +66,14 @@ typedef enum
|
||||
RxTx_CMD_OUT_CD_H, //UUID: , VALUE: Prop: read | write_without_rsp
|
||||
RxTx_CMD_OUT_DP_H, //UUID: RxTx uuid, VALUE: RxTxData
|
||||
RxTx_CMD_OUT_DESC_H, //UUID: 2901, VALUE: RxTxName
|
||||
|
||||
|
||||
//// RxTx ////
|
||||
/**********************************************************************************************/
|
||||
DrawPixel_PS_H, //UUID: , VALUE: DrawPixel service uuid
|
||||
DrawPixel_CMD_OUT_CD_H, //UUID: , VALUE: Prop: write_without_rsp
|
||||
DrawPixel_CMD_OUT_DP_H, //UUID: DrawPixel uuid, VALUE: DrawPixelData
|
||||
DrawPixel_CMD_OUT_DESC_H, //UUID: , VALUE: DrawPixelName
|
||||
|
||||
ATT_END_H,
|
||||
|
||||
}ATT_HANDLE;
|
||||
|
||||
@@ -14,9 +14,9 @@ extern const uint8_t ucMirror[];
|
||||
#include "bart_tif.h"
|
||||
#include "font_60.h"
|
||||
|
||||
#define epd_height 128
|
||||
#define epd_width 250
|
||||
#define epd_buffer_size ((epd_height/8) * epd_width)
|
||||
// #define epd_height 128
|
||||
// #define epd_width 250
|
||||
// #define epd_buffer_size ((epd_height/8) * epd_width)
|
||||
|
||||
RAM uint8_t epd_update_state = 0;
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#define epd_height 128
|
||||
#define epd_width 250
|
||||
#define epd_buffer_size ((epd_height/8) * epd_width)
|
||||
|
||||
void EPD_DLY_LP(unsigned int ms);
|
||||
void EPD_SPI_Write(unsigned char value);
|
||||
void EPD_WriteCmd(unsigned char cmd);
|
||||
|
||||
Reference in New Issue
Block a user