ASRPRO+SSD1306
ASRPRO端源码
#define ST7735_CS_PIN 2
#define ST7735_CS_GPIO_PIN gpio_pin_2
#define ST7735_DC_PIN 3
#define ST7735_DC_GPIO_PIN gpio_pin_3
#define ST7735_RST_PIN 1
#define ST7735_RST_GPIO_PIN gpio_pin_1
#define ST7735_SCK_PIN 5
#define ST7735_MOSI_PIN 6
// #define ST7735_SCK_PIN 6
// #define ST7735_MOSI_PIN 5
//#define ST7735_SCK_GPIO_PIN gpio_pin_5
//#define ST7735_MOSI_GPIO_PIN gpio_pin_6
/* 宏定义 --------------------------------------------------------------------*/
#define MOSI ST7735_MOSI_PIN
#define SCK ST7735_SCK_PIN
#define DC ST7735_DC_PIN
#define CS ST7735_CS_PIN
#include "asr.h"
extern "C"{ void * __dso_handle = 0 ;}
#include "setup.h"
#include "myLib/luxiaoban.h"
#include "HardwareSerial.h"
#include "../U8G2/u8g2ASR.h"
int ndelay_interupt = 0;
bool stop_sign = 0;
u8g2_class u8g2c;
void hardware_init();
void emo_class();
void weather_class();
void draw_string(const char *s);
void PlayWeatherAndDate();
void process(); //主处理函数
bool ndelay(int wait);
void drawImage();
void Show_Time();
QueueHandle_t message1=NULL;
QueueHandle_t message2=NULL;
uint32_t rec_1 = 0;
uint32_t rec_2 = 0;
uint32_t var = 0;
unsigned char COMPUTER_CONTROL = 0; //电脑接管
int CUR_X=0;
int CUR_Y = 12;//set curlsor
int draw_color = 1;
int i = 0;
int data_k = 0;
uint32_t snid;
extern "C" uint8_t myfont1[];
char cmd[20];
int cmd_k = 0; //cmd count
int m_cmd = 0;
char buff[1024] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0xff,0xfe,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xf8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x1f,0xff,0xff,0xff,0xff,0xff,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,
0xf8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x1f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xf0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x00,0x00,0x00,0x00,0x00,0x00,
0x07,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0x80,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc0,0x00,0x00,0x00,0x00,0x00,
0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xf0,0x00,0x00,0x00,0x00,0x00,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf8,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xf8,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf8,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf8,0x00,0x00,0x00,0x00,0x00,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xf0,0x00,0x00,0x00,0x00,0x00,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf0,0x00,0x00,0x00,0x00,0x00,
0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x1f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x80,0x00,0x00,0x00,0x00,0x00,
0x07,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf8,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xff,0xff,0xff,0xff,0xfe,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0xff,0xff,0xff,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xf8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
/*-------------------------------OLED---------*/
void Oled()
{
while(1)
{
if(COMPUTER_CONTROL == 0){
emo_class();
Show_Time();
weather_class();
}
if(xQueueReceive(message1,&rec_1,0)){
ndelay_interupt = 0;
stop_sign = 0;
if(rec_1 == 'e' )
{
Serial.println("MSG emo");
emo_class();
}
else if(rec_1 == 's' )
{
Serial.println("MSG string");
draw_string(cmd);
}
else if(rec_1 == 'w' )
{
Serial.println("MSG weatherData");
PlayWeatherAndDate();
}
else if(rec_1 == 'd')
{
Serial.println("msg display");
drawImage();
}
}//queuemessage end
// delay(1);
}//while end
vTaskDelete(NULL);
}
/*-------------------------------msg_process---------*/
void msg_Process(char * cmd){
if(cmd[1] == 'I') //send imag data
{
Serial.print("recv I");
i = 1024;
}
else if(cmd[1] == 'D') //display imag data
{
Serial.print("recv D");
m_cmd = 'd';
ndelay_interupt = 1;
var = xQueueSend(message1,&m_cmd,0);
}
else if(cmd[1] == '5') //show str
{
Serial.print("recv 5");
cmd[cmd_k-2] =0;
m_cmd = 's';
ndelay_interupt = 1;
var = xQueueSend(message1,&m_cmd,0);
}
else if(cmd[1] == 'W') //play weather
{
Serial.print("recv 4");
m_cmd = 'w';
ndelay_interupt = 1;
var = xQueueSend(message1,&m_cmd,0);
//PlayWeatherAndDate();
}
else if(cmd[1] =='E') //play emo
{
Serial.print("recv 3");
m_cmd = 'e';
ndelay_interupt =1;
var = xQueueSend(message1,&m_cmd,0);
//emo_class();
}
else if(cmd[1] == 'T') //show Time
{
}
else
{
Serial.println("no cmd");
}
//command select
if(strcmp(cmd,"weather")==0) //4
{
Serial.println("play weather");
m_cmd = 'w';
ndelay_interupt = 1;
var = xQueueSend(message1,&m_cmd,0);
//PlayWeatherAndDate();
}
else if(strcmp(cmd,"emo") == 0) //3
{
Serial.println("play emo");
m_cmd = 'e';
ndelay_interupt = 1;
var = xQueueSend(message1,&m_cmd,0);
//emo_class();
}
//command end
}
/*-------------------------------ASR---------*/
//{speak:娇娇-邻家女声,vol:10,speed:10,platform:haohaodada}
//{playid:10001,voice:天问五幺唤醒我。}
//{playid:10002,voice:记得叫醒我哦}
//{ID:0,keyword:"唤醒词",ASR:"天问五幺",ASRTO:"哎 我在"}
void ASR_CODE()
{
//emo_tst(&u8g2);
//{ID:500,keyword:"唤醒词",ASR:"小鹿同学",ASRTO:"哎 我在呢"}
//{ID:501,keyword:"唤醒词",ASR:"小鹿小鹿",ASRTO:"哎"}
//{ID:506,keyword:"命令词",ASR:"关灯",ASRTO:"好的"}
if(snid == 503){
}
//{ID:505,keyword:"命令词",ASR:"开灯",ASRTO:"好的"}
else if(snid == 505){
//luxiaoban_digital_write(0,0);
Serial.println("开灯");
digitalWrite(4,1);
}
if(snid == 506){
Serial.println("关灯");
digitalWrite(4,0);
//luxiaoban_digital_write(0,1);
}
//{ID:1,keyword:"命令词",ASR:"开机",ASRTO:"好的"}
else if(snid == 1){
Serial.println("开机");
//luxiaoban_digital_write(0,1);
}
//{ID:2,keyword:"命令词",ASR:"关机",ASRTO:"好的"}
else if(snid == 2){
Serial.println("关机");
//luxiaoban_digital_write(0,1);
}
//{ID:3,keyword:"命令词",ASR:"播放音乐",ASRTO:"好的"}
else if(snid == 3){
Serial.println("播放音乐");
}
//{ID:4,keyword:"命令词",ASR:"天气",ASRTO:"好的"}
else if(snid == 4){
Serial.println("weather");
//luxiaoban_digital_write(0,1);
}
//{ID:5,keyword:"命令词",ASR:"时间",ASRTO:"好的"}
else if(snid == 5){
Serial.println("时间");
//luxiaoban_digital_write(0,1);
}
}
char schar;
void process() //serial process
{
while(1)
{
while(Serial.available()> 0 )
{
COMPUTER_CONTROL = 1;
schar = Serial.read();
//Serial.println(schar); //important?
if(i != 0) { //recive data
buff[data_k] = schar;
data_k = data_k + 1;
i = i -1;
cmd_k = 0;
Serial.print("i = ");
Serial.print(i);
}
else{
cmd[cmd_k] = schar;
cmd_k = cmd_k +1;
if(cmd[cmd_k-1] == '\n')
{
cmd[cmd_k-1] = 0;
Serial.println(cmd); //IMPORTANT?
//draw_string(cmd);
//接收协议 M开头 操作码OP 附加信息AD M结尾
//OP = 0 命令 1 数据
//AD OP =1 数据长度
if(cmd[0]== 'M' & cmd[cmd_k-2]=='M' )
{
Serial.println("in xiyi");
Serial.println(cmd[1]);
msg_Process(cmd);
} // end cmd[0]== 'M'
cmd_k = 0;
} //end '\n'
} //end if i !=0
} //end Serial.Avalible
delay(2); // important error no recv
}//end while(1)
vTaskDelete(NULL);
}
//创建线程
void hardware_init(){
message1=xQueueCreate(5,4);
message2=xQueueCreate(5,4);
xTaskCreate(process,"process",256,NULL,4,NULL);
xTaskCreate(Oled,"oled",256,NULL,4,NULL);
vTaskDelete(NULL);
}
void emo_class()
{
ndelay_interupt = 0;
int draw_color = 1;
u8g2c.setFont(myfont1);
u8g2c.setColorIndex(draw_color);
for(int m = 0;m<1;m++)
{ int k = 0;
for(int i = 0;i<30;i++)
{
u8g2c.clearBuffer();
u8g2c.drawGlyph(34,60,96+k%6);
if(ndelay(100))
return ;
u8g2c.sendBuffer();
k = k+1;
}
}
// vTaskDelete(NULL);
}
void weather_class(void)
{
//天气
ndelay_interupt = 0;
int draw_color = 1;
u8g2c.setColorIndex(draw_color);
u8g2c.setFont(u8g2_font_open_iconic_weather_6x_t);
for(int m = 0;m<5;m++)
{ int k = 0;
for(int i = 0 ;i<5;i ++)
{
u8g2c.clearBuffer();
u8g2c.drawGlyph(30,60,65+k%5);
if(ndelay(100))
return ;
u8g2c.sendBuffer();
k = k+1;
// Serial.print(k);
k = k+1;
}
}
}
void Show_Time()
{
u8g2c.setColorIndex(draw_color);
u8g2c.setFont(u8g2_font_tenfatguys_tn);
u8g2c.clearBuffer();
u8g2c.drawStrX2(20,40,"11:20");
if(ndelay(100))
return ;
u8g2c.sendBuffer();
}
void setup()
{
//Serial 0
setPinFun(13,SECOND_FUNCTION);
setPinFun(14,SECOND_FUNCTION);
Serial.begin((9600));
Serial.println("setup");
//u8g2 初始化
// u8g2Init(&u8g2);
u8g2c.u8g2_init();
pinMode(20,output); //pc4
pinMode(4,output); //pa4
setPinFun(4,FIRST_FUNCTION);
xTaskCreate(hardware_init,"hardware_init",256,NULL,100,NULL);
}
void PlayWeatherAndDate()
{
unsigned char r = 0;
for(int i = 0;i<100;i ++)
{
r = r % 40;
u8g2c.setColorIndex(draw_color);
u8g2c.clearBuffer();
u8g2c.setFont(u8g2_font_8x13B_tf);
u8g2c.drawStr(40,60, "12月20日");
u8g2c.setFont(u8g2_font_open_iconic_weather_4x_t);
u8g2c.drawGlyph(65,40,65);
u8g2c.drawCircle(30,30,r );
u8g2c.sendBuffer();
if(ndelay(10))
return ;
r = r+1;
}
}
//draw string
void draw_string(const char *s) {
// assign default color value
int draw_color = 1;
u8g2c.setColorIndex(draw_color);
u8g2c.setFont(u8g2_font_8x13B_tf);
u8g2c.clearBuffer();
u8g2c.drawStr(0,12, s);
u8g2c.sendBuffer();
if(ndelay(1000))
return ;
}
void interrupt(){
ndelay_interupt = 1;
}
bool ndelay(int wait)
{
int w = wait;
while(w >0)
{
if(ndelay_interupt == 1 )
{
//ndelay_interupt = 0;
stop_sign = 1;
Serial.println("ndelay interrup");
return 1;
}
delay(1);
w= w-1;
}
return 0;
}
void drawImage()
{
u8g2c.drawBitmap(0, 0, 16,64, buff); //right 128/8 X64
u8g2c.sendBuffer();
ndelay(1000);
}
//if(xQueueReceive(message2,&rec_2,0)){
// Serial.println(rec_2);
电脑端PY源码
import serial
import threading
import time
from PIL import Image
import datetime
import json
import requests
img = ''
##with Image.open(r"tst2.png") as im:
## img = im.tobytes()
## im.show()
##print(img)
##img = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\xff\xff\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1f\xff\xff\xff\xff\xff\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x00\x00\x00\x07\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x1f\xff\xff\xff\xff\xff\xff\xff\xc0\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xf0\x00\x00\x00\x00\x00\x00\x01\xff\xff\xff\xff\xff\xff\xff\xff\xfc\x00\x00\x00\x00\x00\x00\x07\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x0f\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00\x00\x00\x00\x00\x1f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xc0\x00\x00\x00\x00\x00?\xff\xff\xff\xff\xff\xff\xff\xff\xff\xe0\x00\x00\x00\x00\x00\x7f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf0\x00\x00\x00\x00\x00\x7f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf0\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x7f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf0\x00\x00\x00\x00\x00\x7f\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf0\x00\x00\x00\x00\x00?\xff\xff\xff\xff\xff\xff\xff\xff\xff\xe0\x00\x00\x00\x00\x00?\xff\xff\xff\xff\xff\xff\xff\xff\xff\xe0\x00\x00\x00\x00\x00\x1f\xff\xff\xff\xff\xff\xff\xff\xff\xff\x80\x00\x00\x00\x00\x00\x07\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x03\xff\xff\xff\xff\xff\xff\xff\xff\xfe\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xf8\x00\x00\x00\x00\x00\x00\x00?\xff\xff\xff\xff\xff\xff\xff\xe0\x00\x00\x00\x00\x00\x00\x00\x0f\xff\xff\xff\xff\xff\xff\xff\x80\x00\x00\x00\x00\x00\x00\x00\x01\xff\xff\xff\xff\xff\xff\xfc\x00\x00\x00\x00\x00\x00\x00\x00\x00?\xff\xff\xff\xff\xff\xe0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\xff\xff\xff\xff\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f\xff\xff\xff\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
print("image len:",len(img))
def get_data(): ##https://baijiahao.baidu.com/s?id=1769484471382177983&wfr=spider&for=pc
now = datetime.datetime.now()
h = int(now.strftime("%M"))
m = int(now.strftime("%M"))
return [h,m]
def get_weather(): ##https://blog.csdn.net/gschen_cn/article/details/131886954
url = 'http://t.weather.sojson.com/api/weather/city/'
response = requests.get(url+'101280101')
d = response.json()
print( d["data"]["forecast"][0]["type"])
pass
##处理信息
def recv_msg(msg):
if msg == '开机':
print("msg is boot")
pass
if msg == '关机':
print("msg is shutdown")
pass
if msg == '播放音乐':
pass
##print(img)
sr = serial.Serial("COM12",9600,timeout = 0.1)
##sr.baudrate = 9600
##sr.bytesize = 8
##sr.parity = 'N'
##sr.stopbits = 1
time.sleep(3)
sr.set_buffer_size(2,2)
def rec_thread():
while(1):
data = ''
if(sr.inWaiting()>0):
print("receive:<------",end = '')
data = sr.read(sr.inWaiting())
print(str(data))
s1 = str(data.decode("gb2312"))
print(s1)
## if(s1 == '开灯\r\n'):
## print("is boot")
## else:
## print("is kaiden")
recv_msg(s1[0:-2])
time.sleep(0.1)
print("receive end//")
def send_imag():
sr.write("MIM\n".encode("utf-8"))
send_num = 256
k = 0;
for i in range(int(len(img)/send_num)+1):
sr.write(img[k:k+send_num])
print("send---->:",img[k:k+send_num])
k = k + send_num
sr.flush()
print("send -----------512")
time.sleep(0.5)
sr.write("MDM\n".encode("utf-8"))
if __name__ == "__main__":
t1 = threading.Thread(target = rec_thread)
t1.start()
get_weather()
while(1):
pass
## a = input("exit:q")
## if(a == 'q'):
## exit()
#### break;
## sr.write((a+'\n').encode("utf-8"))
print("---------")