Skip to content

Commit

Permalink
Log battery and charger states in human readable format
Browse files Browse the repository at this point in the history
Add helpers for getting state names and use them in diagnostic logging.
  • Loading branch information
spiiroin committed Jan 25, 2015
1 parent 9770ef1 commit 9bba2ff
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
40 changes: 40 additions & 0 deletions datapipe.c
Expand Up @@ -1019,6 +1019,46 @@ const char *usb_cable_state_repr(usb_cable_state_t state)
return res;
}

/** Convert charger_state_t enum to human readable string
*
* @param state charger_state_t enumeration value
*
* @return human readable representation of state
*/
const char *charger_state_repr(charger_state_t state)
{
const char *res = "unknown";

switch( state ) {
case CHARGER_STATE_UNDEF: res = "undefined"; break;
case CHARGER_STATE_OFF: res = "off"; break;
case CHARGER_STATE_ON: res = "on"; break;
default: break;
}

return res;
}

/** Convert battery_status_t enum to human readable string
*
* @param state battery_status_t enumeration value
*
* @return human readable representation of state
*/
const char *battery_status_repr(battery_status_t state)
{
const char *res = "unknown";
switch( state ) {
case BATTERY_STATUS_UNDEF: res = "undefined"; break;
case BATTERY_STATUS_FULL: res = "full"; break;
case BATTERY_STATUS_OK: res = "ok"; break;
case BATTERY_STATUS_LOW: res = "low"; break;
case BATTERY_STATUS_EMPTY: res = "empty"; break;
default: break;
}
return res;
}

void datapipe_handlers_install(datapipe_handler_t *bindings)
{
if( !bindings )
Expand Down
4 changes: 4 additions & 0 deletions mce.h
Expand Up @@ -241,13 +241,17 @@ typedef enum {
BATTERY_STATUS_EMPTY = 3, /**< Battery empty */
} battery_status_t;

const char *battery_status_repr(battery_status_t state);

/** Charging status */
typedef enum {
CHARGER_STATE_UNDEF = -1, /**< Not known yet */
CHARGER_STATE_OFF = 0, /**< Not charging */
CHARGER_STATE_ON = 1, /**< Charging */
} charger_state_t;

const char *charger_state_repr(charger_state_t state);

/** Camera button state */
typedef enum {
CAMERA_BUTTON_UNDEF = -1, /**< Camera button state not set */
Expand Down
4 changes: 3 additions & 1 deletion modules/battery-upower.c
Expand Up @@ -691,7 +691,9 @@ mcebat_update_cb(gpointer user_data)

/* Process changes */
if( mcebat.charger != prev.charger ) {
mce_log(LL_INFO, "charger: %d -> %d", prev.charger, mcebat.charger);
mce_log(LL_INFO, "charger: %s -> %s",
charger_state_repr(prev.charger),
charger_state_repr(mcebat.charger));

/* Charger connected state */
execute_datapipe(&charger_state_pipe, GINT_TO_POINTER(mcebat.charger),
Expand Down
8 changes: 6 additions & 2 deletions tklock.c
Expand Up @@ -973,7 +973,9 @@ static void tklock_datapipe_charger_state_cb(gconstpointer data)
if( charger_state == prev )
goto EXIT;

mce_log(LL_DEBUG, "charger_state = %d -> %d", prev, charger_state);
mce_log(LL_DEBUG, "charger_state = %s -> %s",
charger_state_repr(prev),
charger_state_repr(charger_state));

/* No exception on mce startup */
if( prev == CHARGER_STATE_UNDEF )
Expand Down Expand Up @@ -1001,7 +1003,9 @@ static void tklock_datapipe_battery_status_cb(gconstpointer data)
if( battery_status == prev )
goto EXIT;

mce_log(LL_DEBUG, "battery_status = %d -> %d", prev, battery_status);
mce_log(LL_DEBUG, "battery_status = %s -> %s",
battery_status_repr(prev),
battery_status_repr(battery_status));

#if 0 /* At the moment there is no notification associated with
* battery full -> no need to turn the display on */
Expand Down

0 comments on commit 9bba2ff

Please sign in to comment.