Files
player/Project/Src/MyWinApp/mywin_demo.c
andy 045cff4cc6 整理代码
1.解决一些编译警告
2.发现png因为文件api不支持而不能使用
2025-10-18 13:58:40 +08:00

281 lines
7.0 KiB
C

#include "mywin_demo.h"
#include "avi.h"
#include "dac.h"
#include "ff.h"
#include "flash_manager.h"
#include "lcd_pwm.h"
#include "mp3play.h"
#include "mylua.h"
#include "mywin_inc.h"
#include "system_file.h"
#include "system_updata.h"
#include "mywin_user_home.h"
#include "mywin_user_stat.h"
#include "mywin_user_status_bar.h"
#include "date.h"
#include "arm_math.h"
#include "fft2d.h"
#include "mywin_user_lock.h"
#include "mywin_user_animation.h"
/*
*
* 自定义窗口示例文件
*
*/
void baseWin_callback(WIN_WindowStruct *win, WIN_MsgStruct *msg);
// 状态显示的回调函数
void stat_callback(void *t);
void mywin_demo_test(void *t) {
WIN_Init();
int lcd_xsize = WIN_GetWinStruct()->lcd->getLcdSizeX();
int lcd_ysize = WIN_GetWinStruct()->lcd->getLcdSizeY();
ui_setScreenBackLightPower(1);
// mylua_test();
// 状态显示
WIN_StatusBarStruct *statubar = 0;
statubar = WIN_CreatStatusBar(0, 0, 0, 0, lcd_xsize, 20);
WIN_ShowWindow((WIN_WindowStruct *)statubar);
// 主页
WIN_HomeStruct *home = 0;
home = WIN_CreatHome(0, 0, 0, 20, lcd_xsize, lcd_ysize - 20);
WIN_SetBackPicPath((WIN_WindowStruct *)home, "0:/JPG/妹子1.jpg");
WIN_SetWinTitle((WIN_WindowStruct *)home, "home");
WIN_ShowWindow((WIN_WindowStruct *)home);
// 设置回调函数
WIN_SetMsgLoopCallBack(0, baseWin_callback);
while (1) {
WIN_Delay(20);
}
}
// 截图函数
void prtSc(void) {
int lcd_xsize = WIN_GetWinStruct()->lcd->getLcdSizeX();
int lcd_ysize = WIN_GetWinStruct()->lcd->getLcdSizeY();
int buff_size = lcd_xsize * lcd_ysize * 2 + 8;
uint8_t *buff = mymalloc(buff_size);
uint8_t scan = 0x00;
uint8_t gray = 0x10;
uint16_t w = lcd_xsize;
uint16_t h = lcd_ysize;
uint8_t is565 = 0x01;
uint8_t rgb = 0x1b;
buff[0] = scan;
buff[1] = gray;
buff[2] = w;
buff[3] = w >> 8;
buff[4] = h;
buff[5] = h >> 8;
buff[6] = is565;
buff[7] = rgb;
static int num = 1;
FIL *file = mymalloc(sizeof(FIL));
char *file_name = mymalloc(256);
FRESULT ret = FR_OK;
sprintf(file_name, "0:/PIC/%d.pic", num);
num++;
ret = f_open(file, file_name, FA_CREATE_NEW | FA_WRITE);
if (ret == FR_OK) {
uint16_t *imag = (uint16_t *)(buff + 8);
UINT real = 0;
WIN_GetWinStruct()->lcd->getColors(imag, 0, 0, w, h);
ret = f_write(file, buff, buff_size, &real);
if (ret != FR_OK)
while (1)
;
else
MSGBOX_TipsTime(0, "截图已保存", file_name, "确定", 5000);
} else
MSGBOX_TipsTime(0, "文件已存在", file_name, "确定", 5000);
f_close(file);
myfree(file);
myfree(file_name);
myfree(buff);
}
static const char *g_powerOffItem[] = {"重启", "重启到BootLoader"};
static void creat_lock(void *ptr) {
WIN_WindowStruct *win = WIN_GetCurrentWindow();
LOCK_EnterLock("0:/PIC/3.pic");
}
// 基本窗口的消息处理回调,用于处理一些全局消息
/*
全局响应的按键:
短按背光键:
长按开关机键:
长按销毁键:
*/
void baseWin_callback(WIN_WindowStruct *win, WIN_MsgStruct *msg) {
WIN_KeyStruct *k = 0;
static int light = 1;
switch (msg->msg) {
case WIN_MSG_INIT:
break;
case WIN_MSG_KEY:
k = msg->data.p;
if (k->shortPress & KEY_VALUE_LIGHT) {
// 短按背光键
light = !light;
ui_setScreenBackLightPower(light);
} else if (k->shortPress & KEY_VALUE_DES) {
// 通知窗口线程调用函数
WIN_RunInWindow("home", creat_lock, 0);
}
if (k->longPress & KEY_VALUE_HOME) {
// 长按关机键
int index = MSGBOX_Select((WIN_WindowStruct *)0, "选择关机选项",
(char **)g_powerOffItem, 2, "确定", "取消");
if (index == 0) {
SysFile_SaveSetFile();
NVIC_SystemReset();
} else if (index == 1) {
SysFile_SaveSetFile();
// 重启到iap并且升级 user.app 文件
(*(uint32_t *)0x20000000) = 0xff000003;
NVIC_SystemReset();
}
} // if (k->longPress&KEY_VALUE_HOME)
else if (k->longPress & KEY_VALUE_DES) {
// 长按销毁键
prtSc();
}
break;
case WIN_MSG_CHID:
break;
case WIN_MSG_EXTMSG:
break;
default:
WIN_DefaultMsgLoop(win, msg);
break;
}
}
// 状态显示的回调函数
void stat_callback(void *t) {
WIN_StatStruct *stat = (WIN_StatStruct *)t;
sprintf(stat->txt, "%.1f,%.1f", mem_perused() / 100.0,
exmem_perused() / 100.0);
WIN_SetInvalid((WIN_WindowStruct *)stat);
}
// 傅里叶变换测试
void FFT_Test(WIN_PicStruct *pic_, int t) {
static float32_t *img = 0;
static int xsize = 0;
static int ysize = 0;
static int ttt = 0;
if (ttt < 256)
ttt++;
else
ttt = 0;
// if (img) return;
if (img == 0) {
// 复制一份图像
img = mymalloc(pic_->xsize * pic_->ysize * sizeof(float32_t));
xsize = pic_->xsize;
ysize = pic_->ysize;
for (int i = 0; i < xsize * ysize; i++) {
img[i] = RGB2GRAY(pic_->data[i]);
}
}
FFT2D_Struct fft2d = {0};
if (FFT2D_Init(&fft2d, 512) == 0) {
FFT2D_Rfft(&fft2d, img, xsize, ysize);
for (int i = 0; i < 512; i++) {
for (int j = 0; j < 512; j++) {
if (((i > ttt) && (i < 512 - ttt)) || ((j > ttt) && (j < 512 - ttt))) {
if (!(((i > ttt) && (i < 512 - ttt)) &&
((j > ttt) && (j < 512 - ttt))))
fft2d.imgBuff[i * 512 + j] = 0;
}
}
}
FFT2D_Rifft(&fft2d, 0);
// 复制到输出
for (int i = 0; i < ysize; i++) {
for (int j = 0; j < xsize; j++) {
pic_->data[i * xsize + j] = fft2d.imgBuff[i * 512 + j];
pic_->data[i * xsize + j] = GRAY2RGB(pic_->data[i * xsize + j]);
}
}
}
FFT2D_Delete(&fft2d);
}
// 测试用代码
static void Delete_code(void) {
// LCD_PWMinit(100);
// DAC_UserStruct dac={0};
//
// dac.buff1=mymalloc (256*4);
// dac.buff2=mymalloc (256*4);
// for (int i=0;i<64;i++) dac.buff1[i]=i*4*4;
// for (int i=0;i<64;i++) dac.buff2[i]=1024-i*4*4;
// dac.buff_size=64*4;
// dac.rate=RATE48000;
//
// DAC_NormalInit (&dac);
// FIL *mp3f=mymalloc (sizeof (FIL));
// FILINFO *mp3f_info=malloc (sizeof (FILINFO));
// f_stat ("0:/这条街.mp3",mp3f_info);
// uint8_t *mp3_data=mymalloc (mp3f_info->fsize);
// UINT datasize=0;
// f_open (mp3f,"0:/这条街.mp3",FA_READ);
// f_read (mp3f,mp3_data,mp3f_info->fsize,&datasize);
// mp3_play_song (mp3_data,datasize);
// char txt[50]={0};
// 显示开机动画
// ANIMATION_ShowGifTime (0,"0:/GIF/12.gif",10000);
// 显示开机图片
// loading ();
// 状态栏
// WIN_StatusBarStruct *statubar=0;
// statubar=WIN_CreatStatusBar (0,0,0,0,LCD_GetLcdSizeX(),20);
// STATUSBAR_SetRes (statubar,&res);
// if (ret==0)
// { STATUSBAR_SetBackPic(statubar,&pic);
// pic.data+=pic.xsize*20;//重设图片位置
// }
// WIN_ShowWindow((WIN_WindowStruct*)statubar);
// stat=WIN_CreatStat (0,0,0,LCD_GetLcdSizeY()/2-30,20,60);//左边
// STAT_SetImg (stat,(uint8_t*)gImage_stat_nfc);
// stat=WIN_CreatStat
//(0,0,LCD_GetLcdSizeX()-20,LCD_GetLcdSizeY()/2-30,20,60);//右边
// STAT_SetImg (stat,(uint8_t*)gImage_stat_bluetooth);
// stat=WIN_CreatStat (0,0,LCD_GetLcdSizeX()/2-30,0,60,20);//上边
// stat->TimerCallBack=stat_bet_callback;
// stat->timerId=WIN_CreatTimer ((WIN_WindowStruct *)stat,1000);
// STAT_SetTxt (stat,"示例文字");
}