forked from enlightenment/enlightenment
battery/batman: Various Improvements.
This adds support for multiple batteries on FreeBSD in line with Linux and OpenBSD. Also display the vendor and model where applicable. There are also fixes specific to the sysctl interface. Fixes a potential crash and let's us have 100 batman gadgets if wanted.
This commit is contained in:
parent
2c5c243b9e
commit
6b70114c6d
|
@ -126,7 +126,8 @@ _battery_sysctl_start(void)
|
||||||
# endif
|
# endif
|
||||||
_battery_sysctl_battery_update();
|
_battery_sysctl_battery_update();
|
||||||
|
|
||||||
bat->last_update = ecore_time_get();
|
if (bat)
|
||||||
|
bat->last_update = ecore_time_get();
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -184,6 +185,8 @@ _battery_sysctl_battery_update()
|
||||||
ecore_poller_poller_interval_set(bat->poll,
|
ecore_poller_poller_interval_set(bat->poll,
|
||||||
battery_config->poll_interval);
|
battery_config->poll_interval);
|
||||||
# if defined(__OpenBSD__) || defined(__NetBSD__)
|
# if defined(__OpenBSD__) || defined(__NetBSD__)
|
||||||
|
charge = 0;
|
||||||
|
|
||||||
/* last full capacity */
|
/* last full capacity */
|
||||||
bat->mib[3] = 7;
|
bat->mib[3] = 7;
|
||||||
bat->mib[4] = 0;
|
bat->mib[4] = 0;
|
||||||
|
|
|
@ -98,7 +98,9 @@ _batman_popup_create(Instance *inst)
|
||||||
elm_box_pack_end(box, label);
|
elm_box_pack_end(box, label);
|
||||||
evas_object_show(label);
|
evas_object_show(label);
|
||||||
|
|
||||||
if (inst->cfg->batman.have_power && (inst->cfg->batman.full < 99))
|
if (eina_list_count(batman_device_batteries) == 0)
|
||||||
|
snprintf(buf, sizeof(buf), _("No Battery Found"));
|
||||||
|
else if (inst->cfg->batman.have_power && (inst->cfg->batman.full < 99))
|
||||||
snprintf(buf, sizeof(buf), _("Battery Charging"));
|
snprintf(buf, sizeof(buf), _("Battery Charging"));
|
||||||
else if (inst->cfg->batman.full >= 99)
|
else if (inst->cfg->batman.full >= 99)
|
||||||
snprintf(buf, sizeof(buf), _("Battery Fully Charged"));
|
snprintf(buf, sizeof(buf), _("Battery Fully Charged"));
|
||||||
|
@ -112,6 +114,16 @@ _batman_popup_create(Instance *inst)
|
||||||
if (!eina_list_count(udis) || !eina_list_data_find(udis, bat->udi))
|
if (!eina_list_count(udis) || !eina_list_data_find(udis, bat->udi))
|
||||||
{
|
{
|
||||||
udis = eina_list_append(udis, bat->udi);
|
udis = eina_list_append(udis, bat->udi);
|
||||||
|
if (bat->vendor && bat->vendor[0] && bat->model && bat->model[0])
|
||||||
|
{
|
||||||
|
label = elm_label_add(box);
|
||||||
|
E_EXPAND(label); E_ALIGN(label, 0.5, 0.5);
|
||||||
|
snprintf(buf, sizeof(buf), "%s (%s)", bat->vendor, bat->model);
|
||||||
|
elm_object_text_set(label, buf);
|
||||||
|
elm_box_pack_end(box, label);
|
||||||
|
evas_object_show(label);
|
||||||
|
}
|
||||||
|
|
||||||
pbar = elm_progressbar_add(box);
|
pbar = elm_progressbar_add(box);
|
||||||
E_EXPAND(pbar); E_FILL(pbar);
|
E_EXPAND(pbar); E_FILL(pbar);
|
||||||
elm_progressbar_span_size_set(pbar, 200 * e_scale);
|
elm_progressbar_span_size_set(pbar, 200 * e_scale);
|
||||||
|
|
|
@ -58,13 +58,6 @@ struct _Battery
|
||||||
Eina_Bool got_prop E_BITFIELD;
|
Eina_Bool got_prop E_BITFIELD;
|
||||||
Eldbus_Proxy *proxy;
|
Eldbus_Proxy *proxy;
|
||||||
int * mib;
|
int * mib;
|
||||||
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
|
||||||
int * mib_state;
|
|
||||||
int * mib_units;
|
|
||||||
int * mib_time;
|
|
||||||
int batteries;
|
|
||||||
int time_min;
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _Ac_Adapter
|
struct _Ac_Adapter
|
||||||
|
|
|
@ -3,6 +3,11 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
|
|
||||||
|
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
||||||
|
# include <dev/acpica/acpiio.h>
|
||||||
|
# include <sys/ioctl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(__OpenBSD__) || defined(__NetBSD__)
|
#if defined(__OpenBSD__) || defined(__NetBSD__)
|
||||||
# include <sys/param.h>
|
# include <sys/param.h>
|
||||||
# include <sys/sensors.h>
|
# include <sys/sensors.h>
|
||||||
|
@ -25,10 +30,13 @@ _batman_sysctl_start(Instance *inst)
|
||||||
struct sensordev snsrdev;
|
struct sensordev snsrdev;
|
||||||
size_t sdlen = sizeof(struct sensordev);
|
size_t sdlen = sizeof(struct sensordev);
|
||||||
char name[256];
|
char name[256];
|
||||||
#elif defined(__FreeBSD__) || defined(__DragonFly__)
|
|
||||||
size_t len;
|
if (eina_list_count(batman_device_batteries) != 0)
|
||||||
#endif
|
{
|
||||||
#if defined(__OpenBSD__) || defined(__NetBSD__)
|
_batman_sysctl_battery_update(inst);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
for (devn = 0;; devn++)
|
for (devn = 0;; devn++)
|
||||||
{
|
{
|
||||||
mib[2] = devn;
|
mib[2] = devn;
|
||||||
|
@ -79,41 +87,49 @@ _batman_sysctl_start(Instance *inst)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#elif defined(__FreeBSD__) || defined(__DragonFly__)
|
#elif defined(__FreeBSD__) || defined(__DragonFly__)
|
||||||
if ((sysctlbyname("hw.acpi.battery.life", NULL, &len, NULL, 0)) != -1)
|
size_t len;
|
||||||
|
int i, count, fd;
|
||||||
|
union acpi_battery_ioctl_arg battio;
|
||||||
|
|
||||||
|
if (eina_list_count(batman_device_batteries) != 0)
|
||||||
{
|
{
|
||||||
Battery *bat = E_NEW(Battery, 1);
|
_batman_sysctl_battery_update(inst);
|
||||||
if (!bat)
|
return 1;
|
||||||
return 0;
|
|
||||||
bat->inst = inst;
|
|
||||||
bat->mib = malloc(sizeof(int) * 4);
|
|
||||||
if (!bat->mib) return 0;
|
|
||||||
sysctlnametomib("hw.acpi.battery.life", bat->mib, &len);
|
|
||||||
|
|
||||||
bat->mib_state = malloc(sizeof(int) * 4);
|
|
||||||
if (!bat->mib_state) return 0;
|
|
||||||
sysctlnametomib("hw.acpi.battery.state", bat->mib_state, &len);
|
|
||||||
|
|
||||||
bat->mib_time = malloc(sizeof(int) * 4);
|
|
||||||
if (!bat->mib_time) return 0;
|
|
||||||
sysctlnametomib("hw.acpi.battery.time", bat->mib_time, &len);
|
|
||||||
|
|
||||||
bat->mib_units = malloc(sizeof(int) * 4);
|
|
||||||
if (!bat->mib_units) return 0;
|
|
||||||
sysctlnametomib("hw.acpi.battery.units", bat->mib_units, &len);
|
|
||||||
|
|
||||||
bat->last_update = ecore_time_get();
|
|
||||||
bat->udi = eina_stringshare_add("hw.acpi.battery");
|
|
||||||
bat->technology = eina_stringshare_add("Unknown");
|
|
||||||
bat->model = eina_stringshare_add("Unknown");
|
|
||||||
bat->vendor = eina_stringshare_add("Unknown");
|
|
||||||
|
|
||||||
bat->poll = ecore_poller_add(ECORE_POLLER_CORE,
|
|
||||||
inst->cfg->batman.poll_interval,
|
|
||||||
_batman_sysctl_battery_update_poll, inst);
|
|
||||||
|
|
||||||
batman_device_batteries = eina_list_append(batman_device_batteries, bat);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((fd = open("/dev/acpi", O_RDONLY)) == -1)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (ioctl(fd, ACPIIO_BATT_GET_UNITS, &count) == -1)
|
||||||
|
{
|
||||||
|
close(fd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
battio.unit = i;
|
||||||
|
if (ioctl(fd, ACPIIO_BATT_GET_BIF, &battio) != -1)
|
||||||
|
{
|
||||||
|
Battery *bat = E_NEW(Battery, 1);
|
||||||
|
if (!bat) return 0;
|
||||||
|
|
||||||
|
bat->inst = inst;
|
||||||
|
bat->last_update = ecore_time_get();
|
||||||
|
bat->last_full_charge = battio.bif.lfcap;
|
||||||
|
bat->model = eina_stringshare_add(battio.bif.model);
|
||||||
|
bat->vendor = eina_stringshare_add(battio.bif.oeminfo);
|
||||||
|
bat->technology = eina_stringshare_add(battio.bif.type);
|
||||||
|
bat->poll = ecore_poller_add(ECORE_POLLER_CORE,
|
||||||
|
inst->cfg->batman.poll_interval,
|
||||||
|
_batman_sysctl_battery_update_poll, inst);
|
||||||
|
|
||||||
|
batman_device_batteries = eina_list_append(batman_device_batteries, bat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
|
||||||
if ((sysctlbyname("hw.acpi.acline", NULL, &len, NULL, 0)) != -1)
|
if ((sysctlbyname("hw.acpi.acline", NULL, &len, NULL, 0)) != -1)
|
||||||
{
|
{
|
||||||
Ac_Adapter *ac = E_NEW(Ac_Adapter, 1);
|
Ac_Adapter *ac = E_NEW(Ac_Adapter, 1);
|
||||||
|
@ -155,11 +171,6 @@ _batman_sysctl_stop(void)
|
||||||
E_FREE_FUNC(bat->model, eina_stringshare_del);
|
E_FREE_FUNC(bat->model, eina_stringshare_del);
|
||||||
E_FREE_FUNC(bat->vendor, eina_stringshare_del);
|
E_FREE_FUNC(bat->vendor, eina_stringshare_del);
|
||||||
E_FREE_FUNC(bat->poll, ecore_poller_del);
|
E_FREE_FUNC(bat->poll, ecore_poller_del);
|
||||||
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
|
||||||
E_FREE(bat->mib_state);
|
|
||||||
E_FREE(bat->mib_time);
|
|
||||||
E_FREE(bat->mib_units);
|
|
||||||
#endif
|
|
||||||
E_FREE(bat->mib);
|
E_FREE(bat->mib);
|
||||||
E_FREE(bat);
|
E_FREE(bat);
|
||||||
}
|
}
|
||||||
|
@ -189,9 +200,9 @@ _batman_sysctl_battery_update(Instance *inst)
|
||||||
struct sensor s;
|
struct sensor s;
|
||||||
size_t slen = sizeof(struct sensor);
|
size_t slen = sizeof(struct sensor);
|
||||||
#elif defined(__FreeBSD__) || defined(__DragonFly__)
|
#elif defined(__FreeBSD__) || defined(__DragonFly__)
|
||||||
double _time;
|
union acpi_battery_ioctl_arg battio;
|
||||||
int value;
|
|
||||||
size_t len;
|
size_t len;
|
||||||
|
int value, fd, i = 0;
|
||||||
#endif
|
#endif
|
||||||
EINA_LIST_FOREACH(batman_device_batteries, l, bat)
|
EINA_LIST_FOREACH(batman_device_batteries, l, bat)
|
||||||
{
|
{
|
||||||
|
@ -284,44 +295,38 @@ _batman_sysctl_battery_update(Instance *inst)
|
||||||
}
|
}
|
||||||
_batman_device_update(bat->inst);
|
_batman_device_update(bat->inst);
|
||||||
#elif defined(__FreeBSD__) || defined(__DragonFly__)
|
#elif defined(__FreeBSD__) || defined(__DragonFly__)
|
||||||
len = sizeof(value);
|
|
||||||
if ((sysctl(bat->mib, 4, &value, &len, NULL, 0)) == -1)
|
if ((fd = open("/dev/acpi", O_RDONLY)) != -1)
|
||||||
{
|
{
|
||||||
return EINA_FALSE;
|
battio.unit = i;
|
||||||
|
|
||||||
|
if (ioctl(fd, ACPIIO_BATT_GET_BATTINFO, &battio) != -1)
|
||||||
|
{
|
||||||
|
bat->got_prop = 1;
|
||||||
|
|
||||||
|
bat->percent = battio.battinfo.cap;
|
||||||
|
|
||||||
|
if (battio.battinfo.state & ACPI_BATT_STAT_CHARGING)
|
||||||
|
bat->charging = EINA_TRUE;
|
||||||
|
else
|
||||||
|
bat->charging = EINA_FALSE;
|
||||||
|
|
||||||
|
bat->time_left = battio.battinfo.min * 60;
|
||||||
|
if (bat->charge_rate > 0)
|
||||||
|
{
|
||||||
|
bat->time_full = (bat->last_full_charge - bat->current_charge) / bat->charge_rate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bat->time_full = bat->time_left = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
bat->percent = value;
|
|
||||||
|
|
||||||
_time = ecore_time_get();
|
|
||||||
bat->last_update = _time;
|
|
||||||
|
|
||||||
len = sizeof(value);
|
|
||||||
if ((sysctl(bat->mib_state, 4, &value, &len, NULL, 0)) == -1)
|
|
||||||
{
|
|
||||||
return EINA_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
bat->charging = !value;
|
|
||||||
bat->got_prop = 1;
|
|
||||||
|
|
||||||
bat->time_full = -1;
|
|
||||||
bat->time_left = -1;
|
|
||||||
|
|
||||||
len = sizeof(bat->time_min);
|
|
||||||
if ((sysctl(bat->mib_time, 4, &bat->time_min, &len, NULL, 0)) == -1)
|
|
||||||
{
|
|
||||||
bat->time_min = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
len = sizeof(bat->batteries);
|
|
||||||
if ((sysctl(bat->mib_units, 4, &bat->batteries, &len, NULL, 0)) == -1)
|
|
||||||
{
|
|
||||||
bat->batteries = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bat->time_min >= 0) bat->time_left = bat->time_min * 60;
|
|
||||||
if (bat->batteries == 1) bat->time_left = -1;
|
|
||||||
_batman_device_update(inst);
|
_batman_device_update(inst);
|
||||||
|
i++;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue