mirror of
https://github.com/korneliuszo/lumiax-controller.git
synced 2026-05-07 05:54:30 +02:00
Make display controlled via uart
This commit is contained in:
Executable
+31
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import tlay2_client
|
||||
import struct
|
||||
from PIL import Image
|
||||
|
||||
def send_image(img):
|
||||
img = img.convert("1")
|
||||
w,h = img.size
|
||||
if w != 200 or h != 128:
|
||||
raise Exception("bad format")
|
||||
|
||||
|
||||
data = []
|
||||
for i in range(h//8):
|
||||
data.append(bytearray([255])*w)
|
||||
for x in range(w):
|
||||
for y in range(h):
|
||||
if img.getpixel((x,y)) == 0:
|
||||
data[y//8][x] &= ~(1<<(7-y%8))
|
||||
|
||||
a=tlay2_client.Tlay2_msg(2)
|
||||
for i in range(len(data)):
|
||||
line = data[i]
|
||||
for j in range(0, len(line), 32):
|
||||
chunk = line[j:j+32]
|
||||
a.msg(struct.pack("<H",96+j+i*(296//8)*8)+chunk)
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
send_image(Image.open(sys.argv[1]))
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
+1
-1
@@ -13,8 +13,8 @@
|
||||
class Display {
|
||||
const struct device *dev;
|
||||
k_mutex mut;
|
||||
uint8_t buff[128*296/8];
|
||||
public:
|
||||
uint8_t buff[128*296/8];
|
||||
class Display_lock
|
||||
{
|
||||
k_mutex *m;
|
||||
|
||||
+15
-8
@@ -68,18 +68,25 @@ struct k_thread display_thread_data;
|
||||
void display_thread(void*,void*,void*)
|
||||
{
|
||||
int spinner_idx=0;
|
||||
int spinner_data_idx=0;
|
||||
char spinner[] = "/-\\|";
|
||||
Reg_data::Data cached = {};
|
||||
while(true)
|
||||
{
|
||||
k_sem_take(®_data.new_sample,K_FOREVER);
|
||||
k_mutex_lock(®_data.mut, K_FOREVER);
|
||||
Reg_data::Data cached = reg_data.d;
|
||||
k_mutex_unlock(®_data.mut);
|
||||
|
||||
if(!k_sem_take(®_data.new_sample,K_NO_WAIT))
|
||||
{
|
||||
auto l = display.lock();
|
||||
k_mutex_lock(®_data.mut, K_FOREVER);
|
||||
cached = reg_data.d;
|
||||
k_mutex_unlock(®_data.mut);
|
||||
spinner_data_idx++;
|
||||
if (!spinner[spinner_data_idx])
|
||||
spinner_data_idx=0;
|
||||
}
|
||||
{
|
||||
//auto l = display.lock();
|
||||
display.print_chr(0,0,spinner[spinner_idx++]);
|
||||
display.print_str(16,0,cached.on ? " ON":"OFF");
|
||||
display.print_chr(8,0,spinner[spinner_data_idx]);
|
||||
display.print_str(32,0,cached.on ? " ON":"OFF");
|
||||
char buff[13];
|
||||
snprintf(buff,13,"Bat %6.2u%%",cached.b_soc);
|
||||
display.print_str(0,16,buff);
|
||||
@@ -217,7 +224,7 @@ int main(void)
|
||||
K_THREAD_STACK_SIZEOF(display_stack_area),
|
||||
display_thread,
|
||||
NULL, NULL, NULL,
|
||||
5, 0, K_NO_WAIT);
|
||||
10, 0, K_NO_WAIT);
|
||||
if (init_modbus_client()) {
|
||||
tlay2.printt("Modbus RTU client initialization failed");
|
||||
return 1;
|
||||
|
||||
@@ -26,6 +26,17 @@ void process_packet(Tlay2<128>* obj, uint8_t*data,size_t len)
|
||||
obj->tx_end();
|
||||
break;
|
||||
}
|
||||
case 2: // display
|
||||
{
|
||||
uint16_t offset = obj->rx_u16(&data[2]);
|
||||
{
|
||||
uint8_t *buffptr = &display.buff[offset];
|
||||
memcpy(buffptr,&data[4],len-4);
|
||||
}
|
||||
obj->tx_init_reply();
|
||||
obj->tx_end();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user