Skip to content

Commit

Permalink
add Stock App and md readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ClimbSnail committed Oct 13, 2022
1 parent 4541042 commit a35670f
Show file tree
Hide file tree
Showing 23 changed files with 2,374 additions and 696 deletions.
1 change: 1 addition & 0 deletions HoloCubic_Firmware/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.pio/
.DS_Store
.vscode/
..VSCodeCounter/
6 changes: 3 additions & 3 deletions HoloCubic_Firmware/lib/lvgl/lv_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ typedef int16_t lv_coord_t;
* The graphical objects and other related data are stored here. */

/* 1: use custom malloc/free, 0: use the built-in `lv_mem_alloc` and `lv_mem_free` */
#define LV_MEM_CUSTOM 0
#define LV_MEM_CUSTOM 1
#if LV_MEM_CUSTOM == 0
/* Size of the memory used by `lv_mem_alloc` in bytes (>= 2kB)*/
# define LV_MEM_SIZE (32U * 1024U)
Expand Down Expand Up @@ -399,7 +399,7 @@ typedef void * lv_indev_drv_user_data_t; /*Type of user data in the i
#define LV_FONT_MONTSERRAT_42 0
#define LV_FONT_MONTSERRAT_44 0
#define LV_FONT_MONTSERRAT_46 0
#define LV_FONT_MONTSERRAT_48 0
#define LV_FONT_MONTSERRAT_48 1

/* Demonstrate special features */
#define LV_FONT_MONTSERRAT_12_SUBPX 0
Expand Down Expand Up @@ -531,7 +531,7 @@ typedef void * lv_font_user_data_t;
#define LV_USE_ARABIC_PERSIAN_CHARS 0

/*Change the built in (v)snprintf functions*/
#define LV_SPRINTF_CUSTOM 0
#define LV_SPRINTF_CUSTOM 1
#if LV_SPRINTF_CUSTOM
# define LV_SPRINTF_INCLUDE <stdio.h>
# define lv_snprintf snprintf
Expand Down
13 changes: 11 additions & 2 deletions HoloCubic_Firmware/src/HoloCubic_AIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "app/weather_old/weather_old.h"
#include "app/anniversary/anniversary.h"
#include "app/heartbeat/heartbeat.h"
#include "app/stockmarket/stockmarket.h"

#include <SPIFFS.h>
#include <esp32-hal.h>
Expand Down Expand Up @@ -127,18 +128,26 @@ void setup()
app_controller->app_install(&game_2048_app);
app_controller->app_install(&anniversary_app);
app_controller->app_install(&heartbeat_app, APP_TYPE_BACKGROUND);
app_controller->app_install(&stockmarket_app);

// 自启动APP
// app_controller->app_auto_start();
app_controller->app_auto_start();
// 优先显示屏幕 加快视觉上的开机时间
app_controller->main_process(&mpu.action_info);

Serial.print(F("lv_port_indev_init: start"));

/*** Init IMU as input device ***/
lv_port_indev_init();
// lv_port_indev_init();

Serial.print(F("lv_port_indev_init: end"));

mpu.init(app_controller->sys_cfg.mpu_order,
app_controller->sys_cfg.auto_calibration_mpu,
&app_controller->mpu_cfg); // 初始化比较耗时

Serial.print(F("mpu.init"));

