Skip to content

Commit

Permalink
version 2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
pvvx committed Feb 25, 2021
1 parent c3b89a7 commit a8c7b89
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 11 deletions.
Binary file added ATC_Thermometer24.bin
Binary file not shown.
Binary file added MHO_C401_v24.bin
Binary file not shown.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ You can directly update/flash the firmware without downloading the binaries belo

**Custom Firmware Versions:**

* [LYWSD03MMC Custom Firmware Version 2.3p](https://github.com/pvvx/ATC_MiThermometer/raw/master/ATC_Thermometer23p.bin)
* [MHO-C401 Custom Firmware Version 2.3p](https://github.com/pvvx/ATC_MiThermometer/raw/master/MHO_C401_v23p.bin)
* [LYWSD03MMC Custom Firmware Version 2.4](https://github.com/pvvx/ATC_MiThermometer/raw/master/ATC_Thermometer24.bin)
* [MHO-C401 Custom Firmware Version 2.4](https://github.com/pvvx/ATC_MiThermometer/raw/master/MHO_C401_v24.bin)

**Original Manufacturer Firmware Version**

Expand All @@ -128,6 +128,7 @@ In case you want to go back to the original firmware, you can download them here
| 2.1 | Periodic display refresh for MHO-C401 <br> 'Erase mi-keys' option to return to original firmware
| 2.2 | Added parameter "Encrypted Mi Beacon"
| 2.3 | Added "Delete all records"
| 2.4 | Added parameter "Clock time step"


## Applications
Expand Down
4 changes: 2 additions & 2 deletions TlsrPgm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

##### TlsrPgm.py #####
### Autor: pvvx ###
## https://github.com/pvvx/TLSRPGM ##

import sys
import signal
Expand Down Expand Up @@ -750,10 +751,9 @@ def AnalogRegs825x(self):
#print('ok')
return True
# Test
def TestDebugPC(self, count = 1):
def TestDebugPC(self, count = 1, offset = 0x6bc):
if count < 1:
count = 1
offset = 0x6bc
flgsleep = False
flgrun = False
i = 0
Expand Down
4 changes: 2 additions & 2 deletions firmware.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{"version": 35,
"custom":["ATC_Thermometer23p.bin", "MHO_C401_v23p.bin"],
{"version": 36,
"custom":["ATC_Thermometer24.bin", "MHO_C401_v24.bin"],
"original":["Original_OTA_Xiaomi_LYWSD03MMC_v1.0.0_0109.bin","Original_OTA_Xiaomi_MHO_C401_v1.0.0_0010.bin"]}
13 changes: 11 additions & 2 deletions src/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ RAM uint32_t min_step_time_update_lcd; // = cfg.min_step_time_update_lcd * 0.05

RAM uint32_t utc_time_sec; // clock in sec (= 0 1970-01-01 00:00:00)
RAM uint32_t utc_time_sec_tick;
#if USE_CLOCK && USE_TIME_ADJUST
RAM uint32_t utc_time_tick_step = CLOCK_16M_SYS_TIMER_CLK_1S; // adjust time clock (in 1/16 us for 1 sec)
#else
#define utc_time_tick_step CLOCK_16M_SYS_TIMER_CLK_1S
#endif

RAM scomfort_t cmf;
const scomfort_t def_cmf = {
Expand Down Expand Up @@ -219,6 +224,10 @@ void user_init_normal(void) {//this will get executed one time after power up
memcpy(&cfg, &def_cfg, sizeof(cfg));
if(flash_read_cfg(&cmf, EEP_ID_CMF, sizeof(cmf)) != sizeof(cmf))
memcpy(&cmf, &def_cmf, sizeof(cmf));
#if USE_CLOCK && USE_TIME_ADJUST
if(flash_read_cfg(&utc_time_tick_step, EEP_ID_TIM, sizeof(utc_time_tick_step)) != sizeof(utc_time_tick_step))
utc_time_tick_step = CLOCK_16M_SYS_TIMER_CLK_1S;
#endif
#if BLE_SECURITY_ENABLE
if(flash_read_cfg(&pincode, EEP_ID_PCD, sizeof(pincode)) != sizeof(pincode))
pincode = 0;
Expand Down Expand Up @@ -382,8 +391,8 @@ _attribute_ram_code_ void lcd(void) {
_attribute_ram_code_ void main_loop(void) {
blt_sdk_main_loop();
#if USE_CLOCK || USE_FLASH_MEMO
while(clock_time() - utc_time_sec_tick > CLOCK_16M_SYS_TIMER_CLK_1S) {
utc_time_sec_tick += CLOCK_16M_SYS_TIMER_CLK_1S;
while(clock_time() - utc_time_sec_tick > utc_time_tick_step) {
utc_time_sec_tick += utc_time_tick_step;
utc_time_sec++; // + 1 sec
}
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define EEP_ID_PCD (0xC0DE) // EEP ID pincode
#define EEP_ID_CMF (0x0FCC) // EEP ID comfort data
#define EEP_ID_DVN (0x0DB5) // EEP ID device name
#define EEP_ID_TIM (0x0ADA) // EEP ID time adjust

typedef struct __attribute__((packed)) _cfg_t {
struct __attribute__((packed)) {
Expand Down Expand Up @@ -103,6 +104,9 @@ extern uint32_t chow_tick_sec; // count chow validity time, in sec
#if USE_CLOCK || USE_FLASH_MEMO
extern uint32_t utc_time_sec; // clock in sec (= 0 1970-01-01 00:00:00)
#endif
#if USE_CLOCK && USE_TIME_ADJUST
extern uint32_t utc_time_tick_step; // adjust time clock (in 1/16 us for 1 sec)
#endif

extern uint32_t pincode; // pincode (if = 0 - not used)

Expand Down
3 changes: 2 additions & 1 deletion src/app_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
extern "C" {
#endif

#define VERSION 0x23 // BCD format (0x34 -> '3.4')
#define VERSION 0x24 // BCD format (0x34 -> '3.4')
#define EEP_SUP_VER 0x09 // EEP data minimum supported version

#define DEVICE_LYWSD03MMC 0x055B // LCD display LYWSD03MMC
Expand All @@ -17,6 +17,7 @@ extern "C" {

#define USE_TRIGGER_OUT 1 // use trigger out (GPIO_PA5)
#define USE_CLOCK 1 // = 1 display clock, = 0 smile blinking
#define USE_TIME_ADJUST 1 // = 1 time correction enabled
#define USE_FLASH_MEMO 1 // = 1 flash logger enable

#define USE_DEVICE_INFO_CHR_UUID 1 // = 1 enable Device Information Characteristics
Expand Down
2 changes: 1 addition & 1 deletion src/ble.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ void init_ble(void) {
///////////////////// Power Management initialization///////////////////
blc_ll_initPowerManagement_module();
bls_pm_setSuspendMask(SUSPEND_DISABLE);
blc_pm_setDeepsleepRetentionThreshold(95, 95);
blc_pm_setDeepsleepRetentionThreshold(50, 30);
blc_pm_setDeepsleepRetentionEarlyWakeupTiming(240);
blc_pm_setDeepsleepRetentionType(DEEPSLEEP_MODE_RET_SRAM_LOW32K);
#if USE_NEW_OTA == 0
Expand Down
11 changes: 10 additions & 1 deletion src/cmd_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,18 @@ void cmd_parser(void * p) {
if(--len > sizeof(utc_time_sec)) len = sizeof(utc_time_sec);
if(len)
memcpy(&utc_time_sec, &req->dat[1], len);
// send_buf[0] = CMD_ID_UTC_TIME;
memcpy(&send_buf[1], &utc_time_sec, sizeof(utc_time_sec));
olen = sizeof(utc_time_sec) + 1;
#if USE_TIME_ADJUST
} else if (cmd == CMD_ID_TADJUST) { // Get/set adjust time clock delta (in 1/16 us for 1 sec)
if(len > 2) {
int16_t delta = req->dat[1] | (req->dat[2] << 8);
utc_time_tick_step = CLOCK_16M_SYS_TIMER_CLK_1S + delta;
flash_write_cfg(&utc_time_tick_step, EEP_ID_TIM, sizeof(utc_time_tick_step));
}
memcpy(&send_buf[1], &utc_time_tick_step, sizeof(utc_time_tick_step));
olen = sizeof(utc_time_tick_step) + 1;
#endif
#endif
#if USE_FLASH_MEMO
} else if (cmd == CMD_ID_LOGGER && len > 2) { // Read memory measures
Expand Down
1 change: 1 addition & 0 deletions src/cmd_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ enum {
CMD_ID_COMFORT = 0x20, // Get/set comfort parameters
CMD_ID_EXTDATA = 0x22, // Get/set show ext. data
CMD_ID_UTC_TIME = 0x23, // Get/set utc time (if USE_CLOCK = 1)
CMD_ID_TADJUST = 0x24, // Get/set adjust time clock delta (in 1/16 us for 1 sec)
CMD_ID_MEASURE = 0x33, // Start/stop notify measures in connection mode
CMD_ID_LOGGER = 0x35, // Read memory measures
CMD_ID_CLRLOG = 0x36, // Clear memory measures
Expand Down

0 comments on commit a8c7b89

Please sign in to comment.