Skip to content

Commit

Permalink
display correction on CGG1
Browse files Browse the repository at this point in the history
  • Loading branch information
pvvx committed Mar 20, 2021
1 parent 1757344 commit b3a9fd8
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 54 deletions.
Binary file removed CGG1_v27r.bin
Binary file not shown.
Binary file added CGG1_v27s.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ You can directly update/flash the firmware without downloading the binaries belo

* [LYWSD03MMC Custom Firmware Version 2.7](https://github.com/pvvx/ATC_MiThermometer/raw/master/ATC_Thermometer27.bin)
* [MHO-C401 Custom Firmware Version 2.7](https://github.com/pvvx/ATC_MiThermometer/raw/master/MHO_C401_v27.bin)
* [CGG1 Custom Firmware Version 2.7r](https://github.com/pvvx/ATC_MiThermometer/raw/master/CGG1_v27r.bin)
* [CGG1 Custom Firmware Version 2.7s](https://github.com/pvvx/ATC_MiThermometer/raw/master/CGG1_v27s.bin)

**Original Manufacturer Firmware Version**

Expand Down
2 changes: 1 addition & 1 deletion firmware.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{"version": 39,
"custom":["ATC_Thermometer27.bin", "MHO_C401_v27.bin", "CGG1_v27r.bin"],
"custom":["ATC_Thermometer27.bin", "MHO_C401_v27.bin", "CGG1_v27s.bin"],
"original":["Original_OTA_Xiaomi_LYWSD03MMC_v1.0.0_0109.bin","Original_OTA_Xiaomi_MHO_C401_v1.0.0_0010.bin","Original_OTA_CGG1_v1.0.1_0093.bin"]}
Binary file removed img/Mi_SWS_Connection.jpg
Binary file not shown.
34 changes: 20 additions & 14 deletions src/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,24 @@ void lcd(void);
const cfg_t def_cfg = {
.flg.temp_F_or_C = false,
.flg.comfort_smiley = true,
.flg2.smiley = 0, // 0 = " " off
.flg.blinking_time_smile = false,
.flg.show_batt_enabled = false,
.flg.advertising_type = 3,
.flg.tx_measures = false,
.flg2.smiley = 0, // 0 = " " off
.advertising_interval = 40, // multiply by 62.5 ms = 2.5 sec
#if DEVICE_TYPE == DEVICE_LYWSD03MMC
.measure_interval = 4, // * advertising_interval = 10 sec
.min_step_time_update_lcd = 49, //x0.05 sec, 2.45 sec
.hw_cfg.hwver = 0,
#else // DEVICE_TYPE == DEVICE_MHO_C401 & DEVICE_CGG1
#elif DEVICE_TYPE == DEVICE_MHO_C401
.measure_interval = 8, // * advertising_interval = 20 sec
.min_step_time_update_lcd = 199, //x0.05 sec, 9.95 sec
.hw_cfg.hwver = 1,
#elif DEVICE_TYPE == DEVICE_CGG1
.measure_interval = 8, // * advertising_interval = 20 sec
.min_step_time_update_lcd = 199, //x0.05 sec, 9.95 sec
.hw_cfg.hwver = 2,
#endif
#if USE_FLASH_MEMO || USE_CLOCK
.hw_cfg.clock = 1,
Expand Down Expand Up @@ -297,17 +301,11 @@ _attribute_ram_code_ void user_init_deepRetn(void) {//after sleep this will get

_attribute_ram_code_ uint8_t is_comfort(int16_t t, uint16_t h) {
uint8_t ret = SMILE_SAD;
if(t >= cmf.t[0] && t <= cmf.t[1] && h >= cmf.h[0] && h <= cmf.h[1]) ret = SMILE_HAPPY;
if(t >= cmf.t[0] && t <= cmf.t[1] && h >= cmf.h[0] && h <= cmf.h[1])
ret = SMILE_HAPPY;
return ret;
}

_attribute_ram_code_ void lcd_set_ext_data(void) {
show_battery_symbol(ext.flg.battery);
show_small_number(ext.small_number, ext.flg.percent_on);
show_temp_symbol(*((uint8_t *) &ext.flg));
show_big_number(ext.big_number);
}

_attribute_ram_code_ __attribute__((optimize("-Os"))) void lcd(void) {
bool set_small_number_and_bat = true;
while (chow_tick_sec && clock_time() - chow_tick_clk
Expand All @@ -317,8 +315,12 @@ _attribute_ram_code_ __attribute__((optimize("-Os"))) void lcd(void) {
}
show_stage++;
if (chow_tick_sec && (show_stage & 2)) { // show ext data
if (show_stage & 1) { // stage blinking or show battery
if (cfg.flg.show_batt_enabled || battery_level <= 15) { // Battery
if (show_stage & 1) { // stage blinking or show battery or clock
if (cfg.flg.show_batt_enabled
#if DEVICE_TYPE != DEVICE_CGG1
|| battery_level <= 15
#endif
) { // Battery
show_smiley(0); // stage show battery
show_battery_symbol(1);
#if DEVICE_TYPE == DEVICE_CGG1
Expand Down Expand Up @@ -354,7 +356,11 @@ _attribute_ram_code_ __attribute__((optimize("-Os"))) void lcd(void) {
return;
}
#endif
if (cfg.flg.show_batt_enabled || battery_level <= 15) { // Battery
if (cfg.flg.show_batt_enabled
#if DEVICE_TYPE != DEVICE_CGG1
|| battery_level <= 15
#endif
) { // Battery
show_smiley(0); // stage show battery
show_battery_symbol(1);
#if DEVICE_TYPE == DEVICE_CGG1
Expand Down Expand Up @@ -385,7 +391,7 @@ _attribute_ram_code_ __attribute__((optimize("-Os"))) void lcd(void) {
}
if (set_small_number_and_bat) {
#if DEVICE_TYPE == DEVICE_CGG1
show_battery_symbol(cfg.flg.show_batt_enabled == 0);
show_battery_symbol(!cfg.flg.show_batt_enabled);
show_small_number(measured_data.humi / 10, 1);
#else
show_battery_symbol(0);
Expand Down
2 changes: 1 addition & 1 deletion src/app_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extern "C" {
#define DEVICE_MHO_C401 0x0387 // E-Ink display MHO-C401
#define DEVICE_CGG1 0x0B48 // E-Ink display CGG1 "Qingping Temp & RH Monitor"

#define DEVICE_TYPE DEVICE_LYWSD03MMC // DEVICE_LYWSD03MMC or DEVICE_MHO_C401 or DEVICE_CGG1
#define DEVICE_TYPE DEVICE_CGG1 //DEVICE_LYWSD03MMC // DEVICE_LYWSD03MMC or DEVICE_MHO_C401 or DEVICE_CGG1

#define BLE_SECURITY_ENABLE 1
#define BLE_HOST_SMP_ENABLE BLE_SECURITY_ENABLE
Expand Down
5 changes: 3 additions & 2 deletions src/boot.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
################################################################################

# Add inputs and outputs from these tool invocations to the build variables
OUT_DIR += /src

OBJS += \
$(OUT_PATH)/cstartup_825x.o
$(OUT_PATH)/src/cstartup_825x.o

BOOT_FLAG := -DMCU_STARTUP_825X

Expand All @@ -14,6 +15,6 @@ ifeq ($(USE_FREE_RTOS), 1)
endif

# Each subdirectory must supply rules for building sources it contributes
$(OUT_PATH)/%.o: ./src/%.S
$(OUT_PATH)/src/%.o: ./src/%.S
@echo 'Building file: $<'
@tc32-elf-gcc $(BOOT_FLAG) -c -o"$@" "$<"
6 changes: 4 additions & 2 deletions src/div_mod.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

OBJS += $(OUT_PATH)/div_mod.o
OUT_DIR += /drivers

OBJS += $(OUT_PATH)/drivers/div_mod.o

# Each subdirectory must supply rules for building sources it contributes
$(OUT_PATH)/%.o: $(TEL_PATH)/components/boot/%.S
$(OUT_PATH)/drivers/%.o: $(TEL_PATH)/components/boot/%.S
@echo 'Building file: $<'
@tc32-elf-gcc $(BOOT_FLAG) -c -o"$@" "$<"
29 changes: 15 additions & 14 deletions src/epd_cgg1.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/* Based on source: https://github.com/znanev/ATC_MiThermometer */
#include "app.h"
#include "epd.h"
#include "lcd.h"
#include "battery.h"
#include "drivers/8258/pm.h"
#include "drivers/8258/timer.h"
Expand Down Expand Up @@ -97,11 +98,11 @@ _attribute_ram_code_ void show_temp_symbol(uint8_t symbol) {
else
display_buff[1] &= ~BIT(5); // "_"
}
/* CGG1 no symbol 'smiley'
* 0,1,2,3,4,5 = " " happy
* 6,7 = "----" sad */

/* CGG1 no symbol 'smiley' !
* =5 -> "---" happy, != 5 -> " " sad */
_attribute_ram_code_ void show_smiley(uint8_t state){
if(state > 5)
if(state & 1)
display_buff[7] |= BIT(2);
else
display_buff[7] &= ~BIT(2);
Expand All @@ -118,9 +119,9 @@ _attribute_ram_code_ void show_battery_symbol(bool state){
if(battery_level >= 33) {
display_buff[5] |= BIT(5);
if(battery_level >= 49) {
display_buff[6] |= BIT(1);
display_buff[6] |= BIT(7);
if(battery_level >= 67) {
display_buff[6] |= BIT(7);
display_buff[6] |= BIT(1);
if(battery_level >= 83) {
display_buff[7] |= BIT(5);
}
Expand Down Expand Up @@ -235,14 +236,14 @@ _attribute_ram_code_ __attribute__((optimize("-Os"))) void show_big_number(int16
// no point, show: -99..1999
if(number < 0){
number = -number;
display_buff[9] = BIT(3); // "-"
display_buff[9] |= BIT(3); // "-"
}
number = (number / 10) + ((number % 10) > 5); // round(div 10)
} else { // show: -9.9..199.9
display_buff[3] |= BIT(6); // point
if(number < 0){
number = -number;
display_buff[9] = BIT(3); // "-"
display_buff[9] |= BIT(3); // "-"
}
}
/* number: -99..1999 */
Expand All @@ -258,7 +259,7 @@ _attribute_ram_code_ __attribute__((optimize("-Os"))) void show_big_number(int16
_attribute_ram_code_ __attribute__((optimize("-Os"))) void show_small_number(int16_t number, bool percent){
display_buff[0] &= ~(BIT(0) | BIT(1) | BIT(2));
display_buff[3] &= ~(BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5));
display_buff[5] &= ~BIT(1);
display_buff[5] &= ~(BIT(1) | BIT(2) | BIT(3));
display_buff[6] &= ~BIT(0);
display_buff[7] &= ~(BIT(3) | BIT(6) | BIT(7));
display_buff[8] &= ~(BIT(1) | BIT(2) | BIT(3) | BIT(4));
Expand All @@ -270,30 +271,30 @@ _attribute_ram_code_ __attribute__((optimize("-Os"))) void show_small_number(int
display_buff[16] &= ~(BIT(4) | BIT(5) | BIT(6) | BIT(7));
if(percent)
display_buff[5] |= BIT(3); // "%"
if(number > 999) {
if(number > 9995) {
// "Hi"
display_buff[9] |= BIT(5);
display_buff[10] |= BIT(4) | BIT(6);
display_buff[13] |= BIT(2);
display_buff[14] |= BIT(0) | BIT(1) | BIT(2) | BIT(3);
display_buff[15] |= BIT(0) |BIT(6) | BIT(7);
display_buff[16] |= BIT(4) | BIT(6) | BIT(7);
} else if(number < -99) {
} else if(number < -995) {
//"Lo"
display_buff[7] |= BIT(3);
display_buff[8] |= BIT(1) | BIT(4);
display_buff[9] |= BIT(5) | BIT(7);
display_buff[10] |= BIT(4) | BIT(5) | BIT(6);
display_buff[14] |= BIT(1) | BIT(3);
display_buff[15] |= BIT(6);
display_buff[16] |= BIT(4) | BIT(5) | BIT(6);
display_buff[16] |= BIT(4) | BIT(5) | BIT(6) | BIT(7);
} else {
/* number: -99..999 */
if(number > 995 || number < -95) {
// no point, show: -99..999
if(number < 0){
number = -number;
display_buff[0] |= BIT(2); // "-"
display_buff[15] |= BIT(7); // "-"
}
number = (number / 10) + ((number % 10) > 5); // round(div 10)
} else { // show: -9.9..99.9
Expand Down Expand Up @@ -330,7 +331,7 @@ void show_batt_cgg1(void) {
if(battery_level > 995)
battery_level = 995;
}
show_small_number(battery_level, 1);
show_small_number(battery_level, false);
}

_attribute_ram_code_ void update_lcd(void){
Expand Down
1 change: 1 addition & 0 deletions src/lcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdint.h>
#include "app_config.h"

/* CGG1 no symbol 'smiley' ! */
#define SMILE_HAPPY 5 // "(^-^)" happy
#define SMILE_SAD 6 // "(-^-)" sad
#define TMP_SYM_C 0xA0 // "°C"
Expand Down
41 changes: 22 additions & 19 deletions src/project.mk
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@

OUT_DIR += /src

OBJS += \
$(OUT_PATH)/utils.o \
$(OUT_PATH)/app.o \
$(OUT_PATH)/lcd.o \
$(OUT_PATH)/epd_mho_c401.o \
$(OUT_PATH)/epd_cgg1.o \
$(OUT_PATH)/sensor.o \
$(OUT_PATH)/trigger.o \
$(OUT_PATH)/app_att.o \
$(OUT_PATH)/battery.o \
$(OUT_PATH)/ble.o \
$(OUT_PATH)/i2c.o \
$(OUT_PATH)/cmd_parser.o \
$(OUT_PATH)/flash_eep.o \
$(OUT_PATH)/logger.o \
$(OUT_PATH)/blt_common.o\
$(OUT_PATH)/ccm.o \
$(OUT_PATH)/mi_beacon.o \
$(OUT_PATH)/main.o
$(OUT_PATH)/src/utils.o \
$(OUT_PATH)/src/app.o \
$(OUT_PATH)/src/lcd.o \
$(OUT_PATH)/src/epd_cgg1.o \
$(OUT_PATH)/src/epd_mho_c401.o \
$(OUT_PATH)/src/sensor.o \
$(OUT_PATH)/src/trigger.o \
$(OUT_PATH)/src/app_att.o \
$(OUT_PATH)/src/battery.o \
$(OUT_PATH)/src/ble.o \
$(OUT_PATH)/src/i2c.o \
$(OUT_PATH)/src/cmd_parser.o \
$(OUT_PATH)/src/flash_eep.o \
$(OUT_PATH)/src/logger.o \
$(OUT_PATH)/src/blt_common.o\
$(OUT_PATH)/src/ccm.o \
$(OUT_PATH)/src/mi_beacon.o \
$(OUT_PATH)/src/main.o


# Each subdirectory must supply rules for building sources it contributes
$(OUT_PATH)/%.o: ./src/%.c
$(OUT_PATH)/src/%.o: $(PROJECT_PATH)/%.c
@echo 'Building file: $<'
@tc32-elf-gcc $(GCC_FLAGS) $(INCLUDE_PATHS) -c -o"$@" "$<"

0 comments on commit b3a9fd8

Please sign in to comment.