Skip to content

Commit

Permalink
Guardando cambios locales antes de la actualización
Browse files Browse the repository at this point in the history
  • Loading branch information
Coscolin committed Feb 21, 2024
2 parents da2d594 + f01a523 commit 230343b
Show file tree
Hide file tree
Showing 14 changed files with 729 additions and 201 deletions.
34 changes: 34 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE/dev_pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

# What does this implement/fix?

<!-- Quick description and explanation of changes -->

## Types of changes

- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Other

**Related issue or feature (if applicable):** fixes <link to issue>

## Test Environment

- [ ] TTGO T-Display
- [ ] TTGO T-Display Sandwich
- [ ] ESP8266T-Display S3
- [ ] Other (specify)

## Checklist:
- [ ] The code change is tested and works locally.

If platfomio.ini or preferences are added/changed:
- [ ] Add explanation
8 changes: 2 additions & 6 deletions .github/workflows/release3.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release V2.3
name: Release V2.4

# # # # # # # # # # #
# To create new release, just push a new tag with the format v* (v1.0, v2.0, v2.1, v2.2, etc)
Expand Down Expand Up @@ -48,11 +48,7 @@ jobs:
strategy:
matrix:
# environment: ${{ fromJSON(needs.get_default_envs.outputs.environments) }}
environment: [esp32dev, esp32dev_OLED, TTGO_TDISPLAY, TTGO_TDISPLAY_SANDWICH, TDISPLAY_S3]
# environment: [TDISPLAY_S3]
# environment: [TTGO_TDISPLAY_SANDWICH]
# environment: [esp32dev, esp32dev-sandwich]
# environment: [esp32dev-sandwich]
environment: [esp32dev, esp32dev_OLED, TTGO_TDISPLAY, TTGO_TDISPLAY_SANDWICH, TDISPLAY_S3, esp32dev_ST7789_240x320]

env:
CHIP_FAMILY: ${{ matrix.environment == 'TDISPLAY_S3' && 'ESP32-S3' || 'ESP32' }}
Expand Down
70 changes: 61 additions & 9 deletions CO2_Gadget.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@
#endif
/*****************************************************************************************************/

// Functions and enum definitions
void reverseButtons(bool reversed);
void outputsLoop();

// Define enum for toneBuzzerBeep
enum ToneBuzzerBeep {
BUZZER_TONE_LOW = 300,
BUZZER_TONE_MED = 1000,
BUZZER_TONE_HIGH = 2000
};

// Define enum for durationBuzzerBeep
enum DurationBuzzerBeep {
DURATION_BEEP_SHORT = 50,
DURATION_BEEP_MEDIUM = 150,
DURATION_BEEP_LONG = 300
};

// Next data always defined to be able to configure in menu
String hostName = UNITHOSTNAME;
String rootTopic = UNITHOSTNAME;
Expand All @@ -25,7 +43,6 @@ String mqttUser = "";
String mqttPass = "";
String wifiSSID = WIFI_SSID_CREDENTIALS;
String wifiPass = WIFI_PW_CREDENTIALS;
String mDNSName = "Unset";
String MACAddress = "Unset";
uint8_t peerESPNowAddress[] = ESPNOW_PEER_MAC_ADDRESS;

Expand Down Expand Up @@ -57,10 +74,18 @@ bool displayShowCO2 = true;
bool displayShowPM25 = true;
bool debugSensors = false;
bool inMenu = false;
bool shouldWakeUpDisplay = false;
uint16_t measurementInterval = 10;
bool bleInitialized = false;
int8_t selectedCO2Sensor = -1;
bool outputsModeRelay = false;

// Variables for buzzer functionality
bool buzzerBeeping = false;
uint16_t toneBuzzerBeep = BUZZER_TONE_MED;
uint16_t durationBuzzerBeep = DURATION_BEEP_MEDIUM;
int16_t timeBetweenBuzzerBeeps = -1;

uint8_t channelESPNow = 1;
uint16_t boardIdESPNow = 0;
uint64_t timeInitializationCompleted = 0;
Expand Down Expand Up @@ -129,10 +154,6 @@ uint16_t co2RedRange = 1000;

Stream& miSerialPort = Serial;

// Functions and enum definitions
void reverseButtons(bool reversed);
void outputsLoop();

