Skip to content

Commit

Permalink
Add shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
ShallowGreen123 committed Sep 20, 2024
1 parent 1fe274a commit 9d022d8
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 17 deletions.
3 changes: 3 additions & 0 deletions examples/factory/factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/*********************************************************************************
* INCLUDES
* *******************************************************************************/
#include <XPowersLib.h>

/*********************************************************************************
* DEFINES
Expand All @@ -24,6 +25,8 @@ extern bool flag_Keypad_init;
extern bool flag_BQ25896_init;
extern bool flag_BQ27220_init;
extern bool flag_LTR553ALS_init;

extern XPowersPPM PPM;
/*********************************************************************************
* TYPEDEFS
* *******************************************************************************/
Expand Down
46 changes: 45 additions & 1 deletion examples/factory/factory.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
#include "SPI.h"


XPowersPPM PPM;

TouchDrvCSTXXX touch;
GxEPD2_BW<GxEPD2_310_GDEQ031T10, GxEPD2_310_GDEQ031T10::HEIGHT> display(GxEPD2_310_GDEQ031T10(BOARD_EPD_CS, BOARD_EPD_DC, BOARD_EPD_RST, BOARD_EPD_BUSY)); // GDEQ031T10 240x320, UC8253, (no inking, backside mark KEGMO 3100)

uint8_t *decodebuffer = NULL;
lv_timer_t *flush_timer = NULL;
int disp_refr_mode = DISP_REFR_MODE_PART;
const char HelloWorld[] = "Hello World!";
const char HelloWorld[] = "T-Deck-Pro!";

bool flag_sd_init = false;
bool flag_lora_init = false;
Expand Down Expand Up @@ -186,6 +188,47 @@ static void lvgl_init(void)
lv_indev_drv_register(&indev_drv);
}

static void bq25896_init(void)
{
// BQ25896 --- 0x6B
Wire.beginTransmission(BOARD_I2C_ADDR_BQ25896);
if (Wire.endTransmission() == 0)
{
flag_BQ25896_init = true;
// battery_25896.begin();
PPM.init(Wire, BOARD_I2C_SDA, BOARD_I2C_SCL, BOARD_I2C_ADDR_BQ25896);
// Set the minimum operating voltage. Below this voltage, the PPM will protect
PPM.setSysPowerDownVoltage(3300);

// Set input current limit, default is 500mA
PPM.setInputCurrentLimit(3250);

Serial.printf("getInputCurrentLimit: %d mA\n",PPM.getInputCurrentLimit());

// Disable current limit pin
PPM.disableCurrentLimitPin();

// Set the charging target voltage, Range:3840 ~ 4608mV ,step:16 mV
PPM.setChargeTargetVoltage(4208);

// Set the precharge current , Range: 64mA ~ 1024mA ,step:64mA
PPM.setPrechargeCurr(64);

// The premise is that Limit Pin is disabled, or it will only follow the maximum charging current set by Limi tPin.
// Set the charging current , Range:0~5056mA ,step:64mA
PPM.setChargerConstantCurr(832);

// Get the set charging current
PPM.getChargerConstantCurr();
Serial.printf("getChargerConstantCurr: %d mA\n",PPM.getChargerConstantCurr());

PPM.enableADCMeasure();

PPM.enableCharge();
}
}


void setup()
{
Serial.begin(115200);
Expand Down Expand Up @@ -237,6 +280,7 @@ void setup()
}
}
}
bq25896_init();
Serial.printf("------------------------------ \n");

touch.setPins(BOARD_TOUCH_RST, BOARD_TOUCH_INT);
Expand Down
24 changes: 19 additions & 5 deletions examples/factory/ui_deckpro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ static struct menu_btn menu_btn_list[] =
{SCREEN6_ID, &img_batt, "Battery", 167, 111},
{SCREEN7_ID, &img_touch, "Input", 23, 199},
{SCREEN8_ID, &img_A7682, "A7682", 95, 199},
{SCREEN9_ID, &img_lora, "Lora8", 167, 199},
{SCREEN10_ID, &img_lora, "Lora9", 23, 23}, // Page two
{SCREEN9_ID, &img_lora, "Shutdown", 167, 199},
{SCREEN10_ID, &img_lora, "Text ", 23, 23}, // Page two
};

static void menu_btn_event_cb(lv_event_t *e)
Expand Down Expand Up @@ -847,7 +847,7 @@ static void scr6_btn_event_cb(lv_event_t * e)
}
}

void batt_trans_event_cb(lv_event_t *e)
static void batt_trans_event_cb(lv_event_t *e)
{
if(e->code == LV_EVENT_CLICKED) {
show_batt_type = !show_batt_type;
Expand Down Expand Up @@ -1048,17 +1048,31 @@ static scr_lifecycle_t screen8 = {
#endif
//************************************[ screen 9 ]******************************************
#if 1
static lv_timer_t *shutdown_timer = NULL;

static void scr9_btn_event_cb(lv_event_t * e)
{
if(e->code == LV_EVENT_CLICKED){
scr_mgr_switch(SCREEN0_ID, false);
}
}

static void shutdown_timer_event(lv_timer_t* t)
{
ui_shutdown_on();
}

static void create9(lv_obj_t *parent)
{

lv_obj_t *back9_label = scr_back_btn_create(parent, ("999"), scr9_btn_event_cb);
lv_obj_t *lab = lv_label_create(parent);
lv_obj_set_style_text_font(lab, FONT_BOLD_SIZE_15, LV_PART_MAIN);
lv_label_set_text(lab, "Shutdown...");
lv_obj_center(lab);

shutdown_timer = lv_timer_create(shutdown_timer_event, 1000, NULL);


lv_obj_t *back9_label = scr_back_btn_create(parent, ("Shutdown"), scr9_btn_event_cb);
}
static void entry9(void)
{
Expand Down
40 changes: 30 additions & 10 deletions examples/factory/ui_deckpro_port.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,43 +205,57 @@ bool ui_gyroscope_is_vaild(void) { return flag_Gyroscope_init; }
// BQ25896
bool ui_batt_25896_is_chg(void)
{
return true;
if(PPM.isVbusIn() == false) {
return false;
} else {
return true;
}
// return true;
}
float ui_batt_25896_get_vbus(void)
{
return 4.5;
return (PPM.getVbusVoltage() *1.0 / 1000.0 );
// return 4.5;
}
float ui_batt_25896_get_vsys(void)
{
return 4.5;
return (PPM.getSystemVoltage() * 1.0 / 1000.0);
// return 4.5;
}
float ui_batt_25896_get_vbat(void)
{
return 4.5;
return (PPM.getBattVoltage() * 1.0 / 1000.0);
// return 4.5;
}
float ui_batt_25896_get_volt_targ(void)
{
return 4.5;
return (PPM.getChargeTargetVoltage() * 1.0 / 1000.0);
// return 4.5;
}
float ui_batt_25896_get_chg_curr(void)
{
return 4.5;
return (PPM.getChargeCurrent());
// return 4.5;
}
float ui_batt_25896_get_pre_curr(void)
{
return 4.5;
return (PPM.getPrechargeCurr());;
// return 4.5;
}
const char * ui_batt_25896_get_chg_st(void)
{
return "hello";
return PPM.getChargeStatusString();
// return "hello";
}
const char * ui_batt_25896_get_vbus_st(void)
{
return "hello";
return PPM.getBusStatusString();
// return "hello";
}
const char * ui_batt_25896_get_ntc_st(void)
{
return "hello";
return PPM.getNTCStatusString();
// return "hello";
}

//************************************[ screen 7 ]****************************************** Input
Expand All @@ -264,4 +278,10 @@ void ui_input_set_keypay_flag(void)
{
keypad_set_flag();
}
//************************************[ screen 9 ]****************************************** Input

void ui_shutdown_on(void)
{
PPM.shutdown();
Serial.println("Shutdown .....");
}
4 changes: 4 additions & 0 deletions examples/factory/ui_deckpro_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ const char * ui_batt_25896_get_ntc_st(void);
int ui_input_get_touch_coord(int *x, int *y);
int ui_input_get_keypay_val(char *v);
void ui_input_set_keypay_flag(void);

//
void ui_shutdown_on(void);

#ifdef __cplusplus
} /*extern "C"*/
#endif
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ lib_deps =
mikalhart/TinyGPSPlus @ ^1.0.3
vshymanskyy/TinyGSM@^0.12.0
lvgl/lvgl @ ~8.3.9
lewisxhe/XPowersLib @ ^0.1.8
lewisxhe/XPowersLib @ ^0.2.4
adafruit/Adafruit TCA8418 @ ^1.0.1
adafruit/Adafruit BusIO @ ^1.14.4
olikraus/U8g2_for_Adafruit_GFX@^1.8.0
Expand Down

0 comments on commit 9d022d8

Please sign in to comment.