static int get_property(struct power_supply *b, enum power_supply_property psp, union power_supply_propval *val) { int rc = 0; switch (psp) { case POWER_SUPPLY_PROP_STATUS: val->intval = get_battery_status(b); break; case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN: val->intval = 0xfd0; break; case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: val->intval = 0xc00; break; case POWER_SUPPLY_PROP_VOLTAGE_NOW: val->intval = get_battery_voltage(); break; case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: val->intval = 100; break; default: val->intval = -1; rc = -1; } return rc; };
EFI_STATUS get_battery_voltage(UINTN *voltage) { struct battery_status status; EFI_STATUS ret; ret = get_battery_status(&status); if (EFI_ERROR(ret)) return ret; *voltage = status.BatteryVoltageLevel; return EFI_SUCCESS; }
int main(void) { char *status; char *datetime; char *battery_status; int bat0; char hostname[16]; //hostname[15] = '\0'; gethostname(hostname, 15); int is_laptop; is_laptop = strcmp(hostname, "miku"); if (!(dpy = XOpenDisplay(NULL))) { fprintf(stderr, "Cannot open display.\n"); return 1; } if((status = malloc(200)) == NULL) exit(1); for(;;sleep(10)) { datetime = get_datetime(); if(!is_laptop) { battery_status = get_battery_status(); bat0 = get_battery(); snprintf(status, 200, "%s%d%% | %s", battery_status, bat0, datetime); } else { snprintf(status, 200, "%s", datetime); } setstatus(status); } free(datetime); free(status); XCloseDisplay(dpy); return 0; }
BOOLEAN is_battery_below_boot_OS_threshold(void) { struct battery_status status; EFI_STATUS ret; UINTN value, threshold; UINT8 ia_apps_to_use; ret = get_battery_status(&status); if (EFI_ERROR(ret)) return FALSE; ia_apps_to_use = oem1_get_ia_apps_to_use(); if (ia_apps_to_use == (UINT8)-1) { error(L"OEM1 ACPI table parse error"); return FALSE; } if (status.CapacityReadable && ia_apps_to_use == OEM1_USE_IA_APPS_CAP) { value = status.BatteryCapacityLevel; threshold = oem1_get_ia_apps_cap(); debug(L"Battery: %d%% Threshold: %d%%", value, threshold); } else { value = status.BatteryVoltageLevel; threshold = oem1_get_ia_apps_run(); debug(L"Battery: %dmV Threshold: %dmV", value, threshold); if (value == 0) { /* This is very common to have such an issue when we are working on a new hardware. Instead of blocking the boot flow, we raise an error. */ error(L"Impossible 0mV battery voltage. This has to be fixed !"); error(L"Assuming battery voltage is above threshold"); return FALSE; } } return value < threshold; }
const struct linux_logo * __init_refok fb_find_logo(int depth) { struct linux_logo *logo = NULL; const struct linux_logo *m_logo = NULL; if (nologo) return NULL; if (depth >= 1) { #ifdef CONFIG_LOGO_LINUX_MONO /* Generic Linux logo */ logo = &logo_linux_mono; #endif #ifdef CONFIG_LOGO_SUPERH_MONO /* SuperH Linux logo */ logo = &logo_superh_mono; #endif } if (depth >= 4) { #ifdef CONFIG_LOGO_LINUX_VGA16 /* Generic Linux logo */ logo = &logo_linux_vga16; #endif #ifdef CONFIG_LOGO_BLACKFIN_VGA16 /* Blackfin processor logo */ logo = &logo_blackfin_vga16; #endif #ifdef CONFIG_LOGO_SUPERH_VGA16 /* SuperH Linux logo */ logo = &logo_superh_vga16; #endif } if (depth >= 8) { #ifdef CONFIG_LOGO_LINUX_CLUT224 /* Generic Linux logo */ logo = &logo_linux_clut224; #endif #ifdef CONFIG_LOGO_LINUX_CLUT224_TR785 /* Generic Linux logo */ logo = &tr785_logo_linux_clut224; #endif #ifdef CONFIG_LOGO_LINUX_CLUT224_TR7088 /* Generic Linux logo */ logo = &tr7088_logo_linux_clut224; #endif #ifdef CONFIG_LOGO_LINUX_CLUT224_TR101Q /* Generic Linux logo */ logo = &tr101q_logo_linux_clut224; #endif #ifdef CONFIG_LOGO_LINUX_CLUT224_TR7078 /* Generic Linux logo */ logo = &tr7078_logo_linux_clut224; #endif #ifdef CONFIG_LOGO_LINUX_CLUT224_TR838 /* Generic Linux logo */ logo = &tr838_logo_linux_clut224; #endif #ifdef CONFIG_LOGO_LINUX_CLUT224_TR7088TN /* Generic Linux logo */ logo = &tr7088tn_logo_linux_clut224; #endif #ifdef CONFIG_LOGO_LINUX_CLUT224_XBT_3188 /* Generic Linux logo */ logo = &xbt_3188_logo_linux_clut224; #endif #ifdef CONFIG_LOGO_PIPO_CLUT224 /* Generic Linux logo */ logo = &logo_pipo_clut224; #endif #ifdef CONFIG_LOGO_G3_CLUT224 /* Generic Linux logo */ logo = &logo_g3_clut224; #endif #ifdef CONFIG_LOGO_BLACKFIN_CLUT224 /* Blackfin Linux logo */ logo = &logo_blackfin_clut224; #endif #ifdef CONFIG_LOGO_DEC_CLUT224 /* DEC Linux logo on MIPS/MIPS64 or ALPHA */ logo = &logo_dec_clut224; #endif #ifdef CONFIG_LOGO_MAC_CLUT224 /* Macintosh Linux logo on m68k */ if (MACH_IS_MAC) logo = &logo_mac_clut224; #endif #ifdef CONFIG_LOGO_PARISC_CLUT224 /* PA-RISC Linux logo */ logo = &logo_parisc_clut224; #endif #ifdef CONFIG_LOGO_SGI_CLUT224 /* SGI Linux logo on MIPS/MIPS64 and VISWS */ logo = &logo_sgi_clut224; #endif #ifdef CONFIG_LOGO_SUN_CLUT224 /* Sun Linux logo */ logo = &logo_sun_clut224; #endif #ifdef CONFIG_LOGO_SUPERH_CLUT224 /* SuperH Linux logo */ logo = &logo_superh_clut224; #endif #ifdef CONFIG_LOGO_M32R_CLUT224 /* M32R Linux logo */ logo = &logo_m32r_clut224; #endif #ifdef CONFIG_LOGO_CRUZ_CLUT224 logo = &logo_cruz_clut224; #endif #ifdef CONFIG_LOGO_LINUX_800x480_CLUT224 logo = &logo_linux_800x480_clut224; #endif #ifdef CONFIG_LOGO_LOWERPOWER_WARNING if( 1 == get_battery_status()){ logo = &logo_linux_lowerpower_clut224; } #endif #if defined(CONFIG_TCHIP_MACH_TR101Q) && defined(CONFIG_POWER_ON_CHARGER_DISPLAY) && defined(CONFIG_TCHIP_TR101Q_HAVE_CHARGE_LOGO) if ( 1 == tchip_is_boot_charge_mode() ) // charging logo = &tr101q_charging_logo_linux_clut224; #endif if (depth >= 24) { #ifdef CONFIG_LOGO_LINUX_BMP #ifdef CONFIG_LOGO_LINUX_BMP_SUNSET logo = &logo_sunset_bmp; #endif #ifdef CONFIG_LOGO_LINUX_BMP_ANDROID logo = &logo_android_bmp; #endif #ifdef CONFIG_LOGO_LINUX_BMP_ANDROID_TR7888_KNC logo = &tr7888_knc_logo_android_bmp; #endif #endif } else { /* logo->width = ((logo->data[0] << 8) + logo->data[1]); logo->height = ((logo->data[2] << 8) + logo->data[3]); logo->clutsize = logo->clut[0]; logo->data += 4; logo->clut += 1; */ } } m_logo = logo; return m_logo; }
static void update_tray_icon_status (GtkStatusIcon *tray_icon) { gboolean battery_present = FALSE; gboolean ac_online = FALSE; gint battery_status = -1; static gint old_battery_status = -1; static gboolean battery_low = FALSE; static gboolean battery_critical = FALSE; static gboolean spawn_command_critical = FALSE; gint percentage, time; gchar *battery_string, *time_string; GError *error = NULL; #ifdef WITH_NOTIFY NotifyNotification *notification = NULL; #endif g_return_if_fail (tray_icon != NULL); /* update tray icon for AC only */ if (battery_path == NULL) { static gboolean ac_notified = FALSE; if (ac_notified == FALSE) { ac_notified = TRUE; NOTIFY_MESSAGE (¬ification, _("AC only, no battery!"), NULL, NOTIFY_EXPIRES_NEVER, NOTIFY_URGENCY_NORMAL); } gtk_status_icon_set_tooltip_text (tray_icon, _("AC only, no battery!")); gtk_status_icon_set_from_icon_name (tray_icon, "ac-adapter"); return; } /* update tray icon for battery */ if (get_battery_present (&battery_present) == FALSE) { return; } if (battery_present == FALSE) { battery_status = MISSING; } else { if (get_battery_status (&battery_status) == FALSE) { return; } /* workaround for limited/bugged batteries/drivers */ /* that unduly return unknown status */ if (battery_status == UNKNOWN && get_ac_online (&ac_online) == TRUE) { if (ac_online == TRUE) { battery_status = CHARGING; if (get_battery_charge (FALSE, &percentage, NULL) == TRUE && percentage >= 99) { battery_status = CHARGED; } } else { battery_status = DISCHARGING; } } } #define HANDLE_BATTERY_STATUS(PCT,TIM,EXP,URG) \ \ percentage = PCT; \ \ battery_string = get_battery_string (battery_status, percentage); \ time_string = get_time_string (TIM); \ \ if (old_battery_status != battery_status) { \ old_battery_status = battery_status; \ NOTIFY_MESSAGE (¬ification, battery_string, time_string, EXP, URG); \ } \ \ gtk_status_icon_set_tooltip_text (tray_icon, get_tooltip_string (battery_string, time_string)); \ gtk_status_icon_set_from_icon_name (tray_icon, get_icon_name (battery_status, percentage)); switch (battery_status) { case MISSING: HANDLE_BATTERY_STATUS (0, -1, NOTIFY_EXPIRES_NEVER, NOTIFY_URGENCY_NORMAL) break; case UNKNOWN: HANDLE_BATTERY_STATUS (0, -1, NOTIFY_EXPIRES_DEFAULT, NOTIFY_URGENCY_NORMAL) break; case CHARGED: HANDLE_BATTERY_STATUS (100, -1, NOTIFY_EXPIRES_DEFAULT, NOTIFY_URGENCY_NORMAL) break; case CHARGING: if (old_battery_status != CHARGING && estimation_needed == TRUE) { reset_battery_time_estimation (); } if (get_battery_charge (FALSE, &percentage, &time) == FALSE) { return; } HANDLE_BATTERY_STATUS (percentage, time, NOTIFY_EXPIRES_DEFAULT, NOTIFY_URGENCY_NORMAL) break; case DISCHARGING: case NOT_CHARGING: if (old_battery_status != DISCHARGING && estimation_needed == TRUE) { reset_battery_time_estimation (); } if (get_battery_charge (TRUE, &percentage, &time) == FALSE) { return; } battery_string = get_battery_string (battery_status, percentage); time_string = get_time_string (time); if (old_battery_status != DISCHARGING) { old_battery_status = DISCHARGING; NOTIFY_MESSAGE (¬ification, battery_string, time_string, NOTIFY_EXPIRES_DEFAULT, NOTIFY_URGENCY_NORMAL); battery_low = FALSE; battery_critical = FALSE; spawn_command_critical = FALSE; } if (battery_low == FALSE && percentage <= configuration.low_level) { battery_low = TRUE; battery_string = get_battery_string (LOW_LEVEL, percentage); NOTIFY_MESSAGE (¬ification, battery_string, time_string, NOTIFY_EXPIRES_NEVER, NOTIFY_URGENCY_NORMAL); } if (battery_critical == FALSE && percentage <= configuration.critical_level) { battery_critical = TRUE; battery_string = get_battery_string (CRITICAL_LEVEL, percentage); NOTIFY_MESSAGE (¬ification, battery_string, time_string, NOTIFY_EXPIRES_NEVER, NOTIFY_URGENCY_CRITICAL); spawn_command_critical = TRUE; } gtk_status_icon_set_tooltip_text (tray_icon, get_tooltip_string (battery_string, time_string)); gtk_status_icon_set_from_icon_name (tray_icon, get_icon_name (battery_status, percentage)); if (spawn_command_critical == TRUE) { spawn_command_critical = FALSE; if (configuration.command_critical_level != NULL) { syslog (LOG_CRIT, _("Spawning critical battery level command in 30 seconds: %s"), configuration.command_critical_level); g_usleep (G_USEC_PER_SEC * 30); if (g_spawn_command_line_async (configuration.command_critical_level, &error) == FALSE) { syslog (LOG_CRIT, _("Cannot spawn critical battery level command: %s"), error->message); g_error_free (error); error = NULL; NOTIFY_MESSAGE (¬ification, _("Cannot spawn critical battery level command!"), configuration.command_critical_level, NOTIFY_EXPIRES_NEVER, NOTIFY_URGENCY_CRITICAL); } } } break; } }
const struct linux_logo * __init_refok fb_find_logo(int depth) { struct linux_logo *logo = NULL; const struct linux_logo *m_logo = NULL; if (nologo) return NULL; if (depth >= 1) { #ifdef CONFIG_LOGO_LINUX_MONO /* Generic Linux logo */ logo = &logo_linux_mono; #endif #ifdef CONFIG_LOGO_SUPERH_MONO /* SuperH Linux logo */ logo = &logo_superh_mono; #endif } if (depth >= 4) { #ifdef CONFIG_LOGO_LINUX_VGA16 /* Generic Linux logo */ logo = &logo_linux_vga16; #endif #ifdef CONFIG_LOGO_BLACKFIN_VGA16 /* Blackfin processor logo */ logo = &logo_blackfin_vga16; #endif #ifdef CONFIG_LOGO_SUPERH_VGA16 /* SuperH Linux logo */ logo = &logo_superh_vga16; #endif } if (depth >= 8) { #ifdef CONFIG_LOGO_LINUX_CLUT224 /* Generic Linux logo */ logo = &logo_linux_clut224; #endif #ifdef CONFIG_LOGO_PIPO_CLUT224 /* Generic Linux logo */ logo = &logo_pipo_clut224; #endif #ifdef CONFIG_LOGO_HAIER_1043_CLUT224 /* HaierPad 1043 custom logo */ logo = &logo_haier_1043_clut224; #endif #ifdef CONFIG_LOGO_LINUX_NYAN_CLUT224 /* Generic Linux logo */ logo = &logo_linux_nyan_clut224; #endif #ifdef CONFIG_LOGO_LINUX_KURISU_CLUT224 /* Generic Linux logo */ logo = &logo_linux_kurisu_clut224; #endif #ifdef CONFIG_LOGO_G3_CLUT224 /* Generic Linux logo */ logo = &logo_g3_clut224; #endif #ifdef CONFIG_LOGO_BLACKFIN_CLUT224 /* Blackfin Linux logo */ logo = &logo_blackfin_clut224; #endif #ifdef CONFIG_LOGO_DEC_CLUT224 /* DEC Linux logo on MIPS/MIPS64 or ALPHA */ logo = &logo_dec_clut224; #endif #ifdef CONFIG_LOGO_MAC_CLUT224 /* Macintosh Linux logo on m68k */ if (MACH_IS_MAC) logo = &logo_mac_clut224; #endif #ifdef CONFIG_LOGO_PARISC_CLUT224 /* PA-RISC Linux logo */ logo = &logo_parisc_clut224; #endif #ifdef CONFIG_LOGO_SGI_CLUT224 /* SGI Linux logo on MIPS/MIPS64 and VISWS */ logo = &logo_sgi_clut224; #endif #ifdef CONFIG_LOGO_SUN_CLUT224 /* Sun Linux logo */ logo = &logo_sun_clut224; #endif #ifdef CONFIG_LOGO_SUPERH_CLUT224 /* SuperH Linux logo */ logo = &logo_superh_clut224; #endif #ifdef CONFIG_LOGO_M32R_CLUT224 /* M32R Linux logo */ logo = &logo_m32r_clut224; #endif #ifdef CONFIG_LOGO_CRUZ_CLUT224 logo = &logo_cruz_clut224; #endif #ifdef CONFIG_LOGO_LINUX_800x480_CLUT224 logo = &logo_linux_800x480_clut224; #endif #ifdef CONFIG_LOGO_LOWERPOWER_WARNING if( 1 == get_battery_status()){ logo = &logo_linux_lowerpower_clut224; } #endif if (depth >= 24) { #ifdef CONFIG_LOGO_LINUX_BMP #ifdef CONFIG_LOGO_LINUX_BMP_SUNSET logo = &logo_sunset_bmp; #endif #ifdef CONFIG_LOGO_LINUX_BMP_ANDROID logo = &logo_android_bmp; #endif #endif } else { logo->width = ((logo->data[0] << 8) + logo->data[1]); logo->height = ((logo->data[2] << 8) + logo->data[3]); logo->clutsize = logo->clut[0]; logo->data += 4; logo->clut += 1; } } m_logo = logo; return m_logo; }