Skip to content

Commit 1865cb7

Browse files
authored
Merge pull request #136 from tmobile/tmo-CFSPDK-1030-Check-battery-attached
Check for battery attached
2 parents 554c75c + edf36aa commit 1865cb7

File tree

1 file changed

+45
-28
lines changed

1 file changed

+45
-28
lines changed

samples/tmo_shell/src/tmo_shell.c

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,7 +1619,7 @@ int process_cli_cmd_modem_psm(const struct shell *shell, size_t argc, char **arg
16191619
u->psm.t3324 = t3324 + (t3324_mul << 5);
16201620

16211621
shell_print(shell, "Set PSM mode: %d,\n"
1622-
"\tT3412 Unit: %d, T3412 Value: %d, T3324 Unit: %d, T3324 Value: %d",
1622+
" T3412 Unit: %d, T3412 Value: %d, T3324 Unit: %d, T3324 Value: %d",
16231623
mode, t3412_mul, t3412, t3324_mul, t3324);
16241624
tmo_set_modem(AT_MODEM_PSM_SET,(union params_cmd*) u, sd);
16251625
} else {
@@ -1716,9 +1716,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE(ble_adv_sub,
17161716
SHELL_CMD(conn, NULL, "Advertise as connectable", cmd_ble_adv_conn),
17171717
SHELL_CMD(eddystone, NULL, "Advertise as eddystone beacon", cmd_ble_adv_ebeacon),
17181718
SHELL_CMD(ibeacon, NULL, "Advertise as ibeacon\n"
1719-
"\tUsage:\n"
1720-
"\t tmo ble adv ibeacon <uuid (optional)> <major (optional)>\n"
1721-
"\t <minor (optional)> <rssi at 1m (optional)>",
1719+
"Usage:\n"
1720+
" tmo ble adv ibeacon <uuid (optional)> <major (optional)>\n"
1721+
" <minor (optional)> <rssi at 1m (optional)>",
17221722
cmd_ble_adv_ibeacon),
17231723
SHELL_SUBCMD_SET_END
17241724
);
@@ -2065,41 +2065,49 @@ int cmd_charging_status(const struct shell *shell, size_t argc, char **argv)
20652065

20662066
status = get_battery_charging_status(&charging, &vbus, &attached, &fault);
20672067
if (status != 0) {
2068-
shell_error(shell, "Charger VBUS status command failed");
2068+
shell_error(shell, "Charger status command failed");
20692069
}
20702070
else {
20712071
if (!attached) {
2072-
shell_print(shell, "\tNo battery attached");
2072+
shell_print(shell, "No battery attached");
20732073
} else if (!vbus) {
2074-
shell_print(shell, "\tCharger is missing VBUS and is NOT charging");
2074+
shell_print(shell, "Charger is missing VBUS and is NOT charging");
20752075
}
20762076
else {
20772077
if (vbus && charging) {
2078-
shell_print(shell, "\tCharger has VBUS and is charging");
2078+
shell_print(shell, "Charger has VBUS and is charging");
20792079
}
20802080
else {
20812081
if (vbus && !charging) {
2082-
shell_print(shell, "\tCharger has VBUS and is done charging");
2082+
shell_print(shell, "Charger has VBUS and is done charging");
20832083
}
20842084
}
20852085
}
20862086
}
2087-
return 0;
2087+
return status;
20882088
}
20892089

20902090
int cmd_battery_voltage(const struct shell *shell, size_t argc, char **argv)
20912091
{
2092+
int status;
20922093
uint32_t millivolts = 0;
2093-
uint8_t battery_attached = 0;
2094+
uint8_t attached = 0;
20942095
uint8_t charging = 0;
20952096
uint8_t vbus = 0;
20962097
uint8_t fault = 0;
20972098

2098-
get_battery_charging_status(&charging, &vbus, &battery_attached, &fault);
2099-
millivolts = read_battery_voltage();
2100-
shell_print(shell, "\tBattery voltage %d.%03dV", millivolts/1000, millivolts%1000);
2101-
2102-
return millivolts;
2099+
status = get_battery_charging_status(&charging, &vbus, &attached, &fault);
2100+
if (status != 0) {
2101+
shell_error(shell, "Charger status command failed");
2102+
} else {
2103+
if (!attached) {
2104+
shell_print(shell, "No battery attached");
2105+
} else {
2106+
millivolts = read_battery_voltage();
2107+
shell_print(shell, "Battery voltage %d.%03dV", millivolts/1000, millivolts%1000);
2108+
}
2109+
}
2110+
return status;
21032111
}
21042112

