added CO2 and VOC sensor
This commit is contained in:
110
lcd.cpp
110
lcd.cpp
@@ -36,6 +36,8 @@
|
||||
TFT_eSPI tft = TFT_eSPI();
|
||||
TFT_eSprite needle = TFT_eSprite(&tft); // Sprite object for needle
|
||||
TFT_eSprite spr = TFT_eSprite(&tft); // Sprite for meter reading
|
||||
TFT_eSprite nameSpr = TFT_eSprite(&tft);
|
||||
TFT_eSprite unitSpr = TFT_eSprite(&tft);
|
||||
|
||||
// Jpeg image array attached to this sketch
|
||||
#include "dial.h"
|
||||
@@ -46,6 +48,7 @@ TFT_eSprite spr = TFT_eSprite(&tft); // Sprite for meter reading
|
||||
uint16_t *tft_buffer;
|
||||
bool buffer_loaded = false;
|
||||
uint16_t spr_width = 0;
|
||||
uint16_t name_spr_width = 0;
|
||||
|
||||
void createNeedle(void);
|
||||
void plotNeedle(int16_t angle, uint16_t ms_delay);
|
||||
@@ -99,9 +102,16 @@ void initLCD()
|
||||
spr.pushSprite(DIAL_CENTRE_X - spr_width / 2, DIAL_CENTRE_Y - spr.fontHeight() / 2);
|
||||
|
||||
// Plot the label text
|
||||
tft.setTextColor(TFT_WHITE, bg_color);
|
||||
tft.setTextDatum(MC_DATUM);
|
||||
tft.drawString("(PM2.5 ug/m3)", DIAL_CENTRE_X, DIAL_CENTRE_Y + 48, 2);
|
||||
nameSpr.setTextFont(3);
|
||||
name_spr_width = nameSpr.textWidth("Temperature");
|
||||
nameSpr.createSprite(name_spr_width, nameSpr.fontHeight() * 2 + 2);
|
||||
nameSpr.fillSprite(bg_color);
|
||||
nameSpr.setTextColor(TFT_WHITE, bg_color);
|
||||
nameSpr.setTextDatum(MC_DATUM);
|
||||
nameSpr.setTextPadding(name_spr_width);
|
||||
nameSpr.drawString("Sensor Name", name_spr_width / 2, nameSpr.fontHeight() / 2);
|
||||
nameSpr.drawString("Unit", name_spr_width / 2, nameSpr.fontHeight() / 2 * 3 + 2); nameSpr.pushSprite(DIAL_CENTRE_X - name_spr_width / 2, DIAL_CENTRE_Y + 40, 2);
|
||||
nameSpr.pushSprite(DIAL_CENTRE_X - name_spr_width / 2, DIAL_CENTRE_Y + 40, 2);
|
||||
|
||||
// Define where the needle pivot point is on the TFT before
|
||||
// creating the needle so boundary calculation is correct
|
||||
@@ -120,11 +130,101 @@ void initLCD()
|
||||
// =======================================================================================
|
||||
// Loop
|
||||
// =======================================================================================
|
||||
enum DISPLAY_STATE
|
||||
{
|
||||
DISPLAY_PM1P0,
|
||||
DISPLAY_PM2P5,
|
||||
DISPLAY_PM10P0,
|
||||
DISPLAY_TEMP,
|
||||
DISPLAY_HUM,
|
||||
DISPLAY_CO2,
|
||||
DISPLAY_LAST
|
||||
};
|
||||
|
||||
DISPLAY_STATE displaystate = DISPLAY_PM1P0;
|
||||
uint32_t display_last_update = 0;
|
||||
|
||||
#define MAXGUAGE 240
|
||||
#define MINGUAGE 0
|
||||
#define DISPLAY_ROTATE 10 //sec
|
||||
|
||||
void handleLCD()
|
||||
{
|
||||
static uint32_t value;
|
||||
static uint16_t angle;
|
||||
DISPLAY_STATE displaystate_next = DISPLAY_PM1P0;
|
||||
sensor_e nextSensor = AE_1P0;
|
||||
|
||||
switch (displaystate)
|
||||
{
|
||||
case DISPLAY_PM1P0:
|
||||
{
|
||||
nextSensor = AE_1P0;
|
||||
displaystate_next = DISPLAY_PM2P5;
|
||||
}
|
||||
break;
|
||||
case DISPLAY_PM2P5:
|
||||
{
|
||||
nextSensor = AE_2P5;
|
||||
displaystate_next = DISPLAY_PM10P0;
|
||||
}
|
||||
break;
|
||||
case DISPLAY_PM10P0:
|
||||
{
|
||||
nextSensor = AE_10P0;
|
||||
displaystate_next = DISPLAY_TEMP;
|
||||
}
|
||||
break;
|
||||
case DISPLAY_TEMP:
|
||||
{
|
||||
nextSensor = SCD30_temp;
|
||||
displaystate_next = DISPLAY_HUM;
|
||||
}
|
||||
break;
|
||||
case DISPLAY_HUM:
|
||||
{
|
||||
nextSensor = SCD30_hum;
|
||||
displaystate_next = DISPLAY_CO2;
|
||||
}
|
||||
break;
|
||||
case DISPLAY_CO2:
|
||||
{
|
||||
nextSensor = SCD30_hum;
|
||||
displaystate_next = DISPLAY_PM1P0;
|
||||
}
|
||||
break;
|
||||
|
||||
case DISPLAY_LAST:
|
||||
default:
|
||||
{
|
||||
displaystate_next = DISPLAY_PM1P0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
//rotate display
|
||||
uint32_t timenow = millis();
|
||||
if (timenow - display_last_update > (DISPLAY_ROTATE * 1000))
|
||||
{
|
||||
displaystate = displaystate_next;
|
||||
display_last_update = timenow;
|
||||
Serial.println("LCD next State");
|
||||
}
|
||||
//calculate value to angle
|
||||
uint16_t angle = map(getLCDvalue(),0,50,0,240);
|
||||
plotNeedle(angle,15, getLCDvalue());
|
||||
|
||||
AQSSensor *sensor = getSensor(nextSensor);
|
||||
if (sensor == NULL)
|
||||
{
|
||||
Serial.println("LCD: getSensor=NULL!");
|
||||
return;
|
||||
}
|
||||
|
||||
angle = map(value, sensor->getMin(), sensor->getMax(), MINGUAGE, MAXGUAGE);
|
||||
|
||||
plotNeedle(angle, 15, value);
|
||||
|
||||
nameSpr.drawString(sensor->getName().c_str(), name_spr_width / 2, nameSpr.fontHeight() / 2);
|
||||
nameSpr.drawString(sensor->getUnit().c_str(), name_spr_width / 2, nameSpr.fontHeight() / 2 * 3 + 2);
|
||||
nameSpr.pushSprite(DIAL_CENTRE_X - name_spr_width / 2, DIAL_CENTRE_Y + 40, 2);
|
||||
}
|
||||
|
||||
// =======================================================================================
|
||||
|
||||
Reference in New Issue
Block a user