/*** 以此作为MPU6050初始化完成的标志 ***/
RgbConfig *rgb_cfg = &app_controller->rgb_cfg;
// 初始化RGB灯 HSV色彩模式
Expand Down
12 changes: 6 additions & 6 deletions HoloCubic_Firmware/src/app/bilibili_fans/bilibili.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ static MyHttpResult http_request(String uid = "344470052")
// String url = "http://www.dtmb.top/api/fans/index?id=" + uid;
MyHttpResult result;
String url = FANS_API + uid;
HTTPClient *httpClient = new HTTPClient();
httpClient->setTimeout(1000);
bool status = httpClient->begin(url);
HTTPClient httpClient;
httpClient.setTimeout(1000);
bool status = httpClient.begin(url);
if (status == false)
{
result.httpCode = -1;
return result;
}
int httpCode = httpClient->GET();
String httpResponse = httpClient->getString();
httpClient->end();
int httpCode = httpClient.GET();
String httpResponse = httpClient.getString();
httpClient.end();
result.httpCode = httpCode;
result.httpResponse = httpResponse;
return result;
Expand Down
2 changes: 2 additions & 0 deletions HoloCubic_Firmware/src/app/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void start_web_config()
server.on("/weather_setting", weather_setting);
server.on("/weather_old_setting", weather_old_setting);
server.on("/bili_setting", bili_setting);
server.on("/stock_setting", stock_setting);
server.on("/picture_setting", picture_setting);
server.on("/media_setting", media_setting);
server.on("/screen_setting", screen_setting);
Expand All @@ -54,6 +55,7 @@ void start_web_config()
server.on("/saveWeatherConf", saveWeatherConf);
server.on("/saveWeatherOldConf", saveWeatherOldConf);
server.on("/saveBiliConf", saveBiliConf);
server.on("/saveStockConf", saveStockConf);
server.on("/savePictureConf", savePictureConf);
server.on("/saveMediaConf", saveMediaConf);
server.on("/saveScreenConf", saveScreenConf);
Expand Down
40 changes: 40 additions & 0 deletions HoloCubic_Firmware/src/app/server/web_setting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ String file_size(int bytes)
"<label class=\"input\"><span>数据更新周期(毫秒)</span><input type=\"text\"name=\"updataInterval\"value=\"%s\"></label>" \
"</label><input class=\"btn\" type=\"submit\" name=\"submit\" value=\"保存\"></form>"

#define STOCK_SETTING "<form method=\"GET\" action=\"saveStockConf\">" \
"<label class=\"input\"><span>股票代码,例如:sz000001或sh601126</span><input type=\"text\"name=\"stock_id\"value=\"%s\"></label>" \
"<label class=\"input\"><span>数据更新周期(毫秒)</span><input type=\"text\"name=\"updataInterval\"value=\"%s\"></label>" \
"</label><input class=\"btn\" type=\"submit\" name=\"submit\" value=\"保存\"></form>"

#define PICTURE_SETTING "<form method=\"GET\" action=\"savePictureConf\">" \
"<label class=\"input\"><span>自动切换时间间隔(毫秒)</span><input type=\"text\"name=\"switchInterval\"value=\"%s\"></label>" \
"</label><input class=\"btn\" type=\"submit\" name=\"submit\" value=\"保存\"></form>"
Expand Down Expand Up @@ -173,6 +178,7 @@ void init_page_header()
webpage_header += F("<li><a href='/screen_setting'>屏幕分享</a></li>");
webpage_header += F("<li><a href='/heartbeat_setting'>心跳</a></li>");
webpage_header += F("<li><a href='/anniversary_setting'>纪念日</a></li>");
webpage_header += F("<li><a href='/stock_setting'>股票行情</a></li>");
webpage_header += F("</ul>");
}

Expand Down Expand Up @@ -350,6 +356,24 @@ void bili_setting()
Send_HTML(webpage);
}


void stock_setting()
{
char buf[2048];
char bili_uid[32];
char updataInterval[32];
// 读取数据
app_controller->send_to(SERVER_APP_NAME, "Stock", APP_MESSAGE_READ_CFG,
NULL, NULL);
app_controller->send_to(SERVER_APP_NAME, "Stock", APP_MESSAGE_GET_PARAM,
(void *)"stock_id", bili_uid);
app_controller->send_to(SERVER_APP_NAME, "Stock", APP_MESSAGE_GET_PARAM,
(void *)"updataInterval", updataInterval);
sprintf(buf, STOCK_SETTING, bili_uid, updataInterval);
webpage = buf;
Send_HTML(webpage);
}