21052113
extern uint8_t aio_btn_pushed;
@@ -2109,7 +2117,7 @@ int cmd_battery_discharge(const struct shell *shell, size_t argc, char **argv)
21092117
uint8_t percent = 100;
21102118
uint8_t old_percent = 0;
21112119
uint32_t millivolts = 0;
2112-
uint8_t battery_attached = 0;
2120+
uint8_t attached = 0;
21132121
uint8_t charging = 0;
21142122
uint8_t vbus = 0;
21152123
uint8_t fault= 0;
@@ -2130,8 +2138,8 @@ int cmd_battery_discharge(const struct shell *shell, size_t argc, char **argv)
21302138
}
21312139
shell_print(shell, "Discharge setpoint: %d", set_point);
21322140

2133-
get_battery_charging_status(&charging, &vbus, &battery_attached, &fault);
2134-
if (battery_attached != 0) {
2141+
get_battery_charging_status(&charging, &vbus, &attached, &fault);
2142+
if (attached != 0) {
21352143
millivolts = read_battery_voltage();
21362144
millivolts_to_percent(millivolts, &percent);
21372145
old_percent = percent;
@@ -2161,8 +2169,8 @@ int cmd_battery_discharge(const struct shell *shell, size_t argc, char **argv)
21612169
}
21622170

21632171
while (percent > set_point) {
2164-
get_battery_charging_status(&charging, &vbus, &battery_attached, &fault);
2165-
if (battery_attached != 0) {
2172+
get_battery_charging_status(&charging, &vbus, &attached, &fault);
2173+
if (attached != 0) {
21662174
millivolts = read_battery_voltage();
21672175
millivolts_to_percent(millivolts, &percent);
21682176
} else {
@@ -2193,18 +2201,27 @@ int cmd_battery_discharge(const struct shell *shell, size_t argc, char **argv)
21932201

21942202
int cmd_battery_percentage(const struct shell *shell, size_t argc, char **argv)
21952203
{
2204+
int status;
21962205
uint8_t percent = 0;
21972206
uint32_t millivolts = 0;
2198-
uint8_t battery_attached = 0;
2207+
uint8_t attached = 0;
21992208
uint8_t charging = 0;
22002209
uint8_t vbus = 0;
22012210
uint8_t fault= 0;
22022211

2203-
get_battery_charging_status(&charging, &vbus, &battery_attached, &fault);
2204-
millivolts = read_battery_voltage();
2205-
millivolts_to_percent(millivolts, &percent);
2206-
shell_print(shell, "\tBattery level %d percent", percent);
2207-
return 0;
2212+
status = get_battery_charging_status(&charging, &vbus, &attached, &fault);
2213+
if (status != 0) {
2214+
shell_error(shell, "Charger status command failed");
2215+
} else {
2216+
if (!attached) {
2217+
shell_print(shell, "No battery attached");
2218+
} else {
2219+
millivolts = read_battery_voltage();
2220+
millivolts_to_percent(millivolts, &percent);
2221+
shell_print(shell, "Battery level %d percent", percent);
2222+
}
2223+
}
2224+
return status;
22082225
}
22092226

22102227
int udp_cred_dtls(const struct shell *shell, size_t argc, char **argv)
@@ -2213,7 +2230,7 @@ int udp_cred_dtls(const struct shell *shell, size_t argc, char **argv)
22132230
shell_error(shell, "Missing required arguments");
22142231
shell_print(shell, "Usage: tmo udp %s <operation> <socket>>\n"
22152232
" operation:w to write, d to delete dtls credential from modem NVRAM\n"
2216-
" socket: socket descriptor", argv[0]);
2233+
" socket: socket descriptor", argv[0]);
22172234
return -EINVAL;
22182235
}
22192236
return tmo_dtls_cred(shell, argv[0], argv[1], (int) strtol(argv[2], NULL, 10));

0 commit comments

Comments
 (0)