Battery: support for ac connection event cmd
This add two new config options "ac_connected_cmd" and "ac_disconnected_cmd". These commands are executed when AC (mains supply) is connected or disconnected.
This commit is contained in:
parent
3c45cf29c7
commit
db490247e0
4 changed files with 33 additions and 0 deletions
|
@ -44,6 +44,8 @@ static char buf_bat_time[20];
|
|||
|
||||
int8_t battery_low_status;
|
||||
unsigned char battery_low_cmd_sent;
|
||||
char *ac_connected_cmd;
|
||||
char *ac_disconnected_cmd;
|
||||
char *battery_low_cmd;
|
||||
char *battery_lclick_command;
|
||||
char *battery_mclick_command;
|
||||
|
@ -59,6 +61,7 @@ void update_battery_tick(void* arg)
|
|||
|
||||
int old_found = battery_found;
|
||||
int old_percentage = battery_state.percentage;
|
||||
int old_ac_connected = battery_state.ac_connected;
|
||||
int16_t old_hours = battery_state.time.hours;
|
||||
int8_t old_minutes = battery_state.time.minutes;
|
||||
|
||||
|
@ -71,6 +74,14 @@ void update_battery_tick(void* arg)
|
|||
// Try again
|
||||
update_battery();
|
||||
}
|
||||
|
||||
if (old_ac_connected != battery_state.ac_connected) {
|
||||
if(battery_state.ac_connected)
|
||||
tint_exec(ac_connected_cmd);
|
||||
else
|
||||
tint_exec(ac_disconnected_cmd);
|
||||
}
|
||||
|
||||
if (old_found == battery_found &&
|
||||
old_percentage == battery_state.percentage &&
|
||||
old_hours == battery_state.time.hours &&
|
||||
|
@ -215,6 +226,7 @@ int update_battery() {
|
|||
/* reset */
|
||||
battery_state.state = BATTERY_UNKNOWN;
|
||||
battery_state.percentage = 0;
|
||||
battery_state.ac_connected = FALSE;
|
||||
batstate_set_time(&battery_state, 0);
|
||||
|
||||
err = battery_os_update(&battery_state);
|
||||
|
|
|
@ -44,6 +44,7 @@ typedef struct batstate {
|
|||
int percentage;
|
||||
struct battime time;
|
||||
enum chargestate state;
|
||||
gboolean ac_connected;
|
||||
} batstate;
|
||||
|
||||
extern struct batstate battery_state;
|
||||
|
@ -56,6 +57,9 @@ extern int percentage_hide;
|
|||
extern int8_t battery_low_status;
|
||||
extern char *battery_low_cmd;
|
||||
|
||||
extern char *ac_connected_cmd;
|
||||
extern char *ac_disconnected_cmd;
|
||||
|
||||
extern char *battery_lclick_command;
|
||||
extern char *battery_mclick_command;
|
||||
extern char *battery_rclick_command;
|
||||
|
|
|
@ -343,6 +343,7 @@ int battery_os_update(struct batstate *state) {
|
|||
gboolean charging = FALSE;
|
||||
gboolean discharging = FALSE;
|
||||
gboolean full = FALSE;
|
||||
gboolean ac_connected = FALSE;
|
||||
|
||||
for (l = batteries; l != NULL; l = l->next) {
|
||||
struct psy_battery *bat = l->data;
|
||||
|
@ -360,6 +361,7 @@ int battery_os_update(struct batstate *state) {
|
|||
for (l = mains; l != NULL; l = l->next) {
|
||||
struct psy_mains *ac = l->data;
|
||||
update_linux_mains(ac);
|
||||
ac_connected |= (ac->online);
|
||||
}
|
||||
|
||||
/* build global state */
|
||||
|
@ -382,6 +384,9 @@ int battery_os_update(struct batstate *state) {
|
|||
/* calculate percentage */
|
||||
state->percentage = energy_to_percent(total_energy_now, total_energy_full);
|
||||
|
||||
/* AC state */
|
||||
state->ac_connected = ac_connected;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
12
src/config.c
12
src/config.c
|
@ -392,6 +392,18 @@ void add_entry (char *key, char *value)
|
|||
#ifdef ENABLE_BATTERY
|
||||
if (strlen(value) > 0)
|
||||
battery_low_cmd = strdup (value);
|
||||
#endif
|
||||
}
|
||||
else if (strcmp (key, "ac_connected_cmd") == 0) {
|
||||
#ifdef ENABLE_BATTERY
|
||||
if (strlen(value) > 0)
|
||||
ac_connected_cmd = strdup (value);
|
||||
#endif
|
||||
}
|
||||
else if (strcmp (key, "ac_disconnected_cmd") == 0) {
|
||||
#ifdef ENABLE_BATTERY
|
||||
if (strlen(value) > 0)
|
||||
ac_disconnected_cmd = strdup (value);
|
||||
#endif
|
||||
}
|
||||
else if (strcmp (key, "bat1_font") == 0) {
|
||||
|
|
Loading…
Reference in a new issue