Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.vscode/c_cpp_properties.json
.vscode/extensions.json
.vscode/launch.json
.DS_Store
9 changes: 9 additions & 0 deletions git_rev_macro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import subprocess

revision = (
subprocess.check_output(["git", "rev-parse", "HEAD"])
.strip()
.decode("utf-8")

)
print("'-DGIT_REV=\"%s\"'" % revision[:6])
13 changes: 6 additions & 7 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
//#define CHECKBATTERY

//SCALE CONFIG
#define LINE1 (char*)"FW: 3.0.1"
#define LINE2 (char*)"Built-date(YYYYMMDD): 20251009"
#define LINE3 (char*)"S/N: HDS001" //Serial number
#define LINE1 (char*)"FW: 3.0.2"
#define LINE2 (char*)"Built-date "
#define LINE3 __DATE__ //Serial number
#define VERSION /*version*/ LINE1, /*compile date*/ LINE2, /*sn*/ LINE3
//About info
#define FIRMWARE_VER LINE1
Expand Down Expand Up @@ -61,10 +61,9 @@

#define ACEBUTTON //ACEBUTTON ACEBUTTONT
#define DEBOUNCE 100
#define LONGCLICK 1000
#define DOUBLECLICK 300
#define CLICK 200
#define BUTTON_KEY_DELAY 150
#define LONGPRESS_DELAY 900 // threshold for long press
#define DOUBLECLICK_DELAY 600 // max gap between two clicks
#define CLICK_DELAY 180 // max press time that still counts as a click

//DISPLAY
#define Margin_Top 0 //显示边框
Expand Down
57 changes: 46 additions & 11 deletions include/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ void btnFuncWhileConnectedOn();
void btnFuncWhileConnectedOff();
void autoSleepOn();
void autoSleepOff();
void quickBootOn();
void quickBootOff();

// Top-level menu options
// 1/5 define the 1st level menu
Expand All @@ -74,6 +76,7 @@ Menu menuFlipScreen = { "Flip Screen", NULL, NULL, NULL };
Menu menuTimeOnTop = { "Time On Top", NULL, NULL, NULL };
Menu menuBtnFuncWhileConnected = { "Button with BLE", NULL, NULL, NULL };
Menu menuAutoSleep = { "Auto Sleep", NULL, NULL, NULL };
Menu menuQuickBoot = { "Quick Boot", NULL, NULL, NULL };

// 2/5 define the 2st level menu
#ifdef BUZZER
Expand Down Expand Up @@ -124,7 +127,7 @@ Menu menuTimeOnTopOff = { "Weight On Top", timeOnTopOff, NULL, &menuTimeOnTop };
Menu *timeOnTopMenu[] = { &menuTimeOnTopBack, &menuTimeOnTopOn,
&menuTimeOnTopOff };

