[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris.changes
|
|
[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris.spec
^
|
|
[-]
[+]
|
Changed |
_service
^
|
@@ -2,7 +2,7 @@
<service name="tar_git">
<param name="url">https://github.com/nemomobile/mce-plugin-libhybris.git</param>
<param name="branch">master</param>
- <param name="revision">7d214b910530f9474331fe2e890ec48081361966</param>
+ <param name="revision">3e4e459f47f5cb995172e4141834b89012024039</param>
<param name="token"/>
<param name="debian"/>
<param name="dumb"/>
|
[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris-1.12.0.tar.bz2/.depend
^
|
@@ -98,6 +98,7 @@
sysfs-led-bacon.o:\
sysfs-led-bacon.c\
+ plugin-config.h\
plugin-logging.h\
sysfs-led-bacon.h\
sysfs-led-main.h\
@@ -105,6 +106,7 @@
sysfs-led-bacon.pic.o:\
sysfs-led-bacon.c\
+ plugin-config.h\
plugin-logging.h\
sysfs-led-bacon.h\
sysfs-led-main.h\
@@ -112,18 +114,26 @@
sysfs-led-binary.o:\
sysfs-led-binary.c\
+ plugin-config.h\
+ plugin-logging.h\
sysfs-led-binary.h\
sysfs-led-main.h\
sysfs-led-util.h\
+ sysfs-val.h\
sysfs-led-binary.pic.o:\
sysfs-led-binary.c\
+ plugin-config.h\
+ plugin-logging.h\
sysfs-led-binary.h\
sysfs-led-main.h\
sysfs-led-util.h\
+ sysfs-val.h\
sysfs-led-f5121.o:\
sysfs-led-f5121.c\
+ plugin-config.h\
+ plugin-logging.h\
sysfs-led-f5121.h\
sysfs-led-main.h\
sysfs-led-util.h\
@@ -131,6 +141,8 @@
sysfs-led-f5121.pic.o:\
sysfs-led-f5121.c\
+ plugin-config.h\
+ plugin-logging.h\
sysfs-led-f5121.h\
sysfs-led-main.h\
sysfs-led-util.h\
@@ -138,27 +150,37 @@
sysfs-led-hammerhead.o:\
sysfs-led-hammerhead.c\
+ plugin-config.h\
+ plugin-logging.h\
sysfs-led-hammerhead.h\
sysfs-led-main.h\
sysfs-led-util.h\
sysfs-led-hammerhead.pic.o:\
sysfs-led-hammerhead.c\
+ plugin-config.h\
+ plugin-logging.h\
sysfs-led-hammerhead.h\
sysfs-led-main.h\
sysfs-led-util.h\
sysfs-led-htcvision.o:\
sysfs-led-htcvision.c\
+ plugin-config.h\
+ plugin-logging.h\
sysfs-led-htcvision.h\
sysfs-led-main.h\
sysfs-led-util.h\
+ sysfs-val.h\
sysfs-led-htcvision.pic.o:\
sysfs-led-htcvision.c\
+ plugin-config.h\
+ plugin-logging.h\
sysfs-led-htcvision.h\
sysfs-led-main.h\
sysfs-led-util.h\
+ sysfs-val.h\
sysfs-led-main.o:\
sysfs-led-main.c\
@@ -194,15 +216,21 @@
sysfs-led-redgreen.o:\
sysfs-led-redgreen.c\
+ plugin-config.h\
+ plugin-logging.h\
sysfs-led-main.h\
sysfs-led-redgreen.h\
sysfs-led-util.h\
+ sysfs-val.h\
sysfs-led-redgreen.pic.o:\
sysfs-led-redgreen.c\
+ plugin-config.h\
+ plugin-logging.h\
sysfs-led-main.h\
sysfs-led-redgreen.h\
sysfs-led-util.h\
+ sysfs-val.h\
sysfs-led-util.o:\
sysfs-led-util.c\
@@ -216,27 +244,39 @@
sysfs-led-vanilla.o:\
sysfs-led-vanilla.c\
+ plugin-config.h\
+ plugin-logging.h\
sysfs-led-main.h\
sysfs-led-util.h\
sysfs-led-vanilla.h\
+ sysfs-val.h\
sysfs-led-vanilla.pic.o:\
sysfs-led-vanilla.c\
+ plugin-config.h\
+ plugin-logging.h\
sysfs-led-main.h\
sysfs-led-util.h\
sysfs-led-vanilla.h\
+ sysfs-val.h\
sysfs-led-white.o:\
sysfs-led-white.c\
+ plugin-config.h\
+ plugin-logging.h\
sysfs-led-main.h\
sysfs-led-util.h\
sysfs-led-white.h\
+ sysfs-val.h\
sysfs-led-white.pic.o:\
sysfs-led-white.c\
+ plugin-config.h\
+ plugin-logging.h\
sysfs-led-main.h\
sysfs-led-util.h\
sysfs-led-white.h\
+ sysfs-val.h\
sysfs-val.o:\
sysfs-val.c\
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.0.tar.bz2/inifiles/60-bacon.ini
^
|
@@ -0,0 +1,24 @@
+[LEDConfigHybris]
+
+# Choose bacon backend
+BackEnd=bacon
+
+# Configure base directories for red/green/blue channels
+RedDirectory=/sys/class/leds/red
+GreenDirectory=/sys/class/leds/green
+BlueDirectory=/sys/class/leds/blue
+
+# Built-in defaults for directory relative paths
+#BrightnessFile=brightness
+#GrpFreqFile=device/grpfreq
+#GrpPwmFile=device/grppwm
+#BlinkFile=device/blink
+#LedResetFile=device/ledreset
+
+# Optional channel specific overrides
+#RedBrightnessFile=/sys/class/leds/red/brightness
+#RedGrpFreqFile=/sys/class/leds/red/device/grpfreq
+#RedGrpPwmFile=/sys/class/leds/red/device/grppwm
+#RedBlinkFile=/sys/class/leds/red/device/blink
+#RedLedResetFile=/sys/class/leds/red/device/ledreset
+# ... and similarly for Green and Blue.
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.0.tar.bz2/inifiles/60-binary.ini
^
|
@@ -0,0 +1,15 @@
+[LEDConfigHybris]
+
+# Choose binary backend
+BackEnd=binary
+
+# Configure base directories for binary channel
+LedDirectory=/sys/class/leds/binary
+
+# Built-in defaults for directory relative paths
+#BrightnessFile=brightness
+#MaxBrightnessFile=max_brightness
+
+# Optional channel specific overrides
+#LedBrightnessFile=/sys/class/leds/binary/brightness
+#LedMaxBrightnessFile=/sys/class/leds/binary/max_brightness
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.0.tar.bz2/inifiles/60-f5121.ini
^
|
@@ -0,0 +1,20 @@
+[LEDConfigHybris]
+
+# Choose f5121 backend
+BackEnd=f5121
+
+# Configure base directories for red/green/blue channels
+RedDirectory=/sys/class/leds/red
+GreenDirectory=/sys/class/leds/green
+BlueDirectory=/sys/class/leds/blue
+
+# Built-in defaults for directory relative paths
+#BrightnessFile=brightness
+#MaxBrightnessFile=max_brightness
+#BlinkFile=blink
+
+# Optional channel specific overrides
+#RedBrightnessFile=/sys/class/leds/red/brightness
+#RedMaxBrightnessFile=/sys/class/leds/red/max_brightness
+#RedBlinkFile=/sys/class/leds/red/blink
+# ... and similarly for Green and Blue.
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.0.tar.bz2/inifiles/60-hammerhead.ini
^
|
@@ -0,0 +1,22 @@
+[LEDConfigHybris]
+
+# Choose hammerhead backend
+BackEnd=hammerhead
+
+# Configure base directories for red/green/blue channels
+RedDirectory=/sys/class/leds/red
+GreenDirectory=/sys/class/leds/green
+BlueDirectory=/sys/class/leds/blue
+
+# Built-in defaults for directory relative paths
+#BrightnessFile=brightness
+#MaxBrightnessFile=max_brightness
+#OnOffMsFile=on_off_ms
+#RgbStartFile=rgb_start
+
+# Optional channel specific overrides
+#RedBrightnessFile=/sys/class/leds/red/brightness
+#RedMaxBrightnessFile=/sys/class/leds/red/max_brightness
+#RedOnOffMsFile=/sys/class/leds/red/on_off_ms
+#RedRgbStartFile=/sys/class/leds/red/rgb_start
+# ... and similarly for Green and Blue.
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.0.tar.bz2/inifiles/60-htcvision.ini
^
|
@@ -0,0 +1,19 @@
+[LEDConfigHybris]
+
+# Choose htcvision backend
+BackEnd=htcvision
+
+# Configure base directories for amber/green channels
+AmberDirectory=/sys/class/leds/amber
+GreenDirectory=/sys/class/leds/green
+
+# Built-in defaults for directory relative paths
+#BrightnessFile=brightness
+#MaxBrightnessFile=max_brightness
+#BlinkFile=blink
+
+# Optional channel specific overrides
+#AmberBrightnessFile=/sys/class/leds/amber/brightness
+#AmberMaxBrightnessFile=/sys/class/leds/amber/max_brightness
+#AmberBlinkFile=/sys/class/leds/amber/blink
+# ... and similarly for Green.
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.0.tar.bz2/inifiles/60-redgreen.ini
^
|
@@ -0,0 +1,17 @@
+[LEDConfigHybris]
+
+# Choose redgreen backend
+BackEnd=redgreen
+
+# Configure base directories for red/green/blue channels
+RedDirectory=/sys/class/leds/red
+GreenDirectory=/sys/class/leds/green
+
+# Built-in defaults for directory relative paths
+#BrightnessFile=brightness
+#MaxBrightnessFile=max_brightness
+
+# Optional channel specific overrides
+#RedBrightnessFile=/sys/class/leds/red/brightness
+#RedMaxBrightnessFile=/sys/class/leds/red/max_brightness
+# ... and similarly for Green.
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.0.tar.bz2/inifiles/60-vanilla.ini
^
|
@@ -0,0 +1,24 @@
+[LEDConfigHybris]
+
+# Choose vanilla backend
+BackEnd=vanilla
+
+# Configure base directories for red/green/blue channels
+RedDirectory=/sys/class/leds/red
+GreenDirectory=/sys/class/leds/green
+BlueDirectory=/sys/class/leds/blue
+
+# Built-in defaults for directory relative paths
+#BrightnessFile=brightness
+#MaxBrightnessFile=max_brightness
+#BlinkDelayOnFile=blink_delay_on
+#BlinkDelayOffFile=blink_delay_off
+#BlinkFile=blink
+
+# Optional channel specific overrides
+#RedBrightnessFile=/sys/class/leds/red/brightness
+#RedMaxBrightnessFile=/sys/class/leds/red/max_brightness
+#RedBlinkDelayOnFile=/sys/class/leds/red/blink_delay_on
+#RedBlinkDelayOffFile=/sys/class/leds/red/blink_delay_off
+#RedBlinkFile=/sys/class/leds/red/blink
+# ... and similarly for Green and Blue.
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.0.tar.bz2/inifiles/60-white.ini
^
|
@@ -0,0 +1,15 @@
+[LEDConfigHybris]
+
+# Choose white backend
+BackEnd=white
+
+# Configure base directories for white channel
+LedDirectory=/sys/class/leds/white
+
+# Built-in defaults for directory relative paths
+#BrightnessFile=brightness
+#MaxBrightnessFile=max_brightness
+
+# Optional channel specific overrides
+#LedBrightnessFile=/sys/class/leds/white/brightness
+#LedMaxBrightnessFile=/sys/class/leds/white/max_brightness
|
[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris-1.12.0.tar.bz2/plugin-config.c
^
|
@@ -25,6 +25,10 @@
#include "plugin-logging.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
/* ========================================================================= *
* SETTINGS
* ========================================================================= */
@@ -49,11 +53,110 @@
* settings are optional -> check that key actually exists before
* attempting to fetch the value to avoid unwanted logging. */
if( !mce_conf_has_key(group, key) )
- goto EXIT;
+ res = defaultval ? g_strdup(defaultval) : 0;
+ else
+ res = mce_conf_get_string(group, key, defaultval);
- if( (res = mce_conf_get_string(group, key, defaultval)) )
- mce_log(LOG_DEBUG, "[%s] %s = %s", group, key, res ?: "(null)");
+ mce_log(LOG_DEBUG, "[%s] %s = %s", group, key, res ?: "(null)");
-EXIT:
return res;
}
+
+static inline void *lea(const void *base, int offs)
+{
+ return ((char *)base)+offs;
+}
+
+/** Set all configurable dynamic data to null
+ *
+ * @param cfg configuration lookup table
+ * @param obj object to configure
+ */
+void
+objconf_init(const objconf_t *cfg, void *obj)
+{
+ for( size_t i = 0; cfg[i].key; ++i ) {
+ char **memb = lea(obj, cfg[i].off);
+ *memb = 0;
+ }
+}
+
+/** Release all configurable dynamic data
+ *
+ * @param cfg configuration lookup table
+ * @param obj object to configure
+ */
+void
+objconf_quit(const objconf_t *cfg, void *obj)
+{
+ for( size_t i = 0; cfg[i].key; ++i ) {
+ char **memb = lea(obj, cfg[i].off);
+ free(*memb), *memb = 0;
+ }
+}
+
+/** Parse all configurable dynamic data
+ *
+ * @param cfg configuration lookup table
+ * @param obj object to configure
+ *
+ * @return true if at least one member was set, false otherwise
+ */
+bool
+objconf_parse(const objconf_t *cfg, void *obj, const char *chn)
+{
+ int set = 0;
+ gchar *dir = 0;
+
+ char tmp[256];
+
+ /* Fetch channel/led directory in form of:
+ *
+ * <CHANNEL><Directory>=/sys/class/leds/red
+ *
+ * Where CHANNEL depends on backend but should be something
+ * like "Led" for single channel leds and "Red", "Green" etc
+ * for multichannel leds.
+ */
+ snprintf(tmp, sizeof tmp, "%sDirectory", chn);
+ dir = plugin_config_get_string(MCE_CONF_LED_CONFIG_HYBRIS_GROUP, tmp, 0);
+
+ for( size_t i = 0; cfg[i].key; ++i ) {
+ char **memb = lea(obj, cfg[i].off);
+
+ /* Fetch absolute control file path in form of
+ * <CHANNEL><MEMBER>File=sys/class/leds/red/brightness
+ *
+ * Where MEMBER is "Brightness", "MaxBrightness", etc
+ */
+ snprintf(tmp, sizeof tmp, "%s%sFile", chn, cfg[i].key);
+ gchar *val = plugin_config_get_string(MCE_CONF_LED_CONFIG_HYBRIS_GROUP,
+ tmp, 0);
+ if( val ) {
+ snprintf(tmp, sizeof tmp, "%s/%s", dir, val);
+ free(*memb), *memb = strdup(tmp);
+ g_free(val);
+ }
+ else if( dir ) {
+ /* Fetch control file path relative to directory
+ *
+ * <MEMBER>File=brightness
+ */
+ snprintf(tmp, sizeof tmp, "%sFile", cfg[i].key);
+ val = plugin_config_get_string(MCE_CONF_LED_CONFIG_HYBRIS_GROUP,
+ tmp, cfg[i].def);
+ if( val ) {
+ snprintf(tmp, sizeof tmp, "%s/%s", dir, val);
+ free(*memb), *memb = strdup(tmp);
+ g_free(val);
+ }
+ }
+ set += (*memb != 0);
+
+ mce_log(LOG_DEBUG, "%s:%s = %s", chn, cfg[i].key, *memb ?: "NA");
+ }
+
+ g_free(dir);
+
+ return set > 0;
+}
|
[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris-1.12.0.tar.bz2/plugin-config.h
^
|
@@ -26,6 +26,8 @@
# include "plugin-logging.h"
+# include <stdbool.h>
+
# include <glib.h>
/* ========================================================================= *
@@ -43,4 +45,49 @@
gchar * plugin_config_get_string(const gchar *group, const gchar *key, const gchar *defaultval);
+/** Inifile to object member mapping info */
+typedef struct
+{
+ /** Ini-file key */
+ const char *key;
+
+ /** Fallback value in case key is not defined */
+ const char *def;
+
+ /** Offset within object where to store string value */
+ off_t off;
+} objconf_t;
+
+/** Object configuration entry sentinel */
+#define OBJCONF_STOP \
+ {\
+ .key = 0,\
+ }
+
+/** Object configuration entry for file path
+ *
+ * For object->member matches /sys/dir/member
+ */
+#define OBJCONF_FILE(obj_,memb_,key_)\
+ {\
+ .key = #key_,\
+ .def = #memb_,\
+ .off = offsetof(obj_,memb_),\
+ }
+
+/** Object configuration entry for file path
+ *
+ * For object->member does not match /sys/dir/member
+ */
+#define OBJCONF_FILE_EX(obj_,memb_,key_,def_)\
+ {\
+ .key = #key_,\
+ .def = def_,\
+ .off = offsetof(obj_,memb_),\
+ }
+
+void objconf_init(const objconf_t *cfg, void *obj);
+void objconf_quit(const objconf_t *cfg, void *obj);
+bool objconf_parse(const objconf_t *cfg, void *obj, const char *chn);
+
#endif /* PLUGIN_CONFIG_H_ */
|
[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris-1.12.0.tar.bz2/sysfs-led-bacon.c
^
|
@@ -37,6 +37,7 @@
#include "sysfs-led-util.h"
#include "plugin-logging.h"
+#include "plugin-config.h"
#include <stdio.h>
@@ -146,6 +147,8 @@
* ALL_CHANNELS
* ========================================================================= */
+#define BACON_CHANNELS 3
+
static void
led_control_bacon_enable_cb(void *data, bool enable)
{
@@ -153,7 +156,7 @@
mce_log(LL_INFO, "led_control_bacon_enable_cb(%d)", enable);
if(!enable)
- dprintf(channel->fd_ledreset, "%d", 1);
+ dprintf(channel->fd_ledreset, "%d", 1);
}
static void
@@ -176,7 +179,7 @@
// the low 4 bits are ignored, so round up if necessary
if( channel->pwm > 0 && channel->pwm < 16 )
- channel->pwm = 16;
+ channel->pwm = 16;
channel->blink = 1;
} else {
@@ -199,7 +202,7 @@
mce_log(LL_INFO, "led_control_bacon_value_cb(%d,%d,%d), blink=%d", r, g, b, channel->blink);
if( channel->blink )
- dprintf(channel->fd_ledreset, "%d", 0);
+ dprintf(channel->fd_ledreset, "%d", 0);
(channel+0)->brightness = led_util_scale_value(r, (channel+0)->maxval);
(channel+1)->brightness = led_util_scale_value(g, (channel+1)->maxval);
@@ -215,7 +218,7 @@
dprintf(channel->fd_grppwm, "%d", channel->pwm); // 50%?
dprintf(channel->fd_blink, "%d", 1);
} else
- dprintf(channel->fd_blink, "%d", 0);
+ dprintf(channel->fd_blink, "%d", 0);
}
static void
@@ -227,11 +230,11 @@
led_channel_bacon_close(channel + 2);
}
-bool
-led_control_bacon_probe(led_control_t *self)
+static bool
+led_control_bacon_static_probe(led_channel_bacon_t *channel)
{
/** Sysfs control paths for RGB leds */
- static const led_paths_bacon_t paths[][3] =
+ static const led_paths_bacon_t paths[][BACON_CHANNELS] =
{
// bacon
{
@@ -259,7 +262,77 @@
},
};
- static led_channel_bacon_t channel[3];
+ bool ack = false;
+
+ for( size_t i = 0; i < G_N_ELEMENTS(paths); ++i ) {
+ if( led_channel_bacon_probe(&channel[0], &paths[i][0]) &&
+ led_channel_bacon_probe(&channel[1], &paths[i][1]) &&
+ led_channel_bacon_probe(&channel[2], &paths[i][2]) ) {
+ ack = true;
+ break;
+ }
+ }
+
+ return ack;
+}
+
+static bool
+led_control_bacon_dynamic_probe(led_channel_bacon_t *channel)
+{
+ /* See inifiles/60-bacon.ini for example config file */
+ static const objconf_t bacon_conf[] =
+ {
+ OBJCONF_FILE(led_paths_bacon_t, brightness, Brightness),
+#if 0 // load from max_brightness?
+ OBJCONF_FILE(led_paths_bacon_t, max_brightness, MaxBrightness),
+#endif
+ OBJCONF_FILE_EX(led_paths_bacon_t, grpfreq, GrpFreq,
+ "device/grpfreq"),
+ OBJCONF_FILE_EX(led_paths_bacon_t, grppwm, GrpPwm,
+ "device/grppwm"),
+ OBJCONF_FILE_EX(led_paths_bacon_t, blink, Blink,
+ "device/blink"),
+ OBJCONF_FILE_EX(led_paths_bacon_t, ledreset, LedReset,
+ "device/ledreset"),
+ OBJCONF_STOP
+ };
+
+ static const char * const pfix[BACON_CHANNELS] =
+ {
+ "Red", "Green", "Blue"
+ };
+
+ bool ack = false;
+
+ led_paths_bacon_t paths[BACON_CHANNELS];
+
+ for( size_t i = 0; i < BACON_CHANNELS; ++i )
+ objconf_init(bacon_conf, &paths[i]);
+
+ for( size_t i = 0; i < BACON_CHANNELS; ++i )
+ {
+ if( !objconf_parse(bacon_conf, &paths[i], pfix[i]) )
+ goto cleanup;
+
+ if( !led_channel_bacon_probe(channel+0, &paths[i]) )
+ goto cleanup;
+ }
+
+ ack = true;
+
+cleanup:
+
+ for( size_t i = 0; i < BACON_CHANNELS; ++i )
+ objconf_quit(bacon_conf, &paths[i]);
+
+ return ack;
+}
+
+bool
+led_control_bacon_probe(led_control_t *self)
+{
+
+ static led_channel_bacon_t channel[BACON_CHANNELS];
bool res = false;
@@ -277,22 +350,14 @@
// need to check
self->can_breathe = false;
- for( size_t i = 0; i < G_N_ELEMENTS(paths) ; ++i )
- {
- if( led_channel_bacon_probe(&channel[0], &paths[i][0]) &&
- led_channel_bacon_probe(&channel[1], &paths[i][1]) &&
- led_channel_bacon_probe(&channel[2], &paths[i][2]) )
- {
- mce_log(LL_INFO, "bacon probed!");
- res = true;
- break;
- }
- }
+ if( self->use_config )
+ res = led_control_bacon_dynamic_probe(channel);
+
+ if( !res )
+ res = led_control_bacon_static_probe(channel);
if( !res )
- {
led_control_close(self);
- }
return res;
}
|
[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris-1.12.0.tar.bz2/sysfs-led-binary.c
^
|
@@ -35,6 +35,8 @@
#include "sysfs-led-binary.h"
#include "sysfs-led-util.h"
+#include "sysfs-val.h"
+#include "plugin-config.h"
#include <stdio.h>
@@ -46,14 +48,14 @@
typedef struct
{
- const char *val; // W
+ const char *brightness;
+ const char *max_brightness;
} led_paths_binary_t;
typedef struct
{
- int maxval;
- int fd_val;
- int val_last;
+ sysfsval_t *cached_max_brightness;
+ sysfsval_t *cached_brightness;
} led_channel_binary_t;
/* ------------------------------------------------------------------------- *
@@ -82,130 +84,183 @@
static void
led_channel_binary_init(led_channel_binary_t *self)
{
- self->maxval = -1;
- self->fd_val = -1;
- self->val_last = -1;
+ self->cached_max_brightness = sysfsval_create();
+ self->cached_brightness = sysfsval_create();
}
static void
led_channel_binary_close(led_channel_binary_t *self)
{
- led_util_close_file(&self->fd_val);
+ sysfsval_delete(self->cached_max_brightness),
+ self->cached_max_brightness = 0;
+
+ sysfsval_delete(self->cached_brightness),
+ self->cached_brightness = 0;
}
static bool
led_channel_binary_probe(led_channel_binary_t *self,
const led_paths_binary_t *path)
{
- bool res = false;
+ bool res = false;
- led_channel_binary_close(self);
+ if( !sysfsval_open(self->cached_brightness, path->brightness) )
+ goto cleanup;
- self->maxval = 1;
+ if( sysfsval_open(self->cached_max_brightness, path->max_brightness) )
+ sysfsval_refresh(self->cached_max_brightness);
- if( !led_util_open_file(&self->fd_val, path->val) )
- {
- goto cleanup;
- }
+ if( sysfsval_get(self->cached_max_brightness) <= 0 )
+ sysfsval_assume(self->cached_max_brightness, 1);
- res = true;
+ res = true;
cleanup:
- if( !res ) led_channel_binary_close(self);
+ /* Always close the max_brightness file */
+ sysfsval_close(self->cached_max_brightness);
+
+ /* On failure close the other files too */
+ if( !res ) {
+ sysfsval_close(self->cached_brightness);
+ }
- return res;
+ return res;
}
static void
-led_channel_binary_set_value(led_channel_binary_t *self,
- int value)
+led_channel_binary_set_value(led_channel_binary_t *self, int value)
{
- if( self->fd_val != -1 )
- {
- int scaled = led_util_scale_value(value, self->maxval);
- if( self->val_last != scaled ) {
- self->val_last = scaled;
- dprintf(self->fd_val, "%d", scaled);
- }
- }
+ value = led_util_scale_value(value,
+ sysfsval_get(self->cached_max_brightness));
+ sysfsval_set(self->cached_brightness, value);
}
/* ========================================================================= *
* ALL_CHANNELS
* ========================================================================= */
+#define BINARY_CHANNELS 1
+
static void
led_control_binary_map_color(int r, int g, int b, int *mono)
{
- /* Only binary on/off control is available, use
- * 255 as logical level if nonzero rgb value has
- * been requested.
- */
- *mono = (r || g || b) ? 255 : 0;
+ /* Only binary on/off control is available, use
+ * 255 as logical level if nonzero rgb value has
+ * been requested.
+ */
+ *mono = (r || g || b) ? 255 : 0;
}
static void
led_control_binary_value_cb(void *data, int r, int g, int b)
{
- led_channel_binary_t *channel = data;
+ led_channel_binary_t *channel = data;
- int mono = 0;
- led_control_binary_map_color(r, g, b, &mono);
- led_channel_binary_set_value(channel + 0, mono);
+ int mono = 0;
+ led_control_binary_map_color(r, g, b, &mono);
+ led_channel_binary_set_value(channel + 0, mono);
}
static void
led_control_binary_close_cb(void *data)
{
- led_channel_binary_t *channel = data;
- led_channel_binary_close(channel + 0);
+ led_channel_binary_t *channel = data;
+ led_channel_binary_close(channel + 0);
}
-bool
-led_control_binary_probe(led_control_t *self)
+static bool
+led_control_binary_static_probe(led_channel_binary_t *channel)
{
- /** Sysfs control paths for binary leds */
- static const led_paths_binary_t paths[][1] =
- {
- // binary
+ /** Sysfs control paths for binary leds */
+ static const led_paths_binary_t paths[][BINARY_CHANNELS] =
{
- {
- .val = "/sys/class/leds/button-backlight/brightness",
- },
- },
- };
-
- static led_channel_binary_t channel[1];
-
- bool res = false;
-
- led_channel_binary_init(channel+0);
-
- self->name = "binary";
- self->data = channel;
- self->enable = 0;
- self->blink = 0;
- self->value = led_control_binary_value_cb;
- self->close = led_control_binary_close_cb;
-
- /* We can use sw breathing logic to simulate hw blinking */
- self->can_breathe = true;
- self->breath_type = LED_RAMP_HARD_STEP;
-
- for( size_t i = 0; i < G_N_ELEMENTS(paths) ; ++i )
- {
- if( led_channel_binary_probe(&channel[0], &paths[i][0]) )
+ // binary
+ {
+ {
+ .brightness = "/sys/class/leds/button-backlight/brightness",
+ },
+ },
+ };
+
+ bool ack = false;
+
|
[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris-1.12.0.tar.bz2/sysfs-led-f5121.c
^
|
@@ -37,6 +37,7 @@
#include "sysfs-led-f5121.h"
#include "sysfs-led-util.h"
#include "sysfs-val.h"
+#include "plugin-config.h"
#include <stdio.h>
@@ -216,6 +217,8 @@
* ALL_CHANNELS
* ========================================================================= */
+#define F5121_CHANNELS 3
+
static void
led_control_f5121_blink_cb(void *data, int on_ms, int off_ms)
{
@@ -243,11 +246,11 @@
led_channel_f5121_close(channel + 2);
}
-bool
-led_control_f5121_probe(led_control_t *self)
+static bool
+led_control_f5121_static_probe(led_channel_f5121_t *channel)
{
/** Sysfs control paths for RGB leds */
- static const led_paths_f5121_t f5121_paths[][3] =
+ static const led_paths_f5121_t f5121_paths[][F5121_CHANNELS] =
{
// f5121 (Sony Xperia X)
{
@@ -286,7 +289,67 @@
},
};
- static led_channel_f5121_t channel[3];
+ bool ack = false;
+
+ for( size_t i = 0; i < G_N_ELEMENTS(f5121_paths); ++i ) {
+ if( led_channel_f5121_probe(&channel[0], &f5121_paths[i][0]) &&
+ led_channel_f5121_probe(&channel[1], &f5121_paths[i][1]) &&
+ led_channel_f5121_probe(&channel[2], &f5121_paths[i][2]) ) {
+ ack = true;
+ break;
+ }
+ }
+
+ return ack;
+}
+
+static bool
+led_control_f5121_dynamic_probe(led_channel_f5121_t *channel)
+{
+ /* See inifiles/60-f5121.ini for example */
+ static const objconf_t f5121_conf[] =
+ {
+ OBJCONF_FILE(led_paths_f5121_t, brightness, Brightness),
+ OBJCONF_FILE(led_paths_f5121_t, max_brightness, MaxBrightness),
+ OBJCONF_FILE(led_paths_f5121_t, blink, Blink),
+ OBJCONF_STOP
+ };
+
+ static const char * const pfix[F5121_CHANNELS] =
+ {
+ "Red", "Green", "Blue"
+ };
+
+ bool ack = false;
+
+ led_paths_f5121_t paths[F5121_CHANNELS];
+
+ for( size_t i = 0; i < F5121_CHANNELS; ++i )
+ objconf_init(f5121_conf, &paths[i]);
+
+ for( size_t i = 0; i < F5121_CHANNELS; ++i )
+ {
+ if( !objconf_parse(f5121_conf, &paths[i], pfix[i]) )
+ goto cleanup;
+
+ if( !led_channel_f5121_probe(channel+0, &paths[i]) )
+ goto cleanup;
+ }
+
+ ack = true;
+
+cleanup:
+
+ for( size_t i = 0; i < F5121_CHANNELS; ++i )
+ objconf_quit(f5121_conf, &paths[i]);
+
+ return ack;
+}
+
+bool
+led_control_f5121_probe(led_control_t *self)
+{
+ static led_channel_f5121_t channel[F5121_CHANNELS];
bool ack = false;
@@ -304,14 +367,11 @@
/* Prefer to use the built-in soft-blinking */
self->can_breathe = false;
- for( size_t i = 0; i < G_N_ELEMENTS(f5121_paths) ; ++i ) {
- if( led_channel_f5121_probe(&channel[0], &f5121_paths[i][0]) &&
- led_channel_f5121_probe(&channel[1], &f5121_paths[i][1]) &&
- led_channel_f5121_probe(&channel[2], &f5121_paths[i][2]) ) {
- ack = true;
- break;
- }
- }
+ if( self->use_config )
+ ack = led_control_f5121_dynamic_probe(channel);
+
+ if( !ack )
+ ack = led_control_f5121_static_probe(channel);
if( !ack )
led_control_close(self);
|
[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris-1.12.0.tar.bz2/sysfs-led-hammerhead.c
^
|
@@ -40,6 +40,7 @@
#include "sysfs-led-hammerhead.h"
#include "sysfs-led-util.h"
+#include "plugin-config.h"
#include <stdio.h>
#include <unistd.h>
@@ -52,18 +53,18 @@
typedef struct
{
- const char *max; // R
- const char *val; // W
- const char *on_off; // W
- const char *enable; // W
+ const char *max_brightness;
+ const char *brightness;
+ const char *on_off_ms;
+ const char *rgb_start;
} led_paths_hammerhead_t;
typedef struct
{
- int maxval;
- int fd_val;
- int fd_on_off;
- int fd_enable;
+ int cached_max_brightness;
+ int fd_brightness;
+ int fd_on_off_ms;
+ int fd_rgb_start;
} led_channel_hammerhead_t;
/* ------------------------------------------------------------------------- *
@@ -95,18 +96,18 @@
static void
led_channel_hammerhead_init(led_channel_hammerhead_t *self)
{
- self->maxval = -1;
- self->fd_val = -1;
- self->fd_on_off = -1;
- self->fd_enable = -1;
+ self->cached_max_brightness = -1;
+ self->fd_brightness = -1;
+ self->fd_on_off_ms = -1;
+ self->fd_rgb_start = -1;
}
static void
led_channel_hammerhead_close(led_channel_hammerhead_t *self)
{
- led_util_close_file(&self->fd_val);
- led_util_close_file(&self->fd_on_off);
- led_util_close_file(&self->fd_enable);
+ led_util_close_file(&self->fd_brightness);
+ led_util_close_file(&self->fd_on_off_ms);
+ led_util_close_file(&self->fd_rgb_start);
}
static bool
@@ -117,14 +118,14 @@
led_channel_hammerhead_close(self);
- if( (self->maxval = led_util_read_number(path->max)) <= 0 )
+ if( (self->cached_max_brightness = led_util_read_number(path->max_brightness)) <= 0 )
{
goto cleanup;
}
- if( !led_util_open_file(&self->fd_val, path->val) ||
- !led_util_open_file(&self->fd_on_off, path->on_off) ||
- !led_util_open_file(&self->fd_enable, path->enable) )
+ if( !led_util_open_file(&self->fd_brightness, path->brightness) ||
+ !led_util_open_file(&self->fd_on_off_ms, path->on_off_ms) ||
+ !led_util_open_file(&self->fd_rgb_start, path->rgb_start) )
{
goto cleanup;
}
@@ -142,9 +143,9 @@
led_channel_hammerhead_set_enabled(const led_channel_hammerhead_t *self,
bool enable)
{
- if( self->fd_enable != -1 )
+ if( self->fd_rgb_start != -1 )
{
- dprintf(self->fd_enable, "%d", enable);
+ dprintf(self->fd_rgb_start, "%d", enable);
}
}
@@ -152,9 +153,9 @@
led_channel_hammerhead_set_value(const led_channel_hammerhead_t *self,
int value)
{
- if( self->fd_val != -1 )
+ if( self->fd_brightness != -1 )
{
- dprintf(self->fd_val, "%d", led_util_scale_value(value, self->maxval));
+ dprintf(self->fd_brightness, "%d", led_util_scale_value(value, self->cached_max_brightness));
}
}
@@ -162,13 +163,13 @@
led_channel_hammerhead_set_blink(const led_channel_hammerhead_t *self,
int on_ms, int off_ms)
{
- if( self->fd_on_off != -1 )
+ if( self->fd_on_off_ms != -1 )
{
char tmp[32];
int len = snprintf(tmp, sizeof tmp, "%d %d", on_ms, off_ms);
if( len > 0 && len <= (int)sizeof tmp )
{
- if( write(self->fd_on_off, tmp, len) < 0 ) {
+ if( write(self->fd_on_off_ms, tmp, len) < 0 ) {
// dontcare, keep compiler from complaining too
}
}
@@ -179,6 +180,8 @@
* ALL_CHANNELS
* ========================================================================= */
+#define HAMMERHEAD_CHANNELS 3
+
static void
led_control_hammerhead_enable_cb(void *data, bool enable)
{
@@ -215,38 +218,100 @@
led_channel_hammerhead_close(channel + 2);
}
-bool
-led_control_hammerhead_probe(led_control_t *self)
+static bool
+led_control_hammerhead_static_probe(led_channel_hammerhead_t *channel)
{
/** Sysfs control paths for RGB leds */
- static const led_paths_hammerhead_t paths[][3] =
+ static const led_paths_hammerhead_t paths[][HAMMERHEAD_CHANNELS] =
{
// hammerhead (Nexus 5)
{
{
- .max = "/sys/class/leds/red/max_brightness",
- .val = "/sys/class/leds/red/brightness",
- .on_off = "/sys/class/leds/red/on_off_ms",
- .enable = "/sys/class/leds/red/rgb_start",
+ .max_brightness = "/sys/class/leds/red/max_brightness",
+ .brightness = "/sys/class/leds/red/brightness",
+ .on_off_ms = "/sys/class/leds/red/on_off_ms",
+ .rgb_start = "/sys/class/leds/red/rgb_start",
},
{
- .max = "/sys/class/leds/green/max_brightness",
- .val = "/sys/class/leds/green/brightness",
- .on_off = "/sys/class/leds/green/on_off_ms",
- .enable = "/sys/class/leds/green/rgb_start",
+ .max_brightness = "/sys/class/leds/green/max_brightness",
+ .brightness = "/sys/class/leds/green/brightness",
+ .on_off_ms = "/sys/class/leds/green/on_off_ms",
+ .rgb_start = "/sys/class/leds/green/rgb_start",
},
{
- .max = "/sys/class/leds/blue/max_brightness",
- .val = "/sys/class/leds/blue/brightness",
- .on_off = "/sys/class/leds/blue/on_off_ms",
- .enable = "/sys/class/leds/blue/rgb_start",
+ .max_brightness = "/sys/class/leds/blue/max_brightness",
+ .brightness = "/sys/class/leds/blue/brightness",
+ .on_off_ms = "/sys/class/leds/blue/on_off_ms",
+ .rgb_start = "/sys/class/leds/blue/rgb_start",
}
},
};
- static led_channel_hammerhead_t channel[3];
+ bool ack = false;
- bool res = false;
+ for( size_t i = 0; i < G_N_ELEMENTS(paths); ++i ) {
+ if( led_channel_hammerhead_probe(&channel[0], &paths[i][0]) &&
+ led_channel_hammerhead_probe(&channel[1], &paths[i][1]) &&
+ led_channel_hammerhead_probe(&channel[2], &paths[i][2]) ) {
+ ack = true;
+ break;
+ }
+ }
+
+ return ack;
+}
+
+static bool
+led_control_hammerhead_dynamic_probe(led_channel_hammerhead_t *channel)
+{
+ /* See inifiles/60-hammerhead.ini for example */
+ static const objconf_t hammerhead_conf[] =
+ {
+ OBJCONF_FILE(led_paths_hammerhead_t, brightness, Brightness),
|
[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris-1.12.0.tar.bz2/sysfs-led-htcvision.c
^
|
@@ -38,6 +38,8 @@
#include "sysfs-led-htcvision.h"
#include "sysfs-led-util.h"
+#include "sysfs-val.h"
+#include "plugin-config.h"
#include <stdio.h>
@@ -49,16 +51,16 @@
typedef struct
{
- const char *max; // R
- const char *val; // W
- const char *blink; // W
+ const char *max_brightness;
+ const char *brightness;
+ const char *blink;
} led_paths_htcvision_t;
typedef struct
{
- int maxval;
- int fd_val;
- int fd_blink;
+ sysfsval_t * cached_max_brightness;
+ sysfsval_t * cached_brightness;
+ sysfsval_t * cached_blink;
} led_channel_htcvision_t;
/* ------------------------------------------------------------------------- *
@@ -89,16 +91,22 @@
static void
led_channel_htcvision_init(led_channel_htcvision_t *self)
{
- self->maxval = -1;
- self->fd_val = -1;
- self->fd_blink = -1;
+ self->cached_max_brightness = sysfsval_create();
+ self->cached_brightness = sysfsval_create();
+ self->cached_blink = sysfsval_create();
}
static void
led_channel_htcvision_close(led_channel_htcvision_t *self)
{
- led_util_close_file(&self->fd_val);
- led_util_close_file(&self->fd_blink);
+ sysfsval_delete(self->cached_max_brightness),
+ self->cached_max_brightness = 0;
+
+ sysfsval_delete(self->cached_brightness),
+ self->cached_brightness = 0;
+
+ sysfsval_delete(self->cached_blink),
+ self->cached_blink = 0;
}
static bool
@@ -107,24 +115,30 @@
{
bool res = false;
- led_channel_htcvision_close(self);
-
- if( (self->maxval = led_util_read_number(path->max)) <= 0 )
- {
+ if( !sysfsval_open(self->cached_blink, path->blink) )
goto cleanup;
- }
- if( !led_util_open_file(&self->fd_val, path->val) ||
- !led_util_open_file(&self->fd_blink, path->blink) )
- {
+ if( !sysfsval_open(self->cached_brightness, path->brightness) )
goto cleanup;
- }
+
+ if( sysfsval_open(self->cached_max_brightness, path->max_brightness) )
+ sysfsval_refresh(self->cached_max_brightness);
+
+ if( sysfsval_get(self->cached_max_brightness) <= 0 )
+ sysfsval_assume(self->cached_max_brightness, 1);
res = true;
cleanup:
- if( !res ) led_channel_htcvision_close(self);
+ /* Always close the max_brightness file */
+ sysfsval_close(self->cached_max_brightness);
+
+ /* On failure close the other files too */
+ if( !res ) {
+ sysfsval_close(self->cached_brightness);
+ sysfsval_close(self->cached_blink);
+ }
return res;
}
@@ -133,25 +147,23 @@
led_channel_htcvision_set_value(const led_channel_htcvision_t *self,
int value)
{
- if( self->fd_val != -1 )
- {
- dprintf(self->fd_val, "%d", led_util_scale_value(value, self->maxval));
- }
+ value = led_util_scale_value(value,
+ sysfsval_get(self->cached_max_brightness));
+ sysfsval_set(self->cached_brightness, value);
}
static void
led_channel_htcvision_set_blink(const led_channel_htcvision_t *self, int blink)
{
- if( self->fd_blink != -1 )
- {
- dprintf(self->fd_val, "%d", blink);
- }
+ sysfsval_set(self->cached_blink, blink ? 0 : 1);
}
/* ========================================================================= *
* ALL_CHANNELS
* ========================================================================= */
+#define HTCVISION_CHANNELS 2
+
static void
led_control_htcvision_map_color(int r, int g, int b,
int *amber, int *green)
@@ -211,8 +223,8 @@
led_channel_htcvision_close(channel + 1);
}
-bool
-led_control_htcvision_probe(led_control_t *self)
+static bool
+led_control_htcvision_static_probe(led_channel_htcvision_t *channel)
{
/** Sysfs control paths for Amber/Green leds */
static const led_paths_htcvision_t paths[][3] =
@@ -220,21 +232,81 @@
// htc vision, htc ace
{
{
- .max = "/sys/class/leds/amber/max_brightness",
- .val = "/sys/class/leds/amber/brightness",
- .blink = "/sys/class/leds/amber/blink",
+ .max_brightness = "/sys/class/leds/amber/max_brightness",
+ .brightness = "/sys/class/leds/amber/brightness",
+ .blink = "/sys/class/leds/amber/blink",
},
{
- .max = "/sys/class/leds/green/max_brightness",
- .val = "/sys/class/leds/green/brightness",
- .blink = "/sys/class/leds/green/blink",
+ .max_brightness = "/sys/class/leds/green/max_brightness",
+ .brightness = "/sys/class/leds/green/brightness",
+ .blink = "/sys/class/leds/green/blink",
},
},
};
- static led_channel_htcvision_t channel[2];
+ bool ack = false;
- bool res = false;
+ for( size_t i = 0; i < G_N_ELEMENTS(paths); ++i ) {
+ if( led_channel_htcvision_probe(&channel[0], &paths[i][0]) &&
+ led_channel_htcvision_probe(&channel[1], &paths[i][1]) ) {
+ ack = true;
+ break;
+ }
+ }
+
+ return ack;
+}
+
+static bool
+led_control_htcvision_dynamic_probe(led_channel_htcvision_t *channel)
+{
+ /* See inifiles/60-htcvision.ini for example */
+ static const objconf_t htcvision_conf[] =
+ {
+ OBJCONF_FILE(led_paths_htcvision_t, brightness, Brightness),
+ OBJCONF_FILE(led_paths_htcvision_t, max_brightness, MaxBrightness),
+ OBJCONF_FILE(led_paths_htcvision_t, blink, Blink),
+ OBJCONF_STOP
+ };
+
+ static const char * const pfix[HTCVISION_CHANNELS] =
+ {
+ "Amber", "Green"
+ };
+
+ bool ack = false;
+
|
[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris-1.12.0.tar.bz2/sysfs-led-main.c
^
|
@@ -218,6 +218,9 @@
self->value = 0;
self->close = 0;
+ /* Assume paths from config are not to be used */
+ self->use_config = false;
+
/* Assume that it is exceptional if sw breathing can't be supported */
self->can_breathe = true;
/* And half sine curve should be used for breathing */
@@ -306,6 +309,16 @@
for( size_t i = 0; i < G_N_ELEMENTS(lut); ++i )
{
+ self->use_config = false;
+
+ if( name ) {
+ if( strcmp(lut[i].name, name) ) {
+ continue;
+ }
+
+ self->use_config = true;
+ }
+
if( name && strcmp(lut[i].name, name) )
{
continue;
@@ -813,11 +826,12 @@
sysfs_led_generate_ramp(work.on, work.off);
}
+ if( old_style == STYLE_BLINK || new_style == STYLE_BLINK )
+ sysfs_led_reset_blinking = true;
+
/* Schedule led off after kernel settle timeout; once that
* is done, new led color/blink/breathing will be started */
if( !sysfs_led_stop_id ) {
- sysfs_led_reset_blinking = (old_style == STYLE_BLINK ||
- new_style == STYLE_BLINK);
sysfs_led_stop_id = g_timeout_add(SYSFS_LED_KERNEL_DELAY,
sysfs_led_stop_cb, 0);
}
|
[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris-1.12.0.tar.bz2/sysfs-led-main.h
^
|
@@ -52,6 +52,7 @@
const char *name;
void *data;
bool can_breathe;
+ bool use_config;
led_ramp_t breath_type;
void (*enable)(void *data, bool enable);
void (*blink) (void *data, int on_ms, int off_ms);
|
[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris-1.12.0.tar.bz2/sysfs-led-redgreen.c
^
|
@@ -36,6 +36,8 @@
#include "sysfs-led-redgreen.h"
#include "sysfs-led-util.h"
+#include "sysfs-val.h"
+#include "plugin-config.h"
#include <stdio.h>
@@ -47,14 +49,14 @@
typedef struct
{
- const char *max; // R
- const char *val; // W
+ const char *max_brightness;
+ const char *brightness;
} led_paths_redgreen_t;
typedef struct
{
- int maxval;
- int fd_val;
+ sysfsval_t *cached_max_brightness;
+ sysfsval_t *cached_brightness;
} led_channel_redgreen_t;
/* ------------------------------------------------------------------------- *
@@ -83,146 +85,206 @@
static void
led_channel_redgreen_init(led_channel_redgreen_t *self)
{
- self->maxval = -1;
- self->fd_val = -1;
+ self->cached_max_brightness = sysfsval_create();
+ self->cached_brightness = sysfsval_create();
}
static void
led_channel_redgreen_close(led_channel_redgreen_t *self)
{
- led_util_close_file(&self->fd_val);
+ sysfsval_delete(self->cached_max_brightness),
+ self->cached_max_brightness = 0;
+
+ sysfsval_delete(self->cached_brightness),
+ self->cached_brightness = 0;
}
static bool
led_channel_redgreen_probe(led_channel_redgreen_t *self,
- const led_paths_redgreen_t *path)
+ const led_paths_redgreen_t *path)
{
- bool res = false;
+ bool res = false;
- led_channel_redgreen_close(self);
+ if( !sysfsval_open(self->cached_brightness, path->brightness) )
+ goto cleanup;
- if( (self->maxval = led_util_read_number(path->max)) <= 0 )
- {
- goto cleanup;
- }
+ if( sysfsval_open(self->cached_max_brightness, path->max_brightness) )
+ sysfsval_refresh(self->cached_max_brightness);
- if( !led_util_open_file(&self->fd_val, path->val) )
- {
- goto cleanup;
- }
+ if( sysfsval_get(self->cached_max_brightness) <= 0 )
+ goto cleanup;
- res = true;
+ res = true;
cleanup:
- if( !res ) led_channel_redgreen_close(self);
+ /* Always close the max_brightness file */
+ sysfsval_close(self->cached_max_brightness);
+
+ /* On failure close the other files too */
+ if( !res )
+ {
+ sysfsval_close(self->cached_brightness);
+ }
- return res;
+ return res;
}
static void
-led_channel_redgreen_set_value(const led_channel_redgreen_t *self,
- int value)
+led_channel_redgreen_set_value(const led_channel_redgreen_t *self, int value)
{
- if( self->fd_val != -1 )
- {
- dprintf(self->fd_val, "%d", led_util_scale_value(value, self->maxval));
- }
+ value = led_util_scale_value(value,
+ sysfsval_get(self->cached_max_brightness));
+ sysfsval_set(self->cached_brightness, value);
}
/* ========================================================================= *
* ALL_CHANNELS
* ========================================================================= */
+#define REDGREEN_CHANNELS 2
+
static void
led_control_redgreen_map_color(int r, int g, int b, int *red, int *green)
{
- /* If the pattern defines red and/or green intensities, those should
- * be used. Otherwise make sure that requesting for blue only colour
- * does not result in the led being turned off. */
- if( r || g )
- {
- *red = r;
- *green = g;
- }
- else
- {
- *red = b;
- *green = b;
- }
+ /* If the pattern defines red and/or green intensities, those should
+ * be used. Otherwise make sure that requesting for blue only colour
+ * does not result in the led being turned off. */
+ if( r || g )
+ {
+ *red = r;
+ *green = g;
+ }
+ else
+ {
+ *red = b;
+ *green = b;
+ }
}
static void
led_control_redgreen_value_cb(void *data, int r, int g, int b)
{
- const led_channel_redgreen_t *channel = data;
+ const led_channel_redgreen_t *channel = data;
- int red = 0;
- int green = 0;
- led_control_redgreen_map_color(r, g, b, &red, &green);
+ int red = 0;
+ int green = 0;
+ led_control_redgreen_map_color(r, g, b, &red, &green);
- led_channel_redgreen_set_value(channel + 0, red);
- led_channel_redgreen_set_value(channel + 1, green);
+ led_channel_redgreen_set_value(channel + 0, red);
+ led_channel_redgreen_set_value(channel + 1, green);
}
static void
led_control_redgreen_close_cb(void *data)
{
- led_channel_redgreen_t *channel = data;
- led_channel_redgreen_close(channel + 0);
- led_channel_redgreen_close(channel + 1);
+ led_channel_redgreen_t *channel = data;
+ led_channel_redgreen_close(channel + 0);
+ led_channel_redgreen_close(channel + 1);
}
-bool
-led_control_redgreen_probe(led_control_t *self)
+static bool
+led_control_redgreen_static_probe(led_channel_redgreen_t *channel)
{
- /** Sysfs control paths for Red + Green leds */
- static const led_paths_redgreen_t paths[][2] =
- {
- // "standard" paths
- {
- {
- .max = "/sys/class/leds/red/max_brightness",
- .val = "/sys/class/leds/red/brightness",
- },
- {
- .max = "/sys/class/leds/green/max_brightness",
- .val = "/sys/class/leds/green/brightness",
- },
- },
- };
-
- static led_channel_redgreen_t channel[2];
-
- bool res = false;
-
|
[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris-1.12.0.tar.bz2/sysfs-led-vanilla.c
^
|
@@ -47,6 +47,8 @@
#include "sysfs-led-vanilla.h"
#include "sysfs-led-util.h"
+#include "sysfs-val.h"
+#include "plugin-config.h"
#include <stdio.h>
@@ -58,27 +60,21 @@
typedef struct
{
- const char *max; // R
- const char *val; // W
- const char *on; // W
- const char *off; // W
- const char *blink; // W
- int maxval;// value to use if max path is NULL
+ const char *max_brightness; // R
+ const char *brightness; // W
+ const char *blink_delay_on; // W
+ const char *blink_delay_off; // W
+ const char *blink; // W
+ int max_override;// value to use if max_brightness path is NULL
} led_paths_vanilla_t;
typedef struct
{
- int maxval;
- int fd_val;
- int fd_on;
- int fd_off;
- int fd_blink;
-
- int cur_val;
- int cur_on;
- int cur_off;
- int cur_blink;
-
+ sysfsval_t *cached_max_brightness;
+ sysfsval_t *cached_brightness;
+ sysfsval_t *cached_blink_delay_on;
+ sysfsval_t *cached_blink_delay_off;
+ sysfsval_t *cached_blink;
} led_channel_vanilla_t;
/* ------------------------------------------------------------------------- *
@@ -108,25 +104,30 @@
static void
led_channel_vanilla_init(led_channel_vanilla_t *self)
{
- self->fd_on = -1;
- self->fd_off = -1;
- self->fd_val = -1;
- self->fd_blink = -1;
- self->maxval = -1;
-
- self->cur_val = -1;
- self->cur_on = -1;
- self->cur_off = -1;
- self->cur_blink = -1;
+ self->cached_max_brightness = sysfsval_create();
+ self->cached_brightness = sysfsval_create();
+ self->cached_blink_delay_on = sysfsval_create();
+ self->cached_blink_delay_off = sysfsval_create();
+ self->cached_blink = sysfsval_create();
}
static void
led_channel_vanilla_close(led_channel_vanilla_t *self)
{
- led_util_close_file(&self->fd_on);
- led_util_close_file(&self->fd_off);
- led_util_close_file(&self->fd_val);
- led_util_close_file(&self->fd_blink);
+ sysfsval_delete(self->cached_max_brightness),
+ self->cached_max_brightness = 0;
+
+ sysfsval_delete(self->cached_brightness),
+ self->cached_brightness = 0;
+
+ sysfsval_delete(self->cached_blink_delay_on),
+ self->cached_blink_delay_on = 0;
+
+ sysfsval_delete(self->cached_blink_delay_off),
+ self->cached_blink_delay_off = 0;
+
+ sysfsval_delete(self->cached_blink),
+ self->cached_blink = 0;
}
static bool
@@ -135,75 +136,59 @@
{
bool res = false;
- led_channel_vanilla_close(self);
-
// maximum brightness can be read from file or given in config
- if( path->max )
- {
- self->maxval = led_util_read_number(path->max);
- }
- else
- {
- self->maxval = path->maxval;
- }
+ if( sysfsval_open(self->cached_max_brightness, path->max_brightness) )
+ sysfsval_refresh(self->cached_max_brightness);
- if( self->maxval <= 0 )
- {
+ if( path->max_override > 0 )
+ sysfsval_assume(self->cached_max_brightness, path->max_override);
+
+ if( sysfsval_get(self->cached_max_brightness) <= 0 )
goto cleanup;
- }
// we always must have brightness control
- if( !led_util_open_file(&self->fd_val, path->val) )
- {
+ if( !sysfsval_open(self->cached_brightness, path->brightness) )
goto cleanup;
- }
// on/off period controls are optional, but both
// are needed if one is present
- if( led_util_open_file(&self->fd_on, path->on) )
- {
- if( !led_util_open_file(&self->fd_off, path->off) )
- {
- led_util_close_file(&self->fd_on);
- }
+ if( sysfsval_open(self->cached_blink_delay_on, path->blink_delay_on) ) {
+ if( !sysfsval_open(self->cached_blink_delay_off, path->blink_delay_off) )
+ sysfsval_close(self->cached_blink_delay_on);
}
// having "blink" control file is optional
- led_util_open_file(&self->fd_blink, path->blink);
+ sysfsval_open(self->cached_blink, path->blink);
res = true;
cleanup:
- if( !res ) led_channel_vanilla_close(self);
+ /* Always close the max_brightness file */
+ sysfsval_close(self->cached_max_brightness);
+
+ /* On failure close the other files too */
+ if( !res ) {
+ sysfsval_close(self->cached_brightness);
+ sysfsval_close(self->cached_blink_delay_on);
+ sysfsval_close(self->cached_blink_delay_off);
+ sysfsval_close(self->cached_blink);
+ }
return res;
}
static void
-led_channel_vanilla_set_value(led_channel_vanilla_t *self,
- int value)
+led_channel_vanilla_set_value(led_channel_vanilla_t *self, int value)
{
- if( self->fd_val != -1 )
- {
- value = led_util_scale_value(value, self->maxval);
- if( self->cur_val != value )
- {
- self->cur_val = value;
- self->cur_blink = -1;
- dprintf(self->fd_val, "%d", value);
- }
- }
+ value = led_util_scale_value(value,
+ sysfsval_get(self->cached_max_brightness));
+ sysfsval_set(self->cached_brightness, value);
+
+ value = (sysfsval_get(self->cached_blink_delay_on) &&
+ sysfsval_get(self->cached_blink_delay_off));
+ sysfsval_set(self->cached_blink, value);
- if( self->fd_blink != -1 )
- {
- int blink = (self->cur_on > 0 && self->cur_off > 0);
- if( self->cur_blink != blink )
- {
- self->cur_blink = blink;
- dprintf(self->fd_blink, "%d", blink);
- }
- }
}
static void
led_channel_vanilla_set_blink(led_channel_vanilla_t *self,
@@ -214,28 +199,22 @@
* cached brightness value if blinking changes
|
[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris-1.12.0.tar.bz2/sysfs-led-white.c
^
|
@@ -32,6 +32,8 @@
#include "sysfs-led-white.h"
#include "sysfs-led-util.h"
+#include "sysfs-val.h"
+#include "plugin-config.h"
#include <stdio.h>
@@ -43,14 +45,14 @@
typedef struct
{
- const char *max; // R
- const char *val; // W
+ const char *max_brightness; // R
+ const char *brightness; // W
} led_paths_white_t;
typedef struct
{
- int maxval;
- int fd_val;
+ sysfsval_t *cached_max_brightness;
+ sysfsval_t *cached_brightness;
} led_channel_white_t;
/* ------------------------------------------------------------------------- *
@@ -79,126 +81,185 @@
static void
led_channel_white_init(led_channel_white_t *self)
{
- self->maxval = -1;
- self->fd_val = -1;
+ self->cached_max_brightness = sysfsval_create();
+ self->cached_brightness = sysfsval_create();
}
static void
led_channel_white_close(led_channel_white_t *self)
{
- led_util_close_file(&self->fd_val);
+ sysfsval_delete(self->cached_max_brightness),
+ self->cached_max_brightness = 0;
+
+ sysfsval_delete(self->cached_brightness),
+ self->cached_brightness = 0;
}
static bool
led_channel_white_probe(led_channel_white_t *self,
const led_paths_white_t *path)
{
- bool res = false;
+ bool res = false;
+
+ if( !sysfsval_open(self->cached_brightness, path->brightness) )
+ goto cleanup;
- led_channel_white_close(self);
+ if( !sysfsval_open(self->cached_max_brightness, path->max_brightness) )
+ goto cleanup;
- if( (self->maxval = led_util_read_number(path->max)) <= 0 )
- {
- goto cleanup;
- }
+ sysfsval_refresh(self->cached_max_brightness);
- if( !led_util_open_file(&self->fd_val, path->val) )
- {
- goto cleanup;
- }
+ if( sysfsval_get(self->cached_max_brightness) <= 0 )
+ goto cleanup;
- res = true;
+ res = true;
cleanup:
- if( !res ) led_channel_white_close(self);
+ /* Always close the max_brightness file */
+ sysfsval_close(self->cached_max_brightness);
+
+ /* On failure close the other files too */
+ if( !res )
+ {
+ sysfsval_close(self->cached_brightness);
+ }
- return res;
+ return res;
}
static void
led_channel_white_set_value(const led_channel_white_t *self, int value)
{
- if( self->fd_val != -1 )
- {
- dprintf(self->fd_val, "%d", led_util_scale_value(value, self->maxval));
- }
+ value = led_util_scale_value(value,
+ sysfsval_get(self->cached_max_brightness));
+ sysfsval_set(self->cached_brightness, value);
}
/* ========================================================================= *
* ALL_CHANNELS
* ========================================================================= */
+#define WHITE_CHANNELS 1
+
static void
led_control_white_map_color(int r, int g, int b, int *white)
{
- /* Use maximum value from requested RGB value */
- if( r < g ) r = g;
- if( r < b ) r = b;
- *white = r;
+ /* Use maximum value from requested RGB value */
+ if( r < g ) r = g;
+ if( r < b ) r = b;
+ *white = r;
}
static void
led_control_white_value_cb(void *data, int r, int g, int b)
{
- const led_channel_white_t *channel = data;
+ const led_channel_white_t *channel = data;
- int white = 0;
- led_control_white_map_color(r, g, b, &white);
+ int white = 0;
+ led_control_white_map_color(r, g, b, &white);
- led_channel_white_set_value(channel + 0, white);
+ led_channel_white_set_value(channel + 0, white);
}
static void
led_control_white_close_cb(void *data)
{
- led_channel_white_t *channel = data;
- led_channel_white_close(channel + 0);
+ led_channel_white_t *channel = data;
+ led_channel_white_close(channel + 0);
}
+static bool
+led_control_white_static_probe(led_channel_white_t *channel)
+{
+ /** Sysfs control paths for White leds */
+ static const led_paths_white_t paths[][WHITE_CHANNELS] =
+ {
+ // "Motorola Moto G (2nd gen)"
+ {
+ {
+ .max_brightness = "/sys/class/leds/white/max_brightness",
+ .brightness = "/sys/class/leds/white/brightness",
+ },
+ },
+ };
+
+ bool ack = false;
+
+ for( size_t i = 0; i < G_N_ELEMENTS(paths); ++i ) {
+ if( (ack = led_channel_white_probe(channel+0, &paths[i][0])) )
+ break;
+ }
-bool
-led_control_white_probe(led_control_t *self)
+ return ack;
+}
+
+static bool
+led_control_white_dynamic_probe(led_channel_white_t *channel)
{
- /** Sysfs control paths for White leds */
- static const led_paths_white_t paths[][1] =
- {
- // "Motorola Moto G (2nd gen)"
+ static const objconf_t white_conf[] =
{
- {
- .max = "/sys/class/leds/white/max_brightness",
- .val = "/sys/class/leds/white/brightness",
- },
- },
- };
-
- static led_channel_white_t channel[1];
-
- bool res = false;
-
- led_channel_white_init(channel + 0);
-
- self->name = "white";
- self->data = channel;
|
[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris-1.12.0.tar.bz2/sysfs-val.c
^
|
@@ -199,17 +199,23 @@
{
bool ack = true;
- if( self->sv_curr == value )
+ int prev = self->sv_curr;
+ self->sv_curr = value;
+
+ if( prev == self->sv_curr )
goto EXIT;
- mce_log(LOG_DEBUG, "%s: write: %d -> %d", sysfsval_path(self),
- self->sv_curr, value);
+ /* If file is closed: assume it was optional and do not
+ * spam journal with transitions related to it */
+ if( self->sv_file == -1 )
+ goto EXIT;
- self->sv_curr = value;
+ mce_log(LOG_DEBUG, "%s: write: %d -> %d", sysfsval_path(self),
+ prev, self->sv_curr);
char data[256];
- int todo = snprintf(data, sizeof data, "%d\n", value);
+ int todo = snprintf(data, sizeof data, "%d", value);
int done = write(self->sv_file, data, todo);
if( done == todo )
@@ -239,11 +245,22 @@
void
sysfsval_assume(sysfsval_t *self, int value)
{
- if( self->sv_curr != value ) {
- mce_log(LOG_DEBUG, "%s: assume: %d -> %d", sysfsval_path(self),
- self->sv_curr, value);
- self->sv_curr = value;
- }
+ int prev = self->sv_curr;
+ self->sv_curr = value;
+
+ if( prev == self->sv_curr )
+ goto EXIT;
+
+ /* If file is closed: assume it was optional and do not
+ * spam journal with transitions related to it */
+ if( self->sv_file == -1 )
+ goto EXIT;
+
+ mce_log(LOG_DEBUG, "%s: assume: %d -> %d", sysfsval_path(self),
+ prev, self->sv_curr);
+
+EXIT:
+ return;
}
/** Invalidate cached value associated with sysfsval_t object
@@ -258,10 +275,21 @@
void
sysfsval_invalidate(sysfsval_t *self)
{
- if( self->sv_curr != -1 ) {
- self->sv_curr = -1;
- mce_log(LOG_DEBUG, "%s: invalidated", sysfsval_path(self));
- }
+ int prev = self->sv_curr;
+ self->sv_curr = -1;
+
+ if( prev == self->sv_curr )
+ goto EXIT;
+
+ /* If file is closed: assume it was optional and do not
+ * spam journal with transitions related to it */
+ if( self->sv_file == -1 )
+ goto EXIT;
+
+ mce_log(LOG_DEBUG, "%s: invalidated", sysfsval_path(self));
+
+EXIT:
+ return;
}
/** Read value from sysfs file associated with sysfsval_t object
|