X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fsmapi.c;h=e6893b427a014d7357798f6643e7a8b659fe8fec;hb=13188c8b110a8cc94f43bc6c5a37b073e3b78430;hp=1a2d330c93b164e0784c45cafff4bd9c1e63fb35;hpb=dc3ed8df13fdfb6c921b7411a587af83db58e883;p=monky diff --git a/src/smapi.c b/src/smapi.c index 1a2d330..e6893b4 100644 --- a/src/smapi.c +++ b/src/smapi.c @@ -1,4 +1,7 @@ -/* smapi.c: conky support for IBM Thinkpad smapi +/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- + * vim: ts=4 sw=4 noet ai cindent syntax=c + * + * smapi.c: conky support for IBM Thinkpad smapi * * Copyright (C) 2007 Phil Sutter * @@ -18,8 +21,16 @@ * USA. * */ - +#define _GNU_SOURCE +#include "conky.h" /* text_buffer_size, PACKAGE_NAME, maybe more */ #include "smapi.h" +#include "temphelper.h" +#include "logging.h" +#include +#include +#include +#include +#include #define SYS_SMAPI_PATH "/sys/devices/platform/smapi" @@ -92,7 +103,7 @@ char *smapi_get_bat_val(const char *args) if(sscanf(args, "%i %n", &idx, &cnt) <= 0 || snprintf(fname, 127, "%s", (args + cnt)) < 0) { - ERR("smapi: wrong arguments, should be 'bat,,'"); + NORM_ERR("smapi: wrong arguments, should be 'bat,,'"); return NULL; } @@ -114,3 +125,62 @@ char *smapi_get_val(const char *args) return smapi_get_str(str); } + +void print_smapi(struct text_object *obj, char *p, int p_max_size) +{ + char *s; + + if (!obj->data.s) + return; + + s = smapi_get_val(obj->data.s); + snprintf(p, p_max_size, "%s", s); + free(s); +} + +void print_smapi_bat_perc(struct text_object *obj, char *p, int p_max_size) +{ + int idx, val; + if (obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) { + val = smapi_bat_installed(idx) ? + smapi_get_bat_int(idx, "remaining_percent") : 0; + percent_print(p, p_max_size, val); + } else + NORM_ERR("argument to smapi_bat_perc must be an integer"); +} + +void print_smapi_bat_temp(struct text_object *obj, char *p, int p_max_size) +{ + int idx, val; + if (obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) { + val = smapi_bat_installed(idx) ? + smapi_get_bat_int(idx, "temperature") : 0; + /* temperature is in milli degree celsius */ + temp_print(p, p_max_size, val / 1000, TEMP_CELSIUS); + } else + NORM_ERR("argument to smapi_bat_temp must be an integer"); +} + +void print_smapi_bat_power(struct text_object *obj, char *p, int p_max_size) +{ + int idx, val; + if (obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) { + val = smapi_bat_installed(idx) ? + smapi_get_bat_int(idx, "power_now") : 0; + /* power_now is in mW, set to W with one digit precision */ + snprintf(p, p_max_size, "%.1f", ((double)val / 1000)); + } else + NORM_ERR("argument to smapi_bat_power must be an integer"); +} + +void print_smapi_bat_bar(struct text_object *obj, char *p, int p_max_size) +{ + if (!p_max_size) + return; + + if (obj->data.i >= 0 && smapi_bat_installed(obj->data.i)) + new_bar(obj, p, p_max_size, (int) + (255 * smapi_get_bat_int(obj->data.i, "remaining_percent") / 100)); + else + new_bar(obj, p, p_max_size, 0); +}