enum notificationTypes { notifyNothing,
notifyInfo,
notifyWarning,
Expand All @@ -143,9 +164,6 @@ bool displayNotification(String notificationText, String notificationText2, noti
bool displayNotification(String notificationText, String notificationText2, notificationTypes notificationType) { return true; }
bool displayNotification(String notificationText, notificationTypes notificationType) { return true; }
#endif
#if defined(SUPPORT_OLED) || defined(SUPPORT_TFT)
// void setDisplayBrightness(uint32_t newBrightness);
#endif

/*****************************************************************************************************/
/********* *********/
Expand Down Expand Up @@ -240,6 +258,13 @@ uint16_t batteryFullyChargedMillivolts = 4200; // Voltage of battery when it is
#include "CO2_Gadget_TFT.h"
#endif

/*****************************************************************************************************/
/********* *********/
/********* INCLUDE BUZZER FUNCIONALITY *********/
/********* *********/
/*****************************************************************************************************/
#include "CO2_Gadget_Buzzer.h"

/*****************************************************************************************************/
/********* *********/
/********* INCLUDE MENU FUNCIONALITY *********/
Expand All @@ -260,6 +285,16 @@ uint16_t batteryFullyChargedMillivolts = 4200; // Voltage of battery when it is
static int64_t lastReadingsCommunicationTime = 0;
static int startCheckingAfterUs = 1900000;

void wakeUpDisplay() {
if (actualDisplayBrightness == 0) {
#if defined(SUPPORT_OLED) || defined(SUPPORT_TFT)
setDisplayBrightness(DisplayBrightness);
#endif
lastTimeButtonPressed = millis();
}
return;
}

void processPendingCommands() {
if (pendingCalibration == true) {
if (calibrationValue != 0) {
Expand Down Expand Up @@ -341,6 +376,7 @@ void outputsLoop() {
outputsRelays();
outputsRGBLeds();
neopixelLoop();
buzzerLoop();
}

void readingsLoop() {
Expand Down Expand Up @@ -370,6 +406,21 @@ void readingsLoop() {
void adjustBrightnessLoop() {
#if defined(SUPPORT_OLED) || defined(SUPPORT_TFT)

if (shouldWakeUpDisplay) {
wakeUpDisplay();
shouldWakeUpDisplay = false;
}

// If battery pin not connected, assume it's working on external power
if (battery_voltage < 1) {
workingOnExternalPower = true;
}

if (inMenu) {
setDisplayBrightness(DisplayBrightness);
return;
}

// Display backlight IS sleeping
if ((actualDisplayBrightness == 0) && (actualDisplayBrightness != DisplayBrightness)) {
if ((!displayOffOnExternalPower) && (workingOnExternalPower)) {
Expand All @@ -391,7 +442,7 @@ void adjustBrightnessLoop() {
return;
}

if ((actualDisplayBrightness != 0) && (millis() - lastTimeButtonPressed >= timeToDisplayOff * 1000)) {
if ((actualDisplayBrightness != 0) && (millis() - lastTimeButtonPressed >= timeToDisplayOff * 1000) && DisplayBrightness > 0) {
Serial.println("-->[MAIN] Turning off display to save power. Actual brightness: " + String(actualDisplayBrightness));
turnOffDisplay();
}
Expand Down Expand Up @@ -471,6 +522,7 @@ void setup() {
initBattery();
initGPIO();
initNeopixel();
initBuzzer();
#if defined(SUPPORT_OLED) || defined(SUPPORT_TFT)
initDisplay();
#endif
Expand Down
4 changes: 1 addition & 3 deletions CO2_Gadget_Buttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ Button2 btnDwn(BTN_DWN); // Initialize the down button
void IRAM_ATTR buttonUpISR() {
if (actualDisplayBrightness == 0) // Turn on the display only if it's OFF
{
#if defined(SUPPORT_OLED) || defined(SUPPORT_TFT)
setDisplayBrightness(DisplayBrightness); // Turn on the display at DisplayBrightness brightness
#endif
shouldWakeUpDisplay = true;
lastTimeButtonPressed = millis();
}
}
Expand Down
64 changes: 64 additions & 0 deletions CO2_Gadget_Buzzer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#ifndef CO2_Gadget_Buzzer_h
#define CO2_Gadget_Buzzer_h

/*****************************************************************************************************/
/********* *********/
/********* SETUP BUZZER *********/
/********* *********/
/*****************************************************************************************************/

// #define BUZZER_DEBUG
bool belowRedRange = true;

void beepBuzzer() {
static uint16_t numberOfBeepsLeft = 2;
static uint64_t timeNextBeep = 0;
if (millis() > timeNextBeep) {
if (numberOfBeepsLeft == 0) {
if (timeBetweenBuzzerBeeps > 0) {
timeNextBeep = millis() + timeBetweenBuzzerBeeps * 1000;
} else {
belowRedRange = false;
}
numberOfBeepsLeft = 2;
buzzerBeeping = false;
} else {
#ifdef BUZZER_DEBUG
Serial.printf("[BUZZ] Beeps left: %d. Next beep in: %d sec. Beep duration: %d ms\n", numberOfBeepsLeft, timeBetweenBuzzerBeeps, durationBuzzerBeep);
#endif
tone(BUZZER_PIN, toneBuzzerBeep, durationBuzzerBeep);
timeNextBeep = millis() + durationBuzzerBeep + (durationBuzzerBeep * 1.3);
--numberOfBeepsLeft;
buzzerBeeping = true;
}
}
}

void buzzerLoop() {
#ifdef SUPPORT_BUZZER
if (timeBetweenBuzzerBeeps == -1 || inMenu) { // Inside Menu stop BEEPING
buzzerBeeping = false;
belowRedRange = true;
return;
}

if (co2 > co2RedRange && belowRedRange) {
shouldWakeUpDisplay = true;
beepBuzzer();
} else if (co2 < (co2RedRange - BUZZER_HYSTERESIS))
belowRedRange = true;
#endif
}

void initBuzzer() {
#ifdef SUPPORT_BUZZER
Serial.printf("-->[BUZZ] Initializing Buzzer on GPIO %d...\n", BUZZER_PIN);
pinMode(BUZZER_PIN, OUTPUT);

// LEDC initialization
ledcSetup(0, 5000, 8);
ledcAttachPin(BUZZER_PIN, 0);
#endif
}

#endif
Loading

0 comments on commit 230343b

Please sign in to comment.