完成初版设计

This commit is contained in:
BoomPC 2024-05-21 02:24:27 +08:00
parent c9186cda7b
commit 370206729a
1 changed files with 143 additions and 45 deletions

View File

@ -7,8 +7,8 @@ INA226 ina(Wire);
// #include "misakiUTF16FontData.h" // #include "misakiUTF16FontData.h"
#include <LovyanGFX.hpp> #include <LovyanGFX.hpp>
// ESP32でLovyanGFXを独自設定で利用する場合の設定例 // ESP32でLovyanGFXを独自設定で利用する場合の設定例
static constexpr int image_width = 100; static constexpr int image_width = 320;
static constexpr int image_height = 172; static constexpr int image_height = 130;
int32_t current; int32_t current;
uint16_t current_buf[100]; uint16_t current_buf[100];
@ -289,7 +289,7 @@ float Filter(float PreData, float NewData)
void DataProcess(void) void DataProcess(void)
{ {
InitialDataV = ina.readBusVoltage(); InitialDataV = ina.readBusVoltage();
InitialDataI = ina.readShuntCurrent(); InitialDataI = ina.readShuntCurrent() - 0.0026f;
ProcessedDataV = InitialDataV; ProcessedDataV = InitialDataV;
ProcessedDataI = abs(InitialDataI); ProcessedDataI = abs(InitialDataI);
DataPower = ProcessedDataI * ProcessedDataV; DataPower = ProcessedDataI * ProcessedDataV;
@ -300,15 +300,27 @@ void DataDisplay(void)
{ {
DataProcess(); DataProcess();
if (ProcessedDataV < 10.0f) if (ProcessedDataV < 10.0f)
lcd.drawFloat(ProcessedDataV, 4, 160, 58); {
lcd.setTextColor(0xaa96daU, 0x000000U);
lcd.drawFloat(ProcessedDataV, 4, 10, 140);
}
else else
lcd.drawFloat(ProcessedDataV, 3, 160, 58); {
lcd.drawFloat(ProcessedDataI, 4, 160, 116); lcd.setTextColor(0xaa96daU, 0x000000U);
lcd.drawFloat(ProcessedDataV, 3, 10, 140);
}
lcd.setTextColor(0xfcbad3U, 0x000000U);
lcd.drawFloat(ProcessedDataI, 4, 110, 140);
if (DataPower < 10.0f) if (DataPower < 10.0f)
lcd.drawFloat(DataPower, 4, 160, 174); {
lcd.setTextColor(0xffffd2U, 0x000000U);
lcd.drawFloat(DataPower, 4, 210, 140);
}
else else
lcd.drawFloat(DataPower, 3, 160, 174); {
// Serial.print(DataPower,5); lcd.setTextColor(0xffffd2U, 0x000000U);
lcd.drawFloat(DataPower, 3, 210, 140);
}
} }
void LCD_BackBuffer_DrawPixel(uint16_t x, uint16_t y, uint16_t color) void LCD_BackBuffer_DrawPixel(uint16_t x, uint16_t y, uint16_t color)
@ -335,13 +347,23 @@ void Graph_DrawCurve(uint16_t *data, uint16_t color)
// LCD_BackBuffer_DrawPixel(i, y - 1, color); // LCD_BackBuffer_DrawPixel(i, y - 1, color);
} }
} }
uint32_t number = 0; #include <vector>
#define LINE_COUNT 1
uint32_t number = 0;
static std::vector<int> points[LINE_COUNT];
static int colors[] = {0xfcbad3U, 0xaa96daU, TFT_BLUE, TFT_CYAN, TFT_MAGENTA, TFT_YELLOW};
static int xoffset, yoffset, point_count;
int getBaseColor(int x, int y)
{
return ((x ^ y) & 3 || ((x - xoffset) & 31 && y & 31) ? TFT_BLACK : ((!y || x == xoffset) ? TFT_DARKGRAY : TFT_DARKGRAY));
}
void setup(void) void setup(void)
{ {
lcd.init(); lcd.init();
lcd.startWrite(); // lcd.startWrite();
lcd.fillScreen(0xFFFFFFU); lcd.fillScreen(0);
// drawGradation(); // drawGradation();
// lcd.fillScreen(0xFFFFFFU); // lcd.fillScreen(0xFFFFFFU);
@ -366,50 +388,126 @@ void setup(void)
// Display configuration // Display configuration
checkConfig(); checkConfig();
lcd.setTextColor(0xFFFFFFU, 0x000000U); if (lcd.width() < lcd.height())
lcd.fillScreen(0x000000U); lcd.setRotation(lcd.getRotation() ^ 1);
lcd.setFont(&fonts::Font4); yoffset = image_height >> 1;
lcd.setTextDatum(bottom_center); xoffset = image_width >> 1;
lcd.drawString("V", 180, 50); point_count = image_width + 1;
lcd.drawString("A", 180, 108);
lcd.drawString("W", 180, 166);
InitialDataV = ina.readBusVoltage(); for (int i = 0; i < LINE_COUNT; i++)
InitialDataI = ina.readShuntCurrent(); {
ProcessedDataV = InitialDataV; points[i].resize(point_count);
ProcessedDataI = InitialDataI; }
lcd.setFont(&fonts::Font6); lcd.startWrite();
lcd.setTextDatum(bottom_right); lcd.setAddrWindow(0, 0, image_width, image_height);
DataDisplay(); for (int y = 0; y < image_height; y++)
lcd.setColorDepth(16); // LCDを16bitカラーモードに設定する。 {
lcd.setSwapBytes(true); // バイト順変換を有効にする。 for (int x = 0; x < image_width; x++)
int len = image_width * image_height; {
lcd.setAddrWindow(220, 0, image_width, image_height); // 描画範囲を設定。 lcd.writeColor(getBaseColor(x, y - yoffset), 1);
}
}
lcd.endWrite();
// lcd.setTextColor(0xFFFFFFU, 0x000000U);
// lcd.fillScreen(0x000000U);
lcd.setFont(&fonts::Font2);
lcd.setTextDatum(top_left);
lcd.setTextColor(0xaa96daU, 0x000000U);
lcd.drawString("V", 90, 145);
lcd.setTextColor(0xfcbad3U, 0x000000U);
lcd.drawString("A", 190, 145);
lcd.setTextColor(0xffffd2U, 0x000000U);
lcd.drawString("W", 290, 145);
// InitialDataV = ina.readBusVoltage();
// InitialDataI = ina.readShuntCurrent();
// ProcessedDataV = InitialDataV;
// ProcessedDataI = InitialDataI;
// lcd.setFont(&fonts::Font6);
// // DataDisplay();
// lcd.setColorDepth(16); // LCDを16bitカラーモードに設定する。
// // lcd.setSwapBytes(true); // バイト順変換を有効にする。
// int len = image_width * image_height;
// lcd.setAddrWindow(220, 0, image_width, image_height); // 描画範囲を設定。
} }
void loop(void) void loop(void)
{ {
lcd.setSwapBytes(true); // バイト順変換を有効にする。 static int prev_sec;
for (size_t i = 0; i < image_width; i++) static int fps;
++fps;
int sec = millis() / 1000;
if (prev_sec != sec)
{ {
current_buf[i] = current_buf[i + 1]; lcd.setFont(&fonts::Font2);
} lcd.setTextColor(0x999999U, 0x000000U);
current_buf[image_width - 1] = uint16_t(ina.readShuntCurrent() * 50); prev_sec = sec;
Graph_DrawCurve(current_buf, W); lcd.setCursor(10, 10);
lcd.printf("FPS:%03d", fps);
lcd.writePixels((uint16_t *)rgb565, image_width * image_height); // RGB565の16bit画像データを描画。 // lcd.drawNumber(fps, 320, 0);
for (size_t i = 0; i < image_height * image_width; i++) fps = 0;
{
rgb565[i] = 0;
} }
// number++; static int count;
// if (number == 50)
for (int i = 0; i < LINE_COUNT; i++)
{
points[i][count % point_count] = -uint16_t((ina.readShuntCurrent() - 0.0026f) * 50) + 65;
// points[1][count % point_count] = -uint16_t(ina.readBusVoltage() * 5) + 65;
}
++count;
lcd.startWrite();
int index1 = count % point_count;
for (int x = 0; x < point_count - 1; x++)
{
int index0 = index1;
index1 = (index0 + 1) % point_count;
for (int i = 0; i < LINE_COUNT; i++)
{
int y = points[i][index0];
if (y != points[i][index1])
{
lcd.writePixel(x, y + yoffset, getBaseColor(x, y));
}
}
for (int i = 0; i < LINE_COUNT; i++)
{
int y = points[i][index1];
lcd.writePixel(x, y + yoffset, colors[i]);
}
}
lcd.endWrite();
// lcd.startWrite();
// // lcd.setSwapBytes(true); // バイト順変換を有効にする。
// for (size_t i = 0; i < image_width; i++)
// { // {
// DataDisplay(); // current_buf[i] = current_buf[i + 1];
// number = 0;
// } // }
// current_buf[image_width - 1] = uint16_t(ina.readShuntCurrent() * 50);
// Graph_DrawCurve(current_buf, W);
// lcd.writePixels((uint16_t *)rgb565, image_width * image_height); // RGB565の16bit画像データを描画。
// for (size_t i = 0; i < image_height * image_width; i++)
// {
// rgb565[i] = 0;
// }
// lcd.endWrite();
number++;
if (number == 100)
{
lcd.setFont(&fonts::Font4);
DataDisplay();
number = 0;
}
// delay(100); // delay(100);
} }