void picture_setting()
{
char buf[2048];
Expand Down Expand Up @@ -589,6 +613,22 @@ void saveBiliConf(void)
NULL, NULL);
}

void saveStockConf(void)
{
Send_HTML(F("<h1>设置成功! 退出APP或者继续其他设置.</h1>"));
app_controller->send_to(SERVER_APP_NAME, "Stock",
APP_MESSAGE_SET_PARAM,
(void *)"stock_id",
(void *)server.arg("stock_id").c_str());
app_controller->send_to(SERVER_APP_NAME, "Stock",
APP_MESSAGE_SET_PARAM,
(void *)"updataInterval",
(void *)server.arg("updataInterval").c_str());
// 持久化数据
app_controller->send_to(SERVER_APP_NAME, "Stock", APP_MESSAGE_WRITE_CFG,
NULL, NULL);
}

void savePictureConf(void)
{
Send_HTML(F("<h1>设置成功! 退出APP或者继续其他设置.</h1>"));
Expand Down
15 changes: 10 additions & 5 deletions HoloCubic_Firmware/src/app/server/web_setting.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,31 @@ extern AppController *app_controller; // APP控制器
void init_page_header(void);
void init_page_footer(void);
void HomePage(void);

void File_Download(void);
void File_Upload(void);
void File_Delete(void);
void delete_result(void);
void handleFileUpload(void);

void sys_setting(void);
void rgb_setting(void);
void weather_setting(void);
void weather_old_setting(void);
void bili_setting(void);
void stock_setting(void);
void picture_setting(void);
void media_setting(void);
void screen_setting(void);
void heartbeat_setting(void);
void anniversary_setting(void);
void File_Download(void);
void File_Upload(void);
void File_Delete(void);
void delete_result(void);
void handleFileUpload(void);

void saveSysConf(void);
void saveRgbConf(void);
void saveWeatherConf(void);
void saveWeatherOldConf(void);
void saveBiliConf(void);
void saveStockConf(void);
void savePictureConf(void);
void saveMediaConf(void);
void saveScreenConf(void);
Expand Down
11 changes: 11 additions & 0 deletions HoloCubic_Firmware/src/app/stockmarket/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 股票行情实时查看功能

> 作者:redwolf
> 时间:2022-10-07 12:58
> 修改:
> 功能描述:获取选择的股票的当前价格、最高价格、最低价格、今日开盘价、昨日收盘价、成交量、成交金额等
## 查看股票实时行情
http://hq.sinajs.cn/list= + uid;
71 changes: 71 additions & 0 deletions HoloCubic_Firmware/src/app/stockmarket/get_font.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import re
import sys

re_obj = re.compile(r'/\*\(.+\)\*/')
# re_obj = re.compile(r'[\u4e00-\u9fa5]')
word_set = set()
result = "" # 存放返回的结果


def searchWordByRe(file_name):
global re_obj
global word_set
global result

file_obj = open(file_name, 'r', encoding='utf-8')

try:
text_list = file_obj.readlines()

for line in text_list:
dict_list = re_obj.findall(line)

for font in dict_list:
word = font[3:-3]
if word not in word_set:
# 去重
word_set.add(word)
result = result + word

finally:
file_obj.close()

print(result)


def searchWordByEocode(file_name):
global re_obj
global word_set
global result

file_obj = open(file_name, 'r', encoding='utf-8')

try:
text_list = file_obj.readlines()
for line in text_list:
for word in line:
if u'\u4e00' <= word <= u'\u9fff':
if word not in word_set:
# 去重
word_set.add(word)
result = result + word

finally:
file_obj.close()

print(result)


if __name__ == "__main__":
"""
用法:python get_font.py 字模.c文件的路径
"""

file_name = sys.argv[1]
print(file_name)

searchWordByRe(file_name)
# searchWordByEocode()
Loading

0 comments on commit a35670f

Please sign in to comment.