添加测试用代码

This commit is contained in:
Easy 2022-04-22 13:57:14 +08:00
parent 2ea7fa6c22
commit fe15fa7593
3 changed files with 146 additions and 18 deletions

View File

@ -1,5 +1,9 @@
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 128
#define SCREEN_ROTATION 0
#define DOWNLOADED_IMG "/download.jpg"
#define FULL_FONT 1
// #define FULL_FONT 1
// #define CHINESE_FONT 1
#define BLK_PIN 19
#define BTN_PIN 0
@ -37,15 +41,14 @@ String mqtt_password_value = "";
//);
EspMQTTClient mclient;
if(FULL_FONT==1)
{
#ifdef CHINESE_FONT
#ifdef FULL_FONT
#define AA_FONT_CUBIC "Cubic1112"
}
else
{
#else
#include "cubic_12.h"
}
#endif
#endif
// #include "SPI.h"
#include <TFT_eSPI.h>
@ -125,6 +128,7 @@ void setup() {
// 检测本地配置文件
if( SPIFFS.exists( "/config.json" ) )
{
Serial.println("config.json exist");
fileSystem.openFromFile("/config.json", jsonDocument);
Serial.print("JSON Document is: ");
serializeJson(jsonDocument, Serial);
@ -145,6 +149,7 @@ void setup() {
}else
{
Serial.println("config.json not exist");
tft.fillScreen( TFT_BLACK );
tft.setCursor(0, 0, 1);
tft.println("Connect to DeerEspWiFi, go 192.168.4.1");
@ -213,7 +218,12 @@ void setup() {
serializeJson(jsonDocument, Serial);
Serial.println();
// File root = SPIFFS.open("/");
if(SPIFFS.exists("/config.json")) Serial.print("config.json exists ");
else Serial.print("config.json not exists ");
// File root = SPIFFS.open("/","r");
//
// File file = root.openNextFile();
//
@ -255,7 +265,7 @@ String getParam(String name){
void onConnectionEstablished()
{
Serial.println("connected");
tft.fillScreen(TFT_BLACK);tft.setTextColor(0xFFFF,0x0000);tft.setCursor(0, 0, 1);tft.println("Waiting for messages ...");
tft.fillScreen(TFT_BLACK);tft.setTextColor(0xFFFF,0x0000);tft.setCursor(0, 0, 1);tft.println("Waiting for messages at "+mqtt_topic_value+"...");
mclient.subscribe(mqtt_topic_value+"_text", [] (const String &payload)
{
@ -264,11 +274,13 @@ void onConnectionEstablished()
if (SPIFFS.exists(DOWNLOADED_IMG) == true) TJpgDec.drawFsJpg(0, 0, DOWNLOADED_IMG);
else tft.fillScreen( TFT_BLACK );
#ifdef CHINESE_FONT
#ifdef FULL_FONT
tft.loadFont(AA_FONT_CUBIC);
#else
tft.loadFont(cubic_11);
#endif
#endif
if( payload.length() > 80 ) tft.setTextSize(TXT_SCALE/2);
@ -288,7 +300,10 @@ void onConnectionEstablished()
}
#ifdef CHINESE_FONT
tft.unloadFont();
#endif
show_time(true);
@ -343,9 +358,19 @@ void show_time(bool force)
}
void echo_time( String thetime )
{
if( SCREEN_WIDTH == 128 )
{
tft.setCursor(96, 120, 1);
tft.setTextSize(1);
}
if( SCREEN_WIDTH == 240 )
{
tft.setCursor(180, 210, 1);
tft.setTextSize(2);
}
tft.setTextColor(TFT_WHITE,TFT_BLACK);
tft.println(thetime);

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@ -0,0 +1,103 @@
#define WIFI_SSID "wifi名称"
#define WIFI_PASSWORD "wifi密码"
#define SCREEN_WIDTH 240
#define BEEP_BTN PIN_D0
#define IMG_BTN PIN_D6
#define BEEP_PIN PIN_D8 // 蜂鸣器
#include <ESP8266WiFi.h>
#include <TFT_eSPI.h>
TFT_eSPI tft = TFT_eSPI();
#include <TJpg_Decoder.h>
#include <EasyButton.h>
EasyButton beep_btn(BEEP_BTN);
EasyButton image_btn(IMG_BTN);
void setup() {
Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
beep_btn.begin();
beep_btn.onPressed(beep);
image_btn.begin();
image_btn.onPressed(show_image);
tft.begin();
tft.fillScreen(TFT_BLACK);
tft.setTextColor(0xFFFF,0x0000);tft.setCursor(0, 0, 1);tft.setTextSize(1);tft.println("Init ...");
Serial.println("tft init");
if (!SPIFFS.begin()) {
Serial.println("SPIFFS initialisation failed!");
while (1) yield(); // Stay here twiddling thumbs waiting
}
Serial.println("SPIFFS init");
tft.println("SPIFFS init ...");
if( SCREEN_WIDTH == 128 )
{
TJpgDec.setJpgScale(2);
}
TJpgDec.setSwapBytes(true);
TJpgDec.setCallback(tft_output);
Serial.println("TJpgDec init");
tft.println("TJpgDec init ...");
if( WiFi.status() == WL_CONNECTED )
tft.println("Wifi connected ...");
tft.println("Press button ...");
}
void loop() {
// put your main code here, to run repeatedly:
beep_btn.read();
image_btn.read();
}
void beep()
{
tone(BEEP_PIN, 1000, 100);
if (SPIFFS.exists("/cover.jpeg") == true) {
TJpgDec.drawFsJpg(0, 0, "/cover.jpeg");
}else
{
tft.fillScreen(TFT_BLACK);
}
tft.setCursor(0, 0, 1);
tft.println("beep button Pressed ...");
if( WiFi.status() == WL_CONNECTED )
tft.println("Wifi connected ...");
}
void show_image()
{
if (SPIFFS.exists("/cover.jpeg") == true) {
TJpgDec.drawFsJpg(0, 0, "/cover.jpeg");
}
tft.setCursor(0, 0, 1);
tft.println( "image button Pressed ...");
if( WiFi.status() == WL_CONNECTED )
tft.println("Wifi connected ...");
}
bool tft_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t* bitmap)
{
if ( y >= tft.height() ) return 0;
tft.pushImage(x, y, w, h, bitmap);
return 1;
}