diff --git a/src/main.cpp b/src/main.cpp index 458c8fd..ff5ced0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,8 +7,8 @@ INA226 ina(Wire); // #include "misakiUTF16FontData.h" #include // ESP32でLovyanGFXを独自設定で利用する場合の設定例 -static constexpr int image_width = 100; -static constexpr int image_height = 172; +static constexpr int image_width = 320; +static constexpr int image_height = 130; int32_t current; uint16_t current_buf[100]; @@ -289,7 +289,7 @@ float Filter(float PreData, float NewData) void DataProcess(void) { InitialDataV = ina.readBusVoltage(); - InitialDataI = ina.readShuntCurrent(); + InitialDataI = ina.readShuntCurrent() - 0.0026f; ProcessedDataV = InitialDataV; ProcessedDataI = abs(InitialDataI); DataPower = ProcessedDataI * ProcessedDataV; @@ -300,15 +300,27 @@ void DataDisplay(void) { DataProcess(); if (ProcessedDataV < 10.0f) - lcd.drawFloat(ProcessedDataV, 4, 160, 58); + { + lcd.setTextColor(0xaa96daU, 0x000000U); + lcd.drawFloat(ProcessedDataV, 4, 10, 140); + } 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) - lcd.drawFloat(DataPower, 4, 160, 174); + { + lcd.setTextColor(0xffffd2U, 0x000000U); + lcd.drawFloat(DataPower, 4, 210, 140); + } 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) @@ -335,13 +347,23 @@ void Graph_DrawCurve(uint16_t *data, uint16_t color) // LCD_BackBuffer_DrawPixel(i, y - 1, color); } } -uint32_t number = 0; +#include +#define LINE_COUNT 1 +uint32_t number = 0; +static std::vector 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) { lcd.init(); - lcd.startWrite(); - lcd.fillScreen(0xFFFFFFU); + // lcd.startWrite(); + lcd.fillScreen(0); // drawGradation(); // lcd.fillScreen(0xFFFFFFU); @@ -366,50 +388,126 @@ void setup(void) // Display configuration checkConfig(); - lcd.setTextColor(0xFFFFFFU, 0x000000U); - lcd.fillScreen(0x000000U); + if (lcd.width() < lcd.height()) + lcd.setRotation(lcd.getRotation() ^ 1); - lcd.setFont(&fonts::Font4); - lcd.setTextDatum(bottom_center); - lcd.drawString("V", 180, 50); - lcd.drawString("A", 180, 108); - lcd.drawString("W", 180, 166); + yoffset = image_height >> 1; + xoffset = image_width >> 1; + point_count = image_width + 1; - InitialDataV = ina.readBusVoltage(); - InitialDataI = ina.readShuntCurrent(); - ProcessedDataV = InitialDataV; - ProcessedDataI = InitialDataI; + for (int i = 0; i < LINE_COUNT; i++) + { + points[i].resize(point_count); + } - lcd.setFont(&fonts::Font6); - lcd.setTextDatum(bottom_right); - DataDisplay(); - lcd.setColorDepth(16); // LCDを16bitカラーモードに設定する。 - lcd.setSwapBytes(true); // バイト順変換を有効にする。 - int len = image_width * image_height; - lcd.setAddrWindow(220, 0, image_width, image_height); // 描画範囲を設定。 + lcd.startWrite(); + lcd.setAddrWindow(0, 0, image_width, image_height); + for (int y = 0; y < image_height; y++) + { + for (int x = 0; x < image_width; x++) + { + 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) { - lcd.setSwapBytes(true); // バイト順変換を有効にする。 - for (size_t i = 0; i < image_width; i++) + static int prev_sec; + static int fps; + ++fps; + int sec = millis() / 1000; + if (prev_sec != sec) { - current_buf[i] = current_buf[i + 1]; - } - 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.setFont(&fonts::Font2); + lcd.setTextColor(0x999999U, 0x000000U); + prev_sec = sec; + lcd.setCursor(10, 10); + lcd.printf("FPS:%03d", fps); + // lcd.drawNumber(fps, 320, 0); + fps = 0; } - // number++; - // if (number == 50) + static int count; + + 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(); - // number = 0; + // current_buf[i] = current_buf[i + 1]; // } + // 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); }