// Enable button fucntion while BLE connected
// Enable button function while BLE connected
Menu menuBtnFuncWhileConnectedBack = { "Back", NULL, NULL,
&menuBtnFuncWhileConnected };
Menu menuBtnFuncWhileConnectedOn = { "Enable Buttons", btnFuncWhileConnectedOn,
Expand All @@ -136,11 +139,18 @@ Menu *btnFuncWhileConnectedMenu[] = { &menuBtnFuncWhileConnectedBack,
&menuBtnFuncWhileConnectedOn,
&menuBtnFuncWhileConnectedOff };

// Auto sleep function
Menu menuAutoSleepBack = { "Back", NULL, NULL, &menuAutoSleep };
Menu menuAutoSleepOn = { "Auto Sleep On", autoSleepOn, NULL, &menuAutoSleep };
Menu menuAutoSleepOff = { "Auto Sleep Off", autoSleepOff, NULL, &menuAutoSleep };
Menu *autoSleepMenu[] = { &menuAutoSleepBack, &menuAutoSleepOn, &menuAutoSleepOff };

// Quick boot function(aka no delay when pressing the button to boot the scale)
Menu menuQuickBootBack = { "Back", NULL, NULL, &menuQuickBoot };
Menu menuQuickBootOn = { "Quick Boot On", quickBootOn, NULL, &menuQuickBoot };
Menu menuQuickBootOff = { "Quick Boot Off", quickBootOff, NULL, &menuQuickBoot };
Menu *quickBootMenu[] = { &menuQuickBootBack, &menuQuickBootOn, &menuQuickBootOff };

// Menu menuFactoryBack = { "Back", NULL, NULL, &menuFactory };
// Menu menuCalibrateVoltage = { "Calibrate 4.2v", calibrateVoltage, NULL,
// &menuFactory }; Menu menuFactoryDebug = { "Debug Info", enableDebug, NULL,
Expand All @@ -157,7 +167,7 @@ Menu *mainMenu[] = {
&menuCalibration, &menuWifi,
// &menuWiFiUpdate,
&menuAbout, &menuLogo, &menuHeartbeat, &menuFlipScreen, &menuTimeOnTop,
&menuBtnFuncWhileConnected, &menuAutoSleep,
&menuBtnFuncWhileConnected, &menuAutoSleep, &menuQuickBoot,
//, &menuFactory
};
// &menuHolder1, &menuHolder2, &menuHolder3, &menuHolder4,
Expand All @@ -184,6 +194,7 @@ void linkSubmenus() {
menuTimeOnTop.subMenu = timeOnTopMenu[0];
menuBtnFuncWhileConnected.subMenu = btnFuncWhileConnectedMenu[0];
menuAutoSleep.subMenu = autoSleepMenu[0];
menuQuickBoot.subMenu = quickBootMenu[0];
// menuFactory.subMenu = factoryMenu[0];
}

Expand All @@ -200,6 +211,9 @@ void exitMenu() {
delay(1000);
b_menu = false;
// Optionally reset or perform an exit action
t_menuExitTime = millis();
// Capture the moment when menu exit begins to establish a reference point
// This enables timing-based protection against unintended triggers
}

#ifdef BUZZER
Expand Down Expand Up @@ -389,6 +403,26 @@ void autoSleepOff() {
Serial.println("Autosleep off stored in EEPROM.");
}

void quickBootOn() {
b_quickBoot = true;
actionMessage = "Quick Boot On";
t_actionMessage = millis();
t_actionMessageDelay = 1000;
EEPROM.put(i_addr_quickBoot, b_quickBoot);
EEPROM.commit();
Serial.println("Quick boot on stored in EEPROM.");
}

void quickBootOff() {
b_quickBoot = false;
actionMessage = "Quick Boot Off";
t_actionMessage = millis();
t_actionMessageDelay = 1000;
EEPROM.put(i_addr_quickBoot, b_quickBoot);
EEPROM.commit();
Serial.println("Quick boot off stored in EEPROM.");
}

void calibrate() {
b_menu = false;
b_calibration = true; // 让按钮进入校准状态3
Expand All @@ -401,7 +435,7 @@ void calibrate() {
void calibration(int input) {
if (b_calibration == true) {
bool newDataReady = false;
char *c_calval = (char *)"";
char c_calval[25];
if (i_button_cal_status == 1) {
if (input == 0) {
scale.setSamplesInUse(16);
Expand Down Expand Up @@ -908,17 +942,15 @@ void wifiUpdate() {

void showAbout() {
actionMessage = FIRMWARE_VER;
// actionMessage2 = PCB_VER;
actionMessage2 = LINE3;
b_showAbout = true;
u8g2.setFont(FONT_M);
u8g2.setFont(FONT_S);
u8g2.firstPage();
do {
if (AC(actionMessage.c_str()) < 0)
u8g2.setFont(FONT_S);
// u8g2.drawStr(AC(actionMessage.c_str()), AM() - 12,
// actionMessage.c_str()); u8g2.drawStr(AC(actionMessage2.c_str()), AM() +
// 12, actionMessage2.c_str());
u8g2.drawStr(AC(actionMessage.c_str()), AM(), actionMessage.c_str());
u8g2.setFont(FONT_S);
u8g2.drawStr(AC(actionMessage.c_str()), AM() - 24, actionMessage.c_str());
u8g2.drawStr(AC(actionMessage2.c_str()), AM(), actionMessage2.c_str());
u8g2.drawStr(AC(GIT_REV), AM()+ 24, GIT_REV);
} while (u8g2.nextPage());
#ifdef BUZZER
buzzer.off();
Expand Down Expand Up @@ -1122,6 +1154,9 @@ void selectMenu() {
} else if (currentSelection == &menuAutoSleep) {
currentMenu = autoSleepMenu;
currentMenuSize = getMenuSize(autoSleepMenu);
} else if (currentSelection == &menuQuickBoot) {
currentMenu = quickBootMenu;
currentMenuSize = getMenuSize(quickBootMenu);
}
// else if (currentSelection == &menuFactory) {
// currentMenu = factoryMenu;
Expand Down
36 changes: 34 additions & 2 deletions include/parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,37 @@ float f_filtered_temperature = 0;
bool b_ads1115InitFail = true; //ads1115 not detected flag
bool b_wifiOnBoot = false;
bool b_autoSleep = true;

bool b_quickBoot = false;
unsigned int i_buttonBootDelay = 500;
bool b_showChargingUI = false;

//电子秤参数和计时点
bool b_weight_in_serial = false;
// Enhanced tracking system global variables
static float f_tracking_offset = 0.0; // Current tracking offset
static float f_tracking_target = 0.0; // Current tracking target weight
static unsigned long t_last_tracking_update = 0; // Last tracking update time
static const unsigned long TRACKING_UPDATE_INTERVAL = 5000; // Tracking update interval 5 seconds
static const float TRACKING_THRESHOLD = 0.1; // Tracking stability threshold
static const int i_STABLE_COUNT_THRESHOLD = 5; // Stable count threshold
static const float MAX_TRACKING_ADJUSTMENT = 0.5; // Maximum single adjustment

static unsigned long t_last_status_display = 0;
static const unsigned long STATUS_DISPLAY_INTERVAL = 5000;
static bool b_weight_in_serial = true;

static int i_stable_count = 0; // Stable state counter
static bool b_tracking_enabled = true; // Tracking enable flag
static bool b_tracking_active = false; // Whether tracking is currently active

// Stable output system global variables
static float f_previous_stable_value = 0.0; // Previous stable output value
static float f_current_raw_value = 0.0; // Current raw input value
static float STABLE_OUTPUT_THRESHOLD = 0.1; // Minimum change to update output
static bool b_stable_output_enabled = true; // Stable output enable flag
static unsigned long t_last_stable_change = 0; // Time of last stable change



bool b_negativeWeight = false;

bool b_weight_quick_zero = false; //Tare后快速显示为0优化
Expand Down Expand Up @@ -157,6 +184,10 @@ bool b_extraction = false; //萃取模式标识
int b_mode = 0; //0 = pourover; 1 = espresso;

bool b_menu = false;
unsigned long t_menuExitTime = 0;
// Timestamp recording when the menu exit process started
// Used to implement a protection period preventing unintended operations

bool b_calibration = false; //Calibration flag
bool b_ota = false; //wifi ota flag
int i_calibration = 0; //0 for manual cal, 1 for smart cal
Expand Down Expand Up @@ -221,6 +252,7 @@ int i_addr_timeOnTop = i_addr_screenFlipped + sizeof(b_screenFlipped);
int i_addr_btnFuncWhileConnected = i_addr_timeOnTop + sizeof(b_timeOnTop); //b_btnFuncWhileConnected
int i_addr_enableWifiOnBoot = i_addr_btnFuncWhileConnected + sizeof(b_btnFuncWhileConnected); //b_wifiOnBoot
int i_addr_autoSleep = i_addr_enableWifiOnBoot + sizeof(b_wifiOnBoot);
int i_addr_quickBoot = i_addr_autoSleep + sizeof(b_autoSleep);

//int i_addr_enableWifiOnBoot = i_addr_btnFuncWhileConnected + sizeof(b_wifiOnBoot);

Expand Down
24 changes: 13 additions & 11 deletions include/power.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,23 @@ void shut_down_now() {


void shut_down_low_battery(float voltage) {
Serial.print("Low battery, voltage:");
Serial.println(voltage);
refreshOLED((char*)"Low battery", FONT_M);
if (t_batteryRefresh > 0){
Serial.print("Low battery, voltage:");
Serial.println(voltage);
refreshOLED((char*)"Low battery", FONT_M);
#ifdef ESPNOW
if (b_espnow) {
b_power_off = 1;
updateEspnow(1);
}
sendBlePowerOff(3);
if (b_espnow) {
b_power_off = 1;
updateEspnow(1);
}
sendBlePowerOff(3);
#endif
#ifdef BUZZER
buzzer.off();
buzzer.off();
#endif
delay(1000);
esp32_sleep();
delay(1000);
esp32_sleep();
}
}

void shut_down_now_nobeep() {
Expand Down
3 changes: 2 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ data_dir = web_apps

[env:esp32s3]
;-- esp32
platform = https://github.com/pioarduino/platform-espressif32/releases/download/55.03.31/platform-espressif32.zip
platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip
board = esp32-s3-devkitc-1
framework = arduino
#board_build.partitions = <min_spiffs.csv>
Expand All @@ -27,6 +27,7 @@ build_flags =
; -DESP32
-D CONFIG_ASYNC_TCP_RUNNING_CORE=1
-DELEGANTOTA_USE_ASYNC_WEBSERVER=1
!python3 git_rev_macro.py

# -D DEBUG
#
Expand Down
Loading