first commit

This commit is contained in:
cyy_mac
2026-06-16 08:44:45 +08:00
commit c9d2b90a0b
37 changed files with 2396 additions and 0 deletions

20
test/Makefile Normal file
View File

@@ -0,0 +1,20 @@
CC = arm-linux-gcc
CFLAGS = -Wall -O2 -I ..
COMMON = ../common/device.c ../common/tools.c
.PHONY: all clean
all: test_swipe_static test_image_static test_album_static
test_swipe_static: test_swipe.c ../button/button.c $(COMMON)
$(CC) $(CFLAGS) -static -o $@ test_swipe.c ../button/button.c $(COMMON)
test_image_static: test_image.c ../album/album.c $(COMMON)
$(CC) $(CFLAGS) -static -o $@ test_image.c ../album/album.c $(COMMON)
test_album_static: test_album.c ../desktop/desktop.c ../album/album.c ../button/button.c $(COMMON)
$(CC) $(CFLAGS) -static -o $@ test_album.c ../desktop/desktop.c ../album/album.c ../button/button.c $(COMMON)
clean:
rm -f *_static

12
test/test_album.c Normal file
View File

@@ -0,0 +1,12 @@
#include "../common/device.h"
#include "../desktop/desktop.h"
#include <stdio.h>
int main(void)
{
device_init();
desktop_init();
desktop_run();
device_deinit();
return 0;
}

BIN
test/test_album_static Executable file

Binary file not shown.

45
test/test_image.c Normal file
View File

@@ -0,0 +1,45 @@
#include "../common/device.h"
#include "../album/album.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(void)
{
device_init();
fb_clear();
const char *photos[] = {
"images/photo_1.bmp",
"images/photo_2.bmp",
"images/photo_3.bmp",
};
int photo_count = 3;
album_init(photos, photo_count);
album_show(0);
printf("=== Photo Album Test ===\n");
printf("Swipe LEFT = next, RIGHT = prev\n");
printf("Q to quit.\n\n");
int running = 1;
while (running)
{
int dir = get_touch_dir();
switch (dir)
{
case 3:
printf("LEFT → next photo\n");
album_next();
break;
case 4:
printf("RIGHT → prev photo\n");
album_prev();
break;
}
}
device_deinit();
return 0;
}

BIN
test/test_image_static Executable file

Binary file not shown.

58
test/test_ir.c Normal file
View File

@@ -0,0 +1,58 @@
#include "../common/device.h"
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <termios.h>
#include <string.h>
#include <errno.h>
int main(void)
{
device_init();
int fd = open("/dev/ttySAC1", O_RDWR | O_NOCTTY | O_NONBLOCK);
struct termios opt;
tcgetattr(fd, &opt);
cfsetispeed(&opt, B9600);
cfsetospeed(&opt, B9600);
opt.c_cflag |= (CLOCAL | CREAD);
opt.c_cflag &= ~PARENB; opt.c_cflag &= ~CSTOPB; opt.c_cflag &= ~CSIZE;
opt.c_cflag |= CS8;
opt.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
opt.c_iflag &= ~(IXON | IXOFF | IXANY);
opt.c_oflag &= ~OPOST;
opt.c_cc[VMIN] = 0; opt.c_cc[VTIME] = 0;
tcsetattr(fd, TCSANOW, &opt);
printf("=== IR Raw Test ===\n");
printf("Press IR remote. Ctrl+C to exit.\n");
unsigned char buf[3];
int idx = 0;
while (1)
{
int n = read(fd, buf + idx, 3 - idx);
if (n > 0)
{
printf("read %d bytes: ", n);
int i;
for (i = 0; i < n; i++)
printf("%02X ", buf[idx + i]);
printf("\n");
idx += n;
if (idx == 3)
{
printf(" → GOT 3: %02X %02X %02X\n", buf[0], buf[1], buf[2]);
beep_on(); usleep(100000); beep_off();
idx = 0;
}
}
}
close(fd);
device_deinit();
return 0;
}

BIN
test/test_ir_static Executable file

Binary file not shown.

12
test/test_ir_ui.c Normal file
View File

@@ -0,0 +1,12 @@
#include "../common/device.h"
#include "../ir_app/ir_app.h"
#include <stdio.h>
int main(void)
{
device_init();
ir_app_init();
ir_app_run();
device_deinit();
return 0;
}

67
test/test_swipe.c Normal file
View File

@@ -0,0 +1,67 @@
#include "../common/device.h"
#include "../button/button.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(void)
{
device_init();
fb_clear();
/* Create 2 test buttons */
button_t btn1, btn2;
button_init(&btn1, 200, 300, 160, 80, RGB(255, 255, 255), RGB(0, 0, 0));
button_init(&btn2, 600, 300, 160, 80, RGB(255, 255, 255), RGB(0, 0, 0));
printf("=== Swipe + Button Test ===\n");
printf("Left button = learn toggle, Right button = quit\n");
printf("Swipe left/right to change button color.\n\n");
int running = 1;
while (running)
{
fb_clear();
/* Check swipe */
int dir = get_touch_dir();
switch (dir)
{
case 3:
printf("LEFT swipe\n");
btn1.bg_color = RGB(255, 200, 200);
break;
case 4:
printf("RIGHT swipe\n");
btn1.bg_color = RGB(200, 200, 255);
break;
case 0:
break;
default:
btn1.bg_color = RGB(255, 255, 255);
}
/* Check touch for buttons via ts_read */
int sx, sy, touching;
while (ts_read(&sx, &sy, &touching) > 0)
{
if (touching && button_hit(&btn1, sx, sy))
{
printf("BTN1 pressed\n");
button_set_learned(&btn1, !btn1.learned);
}
if (touching && button_hit(&btn2, sx, sy))
{
printf("BTN2 pressed → quit\n");
running = 0;
}
}
btn1.bg_color = btn1.learned ? RGB(200, 255, 200) : btn1.bg_color;
button_draw(&btn1);
button_draw(&btn2);
}
device_deinit();
return 0;
}

BIN
test/test_swipe_static Executable file

Binary file not shown.