Skip to content

Instantly share code, notes, and snippets.

@anoken
Last active February 11, 2022 13:51
Show Gist options
  • Save anoken/8b0ce255e9aef9d1a7f4d46272cedcaa to your computer and use it in GitHub Desktop.
Save anoken/8b0ce255e9aef9d1a7f4d46272cedcaa to your computer and use it in GitHub Desktop.
M5StickCViewer_for_UnitV
// Copyright (c) 2019 aNoken
#include <M5StickC.h>
HardwareSerial serial_ext(2);
typedef struct {
uint32_t length;
uint8_t *buf;
} jpeg_data_t;
jpeg_data_t jpeg_data;
static const int RX_BUF_SIZE = 3000;
static const uint8_t packet_img[4] = { 0xFF, 0xF1, 0xF2, 0xA1};
void setup() {
M5.begin();
M5.Lcd.setRotation(2);
M5.Axp.ScreenBreath(10);
jpeg_data.buf = (uint8_t *) malloc(sizeof(uint8_t) * RX_BUF_SIZE);
jpeg_data.length = 0;
if (jpeg_data.buf == NULL) {
Serial.println("malloc jpeg buffer 1 error");
}
serial_ext.begin(115200, SERIAL_8N1, 32, 33);
}
void loop() {
M5.update();
if (serial_ext.available()) {
uint8_t rx_buffer[10];
int rx_size = serial_ext.readBytes(rx_buffer, 10);
if (rx_size == 10) {
if ((rx_buffer[0] == packet_img[0]) && (rx_buffer[1] == packet_img[1]) &&
(rx_buffer[2] == packet_img[2]) && (rx_buffer[3] == packet_img[3])) {
jpeg_data.length = (uint32_t)(rx_buffer[4] << 16) | (rx_buffer[5] << 8) | rx_buffer[6];
int rx_size = serial_ext.readBytes(jpeg_data.buf, jpeg_data.length);
Serial.println(rx_size);
//M5StickC is not this function (arduino m5stickc lib ver0.1.1)
//you need add this
//https://github.com/anoken/M5StickC/commit/34965325891bdcab97f2bb056d4838cdf75e1b8d
M5.lcd.drawJpg(jpeg_data.buf, jpeg_data.length, 0, 20);
}
else {
int rx_size = serial_ext.readBytes(rx_buffer, 1);
}
}
}
vTaskDelay(10 / portTICK_RATE_MS);
}
## Copyright (c) 2019 aNoken
import image, lcd, sensor,gc
from fpioa_manager import fm,board_info
import KPU as kpu
from Maix import GPIO
from pmu import axp192
from machine import UART,I2C
import ulab as np
from modules import ws2812
#M5StickV LCD Initialize
def m5stickv_init(uniV_use):
if uniV_use==0:
lcd.init()
lcd.rotation(2)
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_windowing((224, 224))
sensor.run(1)
if uniV_use==0:
pmu = axp192()
pmu.setScreenBrightness(9)
def unitv_check():
uniV_use=0
i2c = I2C(I2C.I2C0, freq=100000, scl=28, sda=29)
devices = i2c.scan()
if len(devices)==0:
uniV_use=1
return uniV_use
print("Initialize")
uniV_use=unitv_check()
m5stickv_init(uniV_use)
if uniV_use==1:
class_ws2812 = ws2812(8,1)
class_ws2812.set_led(0,(0,0,0))
class_ws2812.display()
print("M5 Button def")
but_a_pressed = 0
but_b_pressed = 0
if uniV_use==0:
fm.register(36, fm.fpioa.GPIO1)
fm.register(37, fm.fpioa.GPIO2)
else :
fm.register(18, fm.fpioa.GPIO1)
fm.register(19, fm.fpioa.GPIO2)
but_a = GPIO(GPIO.GPIO1, GPIO.IN, GPIO.PULL_UP)
but_b = GPIO(GPIO.GPIO2, GPIO.IN, GPIO.PULL_UP)
#UART Connection
fm.register(35, fm.fpioa.UART1_TX, force=True)
fm.register(34, fm.fpioa.UART1_RX, force=True)
uart_Port = UART(UART.UART1, 115200,8,0,0, timeout=1000, read_buf_len= 4096)
while(True):
img1 = sensor.snapshot()
img_buf=img1.copy()
img_buf=img1.resize(80,80)
img_buf.compress(quality=60)
img_size1 = (img_buf.size()& 0xFF0000)>>16
img_size2 = (img_buf.size()& 0x00FF00)>>8
img_size3 = (img_buf.size()& 0x0000FF)>>0
data_packet = bytearray([0xFF,0xF1,0xF2,0xA1,img_size1,img_size2,img_size3,0x00,0x00,0x00])
uart_Port.write(data_packet)
uart_Port.write(img_buf)
#print("",img_buf.size(),",",data_packet)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment