first commit

This commit is contained in:
2025-01-10 15:20:33 +08:00
commit 4f5d2aa650
66 changed files with 15921 additions and 0 deletions

11
TFT-ESP32/test/README Normal file
View File

@ -0,0 +1,11 @@
This directory is intended for PlatformIO Test Runner and project tests.
Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.
More information about PlatformIO Unit Testing:
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html

82
TFT-ESP32/test/test.cpp Normal file
View File

@ -0,0 +1,82 @@
#include <TFT_eSPI.h> // TFT 显示屏库
TFT_eSPI tft = TFT_eSPI(); // 初始化 TFT 实例
const int screenWidth = 240; // 根据你的屏幕分辨率设置
const int screenHeight = 320;
const int byteWidth = (screenWidth + 7) / 8; // 每行需要的字节数
// 数组用于存储二值化后的屏幕数据
uint8_t binaryImage[screenHeight][byteWidth];
// 将屏幕数据读取并二值化,存储到数组中
void binaryScreenToArray()
{
for (int y = 0; y < screenHeight; y++)
{
uint8_t byteValue = 0;
for (int x = 0; x < screenWidth; x++)
{
// 读取像素颜色
uint16_t color = tft.readPixel(x, y);
// 将颜色二值化假设TFT_WHITE为白色其它为黑色
if (color == TFT_WHITE)
{
byteValue |= (1 << (7 - (x % 8))); // 设置当前位为1白色
}
// 每8个像素存储为一个字节
if (x % 8 == 7 || x == screenWidth - 1)
{
binaryImage[y][x / 8] = byteValue;
byteValue = 0;
}
}
}
}
// 将二值化后的屏幕数据通过串口发送到电脑,值之间用逗号隔开
void sendArrayToPC()
{
Serial.println("Start sending binary screen data:");
for (int y = 0; y < screenHeight; y++)
{
for (int x = 0; x < byteWidth; x++)
{
Serial.print(binaryImage[y][x], HEX); // 以十六进制格式发送每个字节
// 如果不是最后一个字节,则添加逗号
if (x < byteWidth - 1)
{
Serial.print(","); // 用逗号分隔
}
}
Serial.println(); // 每行结束后换行
}
Serial.println("Binary screen data sent.");
}
void setup()
{
Serial.begin(115200); // 初始化串口通信
tft.init(); // 初始化屏幕
tft.setRotation(1); // 根据需要设置屏幕的旋转
tft.fillScreen(TFT_BLACK); // 将屏幕设置为黑色
// 绘制一些内容(测试用)
tft.fillCircle(120, 160, 50, TFT_WHITE); // 在屏幕中间绘制一个白色的圆圈
// 读取并二值化屏幕内容
binaryScreenToArray();
// 将二值化后的数组通过串口传输到电脑
sendArrayToPC();
}
void loop()
{
// 主要功能在 setup 中执行loop 中不做任何操作
}

111
TFT-ESP32/test/testmain.cpp Normal file
View File

@ -0,0 +1,111 @@
//<App !Start!>
// FILE: [main.cpp]
// Created by GUIslice Builder version: [0.17.b34]
//
// GUIslice Builder Generated File
//
// For the latest guides, updates and support view:
// https://github.com/ImpulseAdventure/GUIslice
//
//<App !End!>
// ------------------------------------------------
// Headers to include
// ------------------------------------------------
#include "GUIsliceProjects_GSLC.h"
// ------------------------------------------------
// Program Globals
// ------------------------------------------------
// Save some element references for direct access
//<Save_References !Start!>
//<Save_References !End!>
// Define debug message function
static int16_t DebugOut(char ch)
{
if (ch == (char)'\n')
Serial.println("");
else
Serial.write(ch);
return 0;
}
// ------------------------------------------------
// Callback Methods
// ------------------------------------------------
// Common Button callback
bool CbBtnCommon(void *pvGui, void *pvElemRef, gslc_teTouch eTouch, int16_t nX, int16_t nY)
{
// Typecast the parameters to match the GUI and element types
gslc_tsGui *pGui = (gslc_tsGui *)(pvGui);
gslc_tsElemRef *pElemRef = (gslc_tsElemRef *)(pvElemRef);
gslc_tsElem *pElem = gslc_GetElemFromRef(pGui, pElemRef);
if (eTouch == GSLC_TOUCH_UP_IN)
{
// From the element's ID we can determine which button was pressed.
switch (pElem->nId)
{
//<Button Enums !Start!>
case E_ELEM_BTN1:
break;
case E_ELEM_BTN2:
break;
//<Button Enums !End!>
default:
break;
}
}
return true;
}
//<Checkbox Callback !Start!>
//<Checkbox Callback !End!>
//<Keypad Callback !Start!>
//<Keypad Callback !End!>
//<Spinner Callback !Start!>
//<Spinner Callback !End!>
//<Listbox Callback !Start!>
//<Listbox Callback !End!>
//<Draw Callback !Start!>
//<Draw Callback !End!>
//<Slider Callback !Start!>
//<Slider Callback !End!>
//<Tick Callback !Start!>
//<Tick Callback !End!>
void setup()
{
// ------------------------------------------------
// Initialize
// ------------------------------------------------
Serial.begin(9600);
// Wait for USB Serial
// delay(1000); // NOTE: Some devices require a delay after Serial.begin() before serial port can be used
gslc_InitDebug(&DebugOut);
// ------------------------------------------------
// Create graphic elements
// ------------------------------------------------
InitGUIslice_gen();
}
// -----------------------------------
// Main event loop
// -----------------------------------
void loop()
{
// ------------------------------------------------
// Update GUI Elements
// ------------------------------------------------
// TODO - Add update code for any text, gauges, or sliders
// ------------------------------------------------
// Periodically call GUIslice update function
// ------------------------------------------------
gslc_Update(&m_gui);
}