[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris.changes
|
|
[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris.spec
^
|
|
[-]
[+]
|
Changed |
_service
^
|
@@ -1,10 +1,10 @@
<services>
<service name="tar_git">
- <param name="url">https://github.com/nemomobile/mce-plugin-libhybris.git</param>
- <param name="branch">master</param>
- <param name="revision">fd542a8ae0d944c77d9446003f110372d52d2e78</param>
- <param name="token"/>
- <param name="debian">N</param>
- <param name="dumb">N</param>
+ <param name="url">https://github.com/nemomobile/mce-plugin-libhybris.git</param>
+ <param name="branch">master</param>
+ <param name="revision">HEAD</param>
+ <param name="token"/>
+ <param name="debian">N</param>
+ <param name="dumb">N</param>
</service>
-</services>
\ No newline at end of file
+</services>
|
[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/.depend
^
|
@@ -64,6 +64,16 @@
plugin-logging.h\
sysfs-led-main.h\
+plugin-config.o:\
+ plugin-config.c\
+ plugin-config.h\
+ plugin-logging.h\
+
+plugin-config.pic.o:\
+ plugin-config.c\
+ plugin-config.h\
+ plugin-logging.h\
+
plugin-logging.o:\
plugin-logging.c\
plugin-api.h\
@@ -74,8 +84,21 @@
plugin-api.h\
plugin-logging.h\
+plugin-quirks.o:\
+ plugin-quirks.c\
+ plugin-config.h\
+ plugin-logging.h\
+ plugin-quirks.h\
+
+plugin-quirks.pic.o:\
+ plugin-quirks.c\
+ plugin-config.h\
+ plugin-logging.h\
+ plugin-quirks.h\
+
sysfs-led-bacon.o:\
sysfs-led-bacon.c\
+ plugin-config.h\
plugin-logging.h\
sysfs-led-bacon.h\
sysfs-led-main.h\
@@ -83,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\
@@ -90,45 +114,82 @@
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\
+ sysfs-val.h\
+
+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\
+ sysfs-val.h\
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\
+ plugin-config.h\
plugin-logging.h\
+ plugin-quirks.h\
sysfs-led-bacon.h\
sysfs-led-binary.h\
+ sysfs-led-f5121.h\
sysfs-led-hammerhead.h\
sysfs-led-htcvision.h\
sysfs-led-main.h\
@@ -139,9 +200,12 @@
sysfs-led-main.pic.o:\
sysfs-led-main.c\
+ plugin-config.h\
plugin-logging.h\
+ plugin-quirks.h\
sysfs-led-bacon.h\
sysfs-led-binary.h\
+ sysfs-led-f5121.h\
sysfs-led-hammerhead.h\
sysfs-led-htcvision.h\
sysfs-led-main.h\
@@ -152,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\
@@ -174,25 +244,47 @@
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\
|
[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/Makefile
^
|
@@ -119,9 +119,12 @@
hybris_OBJS += hybris-sensors.pic.o
hybris_OBJS += hybris-thread.pic.o
hybris_OBJS += plugin-api.pic.o
+hybris_OBJS += plugin-config.pic.o
hybris_OBJS += plugin-logging.pic.o
+hybris_OBJS += plugin-quirks.pic.o
hybris_OBJS += sysfs-led-bacon.pic.o
hybris_OBJS += sysfs-led-binary.pic.o
+hybris_OBJS += sysfs-led-f5121.pic.o
hybris_OBJS += sysfs-led-hammerhead.pic.o
hybris_OBJS += sysfs-led-htcvision.pic.o
hybris_OBJS += sysfs-led-main.pic.o
@@ -129,6 +132,7 @@
hybris_OBJS += sysfs-led-util.pic.o
hybris_OBJS += sysfs-led-vanilla.pic.o
hybris_OBJS += sysfs-led-white.pic.o
+hybris_OBJS += sysfs-val.pic.o
hybris.so : LDLIBS += -lhardware -lm
hybris.so : $(hybris_OBJS)
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.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.1.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.1.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.1.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.1.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.1.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.1.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.1.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
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/plugin-config.c
^
|
@@ -0,0 +1,162 @@
+/** @file plugin-config.c
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2017 Jolla Ltd.
+ * <p>
+ * @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
+ *
+ * mce-plugin-libhybris is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License.
+ *
+ * mce-plugin-libhybris is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with mce-plugin-libhybris; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "plugin-config.h"
+
+#include "plugin-logging.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* ========================================================================= *
+ * SETTINGS
+ * ========================================================================= */
+
+gchar *
+plugin_config_get_string(const gchar *group,
+ const gchar *key,
+ const gchar *defaultval)
+{
+ extern gboolean mce_conf_has_key(const gchar *group,
+ const gchar *key);
+
+ extern gchar *mce_conf_get_string(const gchar *group,
+ const gchar *key,
+ const gchar *defaultval);
+
+ gchar *res = 0;
+
+ /* From MCE point of view it is suspicious if code tries to
+ * access settings that are not defined and warning is emitted
+ * in such cases. Whereas from this plugin point of view all
+ * 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) )
+ res = defaultval ? g_strdup(defaultval) : 0;
+ else
+ res = mce_conf_get_string(group, key, defaultval);
+
+ mce_log(LOG_DEBUG, "[%s] %s = %s", group, key, res ?: "(null)");
+
+ 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;
+}
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/plugin-config.h
^
|
@@ -0,0 +1,93 @@
+/** @file plugin-config.h
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2017 Jolla Ltd.
+ * <p>
+ * @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
+ *
+ * mce-plugin-libhybris is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License.
+ *
+ * mce-plugin-libhybris is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with mce-plugin-libhybris; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef PLUGIN_CONFIG_H_
+# define PLUGIN_CONFIG_H_
+
+# include "plugin-logging.h"
+
+# include <stdbool.h>
+
+# include <glib.h>
+
+/* ========================================================================= *
+ * CONFIG
+ * ========================================================================= */
+
+/** Configuration group for mce-plugin-libhybris related values */
+#define MCE_CONF_LED_CONFIG_HYBRIS_GROUP "LEDConfigHybris"
+
+/** Name of the LED backend to use */
+#define MCE_CONF_LED_CONFIG_HYBRIS_BACKEND "BackEnd"
+
+/** Optional enable/disable sw breathing setting */
+#define MCE_CONF_LED_CONFIG_HYBRIS_BREATHING "QuirkBreathing"
+
+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_ */
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/plugin-quirks.c
^
|
@@ -0,0 +1,188 @@
+/** @file plugin-quirks.c
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2017 Jolla Ltd.
+ * <p>
+ * @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
+ *
+ * mce-plugin-libhybris is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License.
+ *
+ * mce-plugin-libhybris is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with mce-plugin-libhybris; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "plugin-quirks.h"
+
+#include "plugin-config.h"
+#include "plugin-logging.h"
+
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+
+/* ========================================================================= *
+ * QUIRKS
+ * ========================================================================= */
+
+/** Strings that should be treated as "1" when evaluating quirk settings */
+static const char * const quirk_true_lut[] =
+{
+ "true", "yes", "enabled", 0
+};
+
+/** Strings that should be treated as "0" when evaluating quirk settings */
+static const char * const quirk_false_lut[] =
+{
+ "false", "no", "disabled", 0
+};
+
+/** Quirk enum id to settings ini-file key lookup table */
+static const char * const quirk_name_lut[QUIRK_COUNT] =
+{
+ [QUIRK_BREATHING] = MCE_CONF_LED_CONFIG_HYBRIS_BREATHING,
+};
+
+/** Flag array for: quirk setting has been defined in mce config */
+static bool quirk_defined_lut[QUIRK_COUNT];
+
+/** Value array for: quirk settings defined in mce config */
+static int quirk_value_lut[QUIRK_COUNT];
+
+/** Helper for checking string exists in an array
+ *
+ * @param vec Array of strings
+ * @param str String to look for
+ *
+ * @return true if string exists in array, false otherwise
+ */
+static bool
+quirk_in_array(const char * const *vec, const char *str)
+{
+ for( ; *vec; ++vec )
+ if( !strcmp(*vec, str) )
+ return true;
+
+ return false;
+}
+
+/** Helper for parsing integer quirk setting values
+ *
+ * To allow improved readability, various aliases for boolean
+ * type values are converted to true/1 or false/0.
+ *
+ * @param str String value from ini-file
+ *
+ * @return Integer value, or zero as fallback value
+ */
+static int
+quirk_parse_value(const char *str)
+{
+ int val = false;
+
+ if( !str )
+ goto EXIT;
+
+ if( quirk_in_array(quirk_false_lut, str) )
+ goto EXIT;
+
+ val = true;
+
+ if( quirk_in_array(quirk_true_lut, str) )
+ goto EXIT;
+
+ val = strtol(str, 0, 0);
+
+EXIT:
+ return val;
+}
+
+/** Populate quirk value array using data from mce configuration files
+ */
+static void
+plugin_quirk_init(void)
+{
+ for( quirk_t id = 0; id < QUIRK_COUNT; ++id ) {
+ gchar *val = plugin_config_get_string(MCE_CONF_LED_CONFIG_HYBRIS_GROUP,
+ quirk_name_lut[id], 0);
+ if( !val )
+ continue;
+
+ quirk_defined_lut[id] = true;
+ quirk_value_lut[id] = quirk_parse_value(val);
+ mce_log(LOG_DEBUG, "set %s = %d",
+ quirk_name_lut[id],
+ quirk_value_lut[id]);
+ g_free(val);
+ }
+}
+
+/** Predicat for: numerical quirk id is valid
+ *
+ * @param id Quirk ID
+ *
+ * @return true if id is valid, false otherwise
+ */
+static bool
+quirk_is_valid(quirk_t id)
+{
+ return id > QUIRK_INVALID && id < QUIRK_COUNT && quirk_name_lut[id];
+}
+
+/** Predicat for: Value for quirk id has been defined in configuration
+ *
+ * @param id Quirk ID
+ *
+ * @return true if id is valid and defined, false otherwise
+ */
+static bool
+quirk_is_defined(quirk_t id)
+{
+ return quirk_is_valid(id) && quirk_defined_lut[id];
+}
+
+/** Get human readable name for a quirk id
+ *
+ * @param id Quirk ID
+ *
+ * @return quirk name used in setting ini-files, or "QuirkInvalid"
+ */
+const char *
+quirk_name(quirk_t id)
+{
+ const char *repr = 0;
+
+ if( quirk_is_valid(id) )
+ repr = quirk_name_lut[id];
+
+ return repr ?: "QuirkInvalid";
+}
+
+/* Get value associated with quirk id
+ *
+ * @param id Quirk ID
+ * @param def Fallback value
+ *
+ * @return Configured quirk value, or the caller provided default value
+ */
+int
+quirk_value(quirk_t id, int def)
+{
+ static bool done = false;
+
+ if( !done ) {
+ done = true;
+ plugin_quirk_init();
+ }
+
+ return quirk_is_defined(id) ? quirk_value_lut[id] : def;
+}
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/plugin-quirks.h
^
|
@@ -0,0 +1,64 @@
+/** @file plugin-quirks.h
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2017 Jolla Ltd.
+ * <p>
+ * @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
+ *
+ * mce-plugin-libhybris is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License.
+ *
+ * mce-plugin-libhybris is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with mce-plugin-libhybris; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef PLUGIN_QUIRKS_H_
+# define PLUGIN_QUIRKS_H_
+
+# include "plugin-logging.h"
+
+/* ========================================================================= *
+ * QUIRKS
+ * ========================================================================= */
+
+/** Quirk setting IDs */
+typedef enum
+{
+ /** Placeholder ID */
+ QUIRK_INVALID = -1,
+
+ /** Override sw breathing desicion made by led backend */
+ QUIRK_BREATHING,
+
+ /** Number of quirks */
+ QUIRK_COUNT
+} quirk_t;
+
+const char *quirk_name(quirk_t id);
+
+int quirk_value(quirk_t id, int def);
+
+/** Helper for caching quirk value locally and logging use for debug purposes
+ */
+#define QUIRK(id,def) ({\
+ static bool done = false;\
+ static int value = 0;\
+ if( !done ) {\
+ done = true;\
+ value = quirk_value((id),(def));\
+ mce_log(LOG_DEBUG, "use %s = %d",\
+ quirk_name((id)), value);\
+ }\
+ value;\
+})
+
+#endif /* PLUGIN_QUIRKS_H_ */
|
[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/sysfs-led-bacon.c
^
|
@@ -37,8 +37,10 @@
#include "sysfs-led-util.h"
#include "plugin-logging.h"
+#include "plugin-config.h"
#include <stdio.h>
+#include <string.h>
#include <glib.h>
@@ -146,6 +148,8 @@
* ALL_CHANNELS
* ========================================================================= */
+#define BACON_CHANNELS 3
+
static void
led_control_bacon_enable_cb(void *data, bool enable)
{
@@ -153,7 +157,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 +180,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 +203,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 +219,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 +231,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 +263,78 @@
},
};
- 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];
+
+ memset(paths, 0, sizeof paths);
+ 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+i, &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 +352,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.1.tar.bz2/sysfs-led-binary.c
^
|
@@ -35,8 +35,11 @@
#include "sysfs-led-binary.h"
#include "sysfs-led-util.h"
+#include "sysfs-val.h"
+#include "plugin-config.h"
#include <stdio.h>
+#include <string.h>
#include <glib.h>
@@ -46,14 +49,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 +85,184 @@
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_rw(self->cached_brightness, path->brightness) )
+ goto cleanup;
- self->maxval = 1;
+ if( sysfsval_open_ro(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",
+ },
+ },
+ };
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/sysfs-led-f5121.c
^
|
@@ -0,0 +1,382 @@
+/** @file sysfs-led-f5121.c
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2017 Jolla Ltd.
+ * <p>
+ * @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
+ * @author Kimmo Lindholm <kimmo.lindholm@eke.fi>
+ *
+ * mce-plugin-libhybris is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License.
+ *
+ * mce-plugin-libhybris is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with mce-plugin-libhybris; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/* ========================================================================= *
+ * RGB led control: Sony Xperia X backend
+ *
+ * Three channels, all of which:
+ * - must have 'brightness' control file
+ * - must have 'max_brightness' control file
+ * - must have 'blink' control file
+ *
+ * Assumptions built into code:
+ * - writing to 'blink' affects 'brightness' control too and vice versa
+ * ========================================================================= */
+
+#include "sysfs-led-f5121.h"
+#include "sysfs-led-util.h"
+#include "sysfs-val.h"
+#include "plugin-config.h"
+
+#include <stdio.h>
+#include <string.h>
+
+#include <glib.h>
+
+/* ========================================================================= *
+ * PROTOTYPES
+ * ========================================================================= */
+
+typedef struct
+{
+ const char *max_brightness;
+ const char *brightness;
+ const char *blink;
+} led_paths_f5121_t;
+
+typedef struct
+{
+ sysfsval_t *cached_max_brightness;
+ sysfsval_t *cached_brightness;
+ sysfsval_t *cached_blink;
+
+ int control_value;
+ bool control_blink;
+
+} led_channel_f5121_t;
+
+/* ------------------------------------------------------------------------- *
+ * ONE_CHANNEL
+ * ------------------------------------------------------------------------- */
+
+static void led_channel_f5121_init (led_channel_f5121_t *self);
+static void led_channel_f5121_close (led_channel_f5121_t *self);
+static bool led_channel_f5121_probe (led_channel_f5121_t *self, const led_paths_f5121_t *path);
+static void led_channel_f5121_set_value (led_channel_f5121_t *self, int value);
+static void led_channel_f5121_set_blink (led_channel_f5121_t *self, int on_ms, int off_ms);
+
+/* ------------------------------------------------------------------------- *
+ * ALL_CHANNELS
+ * ------------------------------------------------------------------------- */
+
+static void led_control_f5121_blink_cb (void *data, int on_ms, int off_ms);
+static void led_control_f5121_value_cb (void *data, int r, int g, int b);
+static void led_control_f5121_close_cb (void *data);
+
+bool led_control_f5121_probe (led_control_t *self);
+
+/* ========================================================================= *
+ * ONE_CHANNEL
+ * ========================================================================= */
+
+static void
+led_channel_f5121_init(led_channel_f5121_t *self)
+{
+ self->cached_max_brightness = sysfsval_create();
+ self->cached_brightness = sysfsval_create();
+ self->cached_blink = sysfsval_create();
+
+ self->control_blink = false;
+ self->control_value = 0;
+}
+
+static void
+led_channel_f5121_close(led_channel_f5121_t *self)
+{
+ 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
+led_channel_f5121_probe(led_channel_f5121_t *self,
+ const led_paths_f5121_t *path)
+{
+ bool ack = false;
+
+ /* Probe control files in reverse existance likelihood order.
+ * Practically all led control directories have 'brightness'
+ * file, most have 'max_brightness' while only some have 'blink'.
+ */
+ if( !sysfsval_open_rw(self->cached_blink, path->blink) )
+ goto cleanup;
+
+ if( !sysfsval_open_ro(self->cached_max_brightness, path->max_brightness) )
+ goto cleanup;
+
+ /* The 'max_brightness' seems to be dynamic. Make an attempt
+ * to set it to an artificially high value and assume that kernel
+ * side will cap the value to the true maximum... */
+#if 0 // TODO: make a QUIRK out of this
+ sysfsval_set(self->cached_max_brightness, 255);
+#endif
+ sysfsval_refresh(self->cached_max_brightness);
+
+ if( sysfsval_get(self->cached_max_brightness) <= 0 )
+ goto cleanup;
+
+ if( !sysfsval_open_rw(self->cached_brightness, path->brightness) )
+ goto cleanup;
+
+ ack = true;
+
+cleanup:
+
+ /* Always close the max_brightness file */
+ sysfsval_close(self->cached_max_brightness);
+
+ /* On failure close the other files too */
+ if( !ack ) {
+ sysfsval_close(self->cached_brightness);
+ sysfsval_close(self->cached_blink);
+ }
+
+ return ack;
+}
+
+static void
+led_channel_f5121_set_value(led_channel_f5121_t *self,
+ int value)
+{
+ value = led_util_scale_value(value,
+ sysfsval_get(self->cached_max_brightness));
+
+ /* Ignore blinking requests while brightness is zero. */
+ if( value <= 0 )
+ self->control_blink = false;
+
+ /* Logically it probably should be that:
+ * - writing blink=1 implies brightness=255
+ * - writing blink=0 implies brightness=0
+ * - writing brightness=n implies blink=0
+ *
+ * However it seems swithing between blinking and non-blinking
+ * modes can cause hiccups that vary from one device to another
+ * (stale sysfs values left behind, led stays off when it should
+ * be lit, ...)
+ *
+ * So the logic is arranged that before switching from static
+ * color to blinking, a brightness=0 is done before writing
+ * blink=0, and when swithing from blinking to static color, a
+ * blink=0 is done before writing brightness=0.
+ *
+ * Note that upper level state machine logic + caching of the
+ * assumed sysfs values means that these transitions are done in
+ * 3 steps (cancel previous mode, reset to black, switch to new
+ * mode) with pproximately SYSFS_LED_KERNEL_DELAY ms in between
+ * the steps.
+ */
+ if( self->control_blink ) {
+ sysfsval_set(self->cached_brightness, 0);
+ sysfsval_set(self->cached_blink, 1);
+ }
+ else {
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/sysfs-led-f5121.h
^
|
@@ -0,0 +1,31 @@
+/** @file sysfs-led-f5121.h
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2017 Jolla Ltd.
+ * <p>
+ * @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
+ *
+ * mce-plugin-libhybris is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License.
+ *
+ * mce-plugin-libhybris is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with mce-plugin-libhybris; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef SYSFS_LED_F5121_H_
+# define SYSFS_LED_F5121_H_
+
+# include "sysfs-led-main.h"
+
+bool led_control_f5121_probe(led_control_t *self);
+
+#endif /* SYSFS_LED_F5121_H_ */
|
[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/sysfs-led-hammerhead.c
^
|
@@ -40,9 +40,11 @@
#include "sysfs-led-hammerhead.h"
#include "sysfs-led-util.h"
+#include "plugin-config.h"
#include <stdio.h>
#include <unistd.h>
+#include <string.h>
#include <glib.h>
@@ -52,18 +54,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 +97,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 +119,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 +144,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 +154,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 +164,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 +181,8 @@
* ALL_CHANNELS
* ========================================================================= */
+#define HAMMERHEAD_CHANNELS 3
+
static void
led_control_hammerhead_enable_cb(void *data, bool enable)
{
@@ -215,38 +219,101 @@
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)
+{
|
[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/sysfs-led-htcvision.c
^
|
@@ -38,8 +38,11 @@
#include "sysfs-led-htcvision.h"
#include "sysfs-led-util.h"
+#include "sysfs-val.h"
+#include "plugin-config.h"
#include <stdio.h>
+#include <string.h>
#include <glib.h>
@@ -49,16 +52,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 +92,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 +116,30 @@
{
bool res = false;
- led_channel_htcvision_close(self);
-
- if( (self->maxval = led_util_read_number(path->max)) <= 0 )
- {
+ if( !sysfsval_open_rw(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_rw(self->cached_brightness, path->brightness) )
goto cleanup;
- }
+
+ if( sysfsval_open_ro(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 +148,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 +224,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 +233,82 @@
// 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"
+ };
|
[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/sysfs-led-main.c
^
|
@@ -27,15 +27,19 @@
#include "sysfs-led-vanilla.h"
#include "sysfs-led-hammerhead.h"
#include "sysfs-led-bacon.h"
+#include "sysfs-led-f5121.h"
#include "sysfs-led-htcvision.h"
#include "sysfs-led-binary.h"
#include "sysfs-led-redgreen.h"
#include "sysfs-led-white.h"
#include "plugin-logging.h"
+#include "plugin-config.h"
+#include "plugin-quirks.h"
#include <stdint.h>
#include <unistd.h>
+#include <string.h>
#include <math.h>
#include <errno.h>
@@ -214,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 */
@@ -255,44 +262,82 @@
/* The probing should be done in order that minimizes
* chances of false positives.
*/
- static const led_control_probe_fn lut[] =
+ static const struct
+ {
+ const char *name;
+ led_control_probe_fn func;
+ } lut[] =
{
/* The hammerhead backend requires presense of
* unique 'on_off_ms' and 'rgb_start' files. */
- led_control_hammerhead_probe,
+ { "hammerhead", led_control_hammerhead_probe },
/* The htc vision backend requires presense of
* unique 'amber' control directory. */
- led_control_htcvision_probe,
+ { "htcvision", led_control_htcvision_probe },
/* The bacon backend */
- led_control_bacon_probe,
+ { "bacon", led_control_bacon_probe },
+
+ /* The f5121 requires 'brightness', 'max_brightness' and 'blink'
+ * control files to be present for red, green and blue channels. */
+ { "f5121", led_control_f5121_probe },
/* The vanilla backend requires only 'brightness'
* control file, but still needs three directories
* to be present for red, green and blue channels. */
- led_control_vanilla_probe,
+ { "vanilla", led_control_vanilla_probe },
/* The redgreen uses subset of "standard" rgb led
* control paths, so to avoid false positive matches
* it must be probed after rgb led controls. */
- led_control_redgreen_probe,
+ { "redgreen", led_control_redgreen_probe },
/* Single control channel with actually working
* brightness control and max_brightness. */
- led_control_white_probe,
+ { "white", led_control_white_probe },
/* The binary backend needs just one directory
* that has 'brightness' control file. */
- led_control_binary_probe,
+ { "binary", led_control_binary_probe },
};
+ bool ack = false;
+ gchar *name = plugin_config_get_string(MCE_CONF_LED_CONFIG_HYBRIS_GROUP,
+ MCE_CONF_LED_CONFIG_HYBRIS_BACKEND,
+ 0);
+
for( size_t i = 0; i < G_N_ELEMENTS(lut); ++i )
{
- if( lut[i](self) ) return true;
+ 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;
+ }
+
+ if( !lut[i].func(self) )
+ {
+ continue;
+ }
+
+ self->can_breathe = QUIRK(QUIRK_BREATHING, self->can_breathe);
+
+ ack = true;
+ break;
}
- return false;
+ g_free(name);
+
+ return ack;
}
/** Set RGB LED enabled/disable
@@ -465,6 +510,7 @@
static void
sysfs_led_set_rgb_blink(int on, int off)
{
+ mce_log(LOG_DEBUG, "on_ms = %d, off_ms = %d", on, off);
led_control_blink(&led_control, on, off);
}
@@ -473,6 +519,7 @@
static void
sysfs_led_set_rgb_value(int r, int g, int b)
{
+ mce_log(LOG_DEBUG, "rgb = %d %d %d", r, g, b);
led_control_value(&led_control, r, g, b);
}
@@ -779,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.1.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.1.tar.bz2/sysfs-led-redgreen.c
^
|
@@ -36,8 +36,11 @@
#include "sysfs-led-redgreen.h"
#include "sysfs-led-util.h"
+#include "sysfs-val.h"
+#include "plugin-config.h"
#include <stdio.h>
+#include <string.h>
#include <glib.h>
@@ -47,14 +50,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 +86,207 @@
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_rw(self->cached_brightness, path->brightness) )
+ goto cleanup;
- if( (self->maxval = led_util_read_number(path->max)) <= 0 )
- {
- goto cleanup;
- }
+ if( sysfsval_open_ro(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];
|
[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/sysfs-led-vanilla.c
^
|
@@ -47,8 +47,11 @@
#include "sysfs-led-vanilla.h"
#include "sysfs-led-util.h"
+#include "sysfs-val.h"
+#include "plugin-config.h"
#include <stdio.h>
+#include <string.h>
#include <glib.h>
@@ -58,27 +61,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 +105,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 +137,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_ro(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_rw(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_rw(self->cached_blink_delay_on, path->blink_delay_on) ) {
+ if( !sysfsval_open_rw(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_rw(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
|
[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/sysfs-led-white.c
^
|
@@ -32,8 +32,11 @@
#include "sysfs-led-white.h"
#include "sysfs-led-util.h"
+#include "sysfs-val.h"
+#include "plugin-config.h"
#include <stdio.h>
+#include <string.h>
#include <glib.h>
@@ -43,14 +46,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 +82,186 @@
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_rw(self->cached_brightness, path->brightness) )
+ goto cleanup;
- led_channel_white_close(self);
+ if( !sysfsval_open_ro(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);
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/sysfs-val.c
^
|
@@ -0,0 +1,374 @@
+/** @file sysfs-val.c
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2017 Jolla Ltd.
+ * <p>
+ * @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
+ *
+ * mce-plugin-libhybris is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License.
+ *
+ * mce-plugin-libhybris is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with mce-plugin-libhybris; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "sysfs-val.h"
+
+#include "plugin-logging.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+
+/* ========================================================================= *
+ * TYPES
+ * ========================================================================= */
+
+struct sysfsval_t
+{
+ char *sv_path;
+ int sv_file;
+ int sv_curr;
+};
+
+/* ========================================================================= *
+ * PROTOS
+ * ========================================================================= */
+
+static void sysfsval_ctor (sysfsval_t *self);
+static void sysfsval_dtor (sysfsval_t *self);
+
+sysfsval_t *sysfsval_create (void);
+void sysfsval_delete (sysfsval_t *self);
+bool sysfsval_open_rw (sysfsval_t *self, const char *path);
+bool sysfsval_open_ro (sysfsval_t *self, const char *path);
+static bool sysfsval_open_ex (sysfsval_t *self, const char *path, mode_t mode);
+void sysfsval_close (sysfsval_t *self);
+const char *sysfsval_path (const sysfsval_t *self);
+int sysfsval_get (const sysfsval_t *self);
+bool sysfsval_set (sysfsval_t *self, int value);
+void sysfsval_invalidate(sysfsval_t *self);
+bool sysfsval_refresh (sysfsval_t *self);
+
+/* ========================================================================= *
+ * CODE
+ * ========================================================================= */
+
+/** Initialize sysfsval_t object to a sane state
+ *
+ * @param self sysfsval_t object pointer
+ */
+static void
+sysfsval_ctor(sysfsval_t *self)
+{
+ self->sv_path = 0;
+ self->sv_file = -1;
+ self->sv_curr = -1;
+}
+
+/** Release all dynamically allocated resources used by sysfsval_t object
+ *
+ * @param self sysfsval_t object pointer
+ */
+static void
+sysfsval_dtor(sysfsval_t *self)
+{
+ sysfsval_close(self);
+}
+
+/** Allocate and initialize an sysfsval_t object
+ *
+ * @return sysfsval_t object pointer
+ */
+sysfsval_t *
+sysfsval_create(void)
+{
+ sysfsval_t *self = calloc(1, sizeof *self);
+ sysfsval_ctor(self);
+ return self;
+}
+
+/** De-initialize and release sysfsval_t object
+ *
+ * @param self sysfsval_t object pointer, or NULL
+ */
+void
+sysfsval_delete(sysfsval_t *self)
+{
+ if( self ) {
+ sysfsval_dtor(self);
+ free(self);
+ }
+}
+
+/** Assign path to sysfsval_t object and open the file in read+write mode
+ *
+ * @param self sysfsval_t object pointer
+ *
+ * @return true if file was opened succesfully, false otherwise
+ */
+bool
+sysfsval_open_rw(sysfsval_t *self, const char *path)
+{
+ return sysfsval_open_ex(self, path, O_RDWR);
+}
+
+/** Assign path to sysfsval_t object and open the file in read-only mode
+ *
+ * @param self sysfsval_t object pointer
+ *
+ * @return true if file was opened succesfully, false otherwise
+ */
+bool
+sysfsval_open_ro(sysfsval_t *self, const char *path)
+{
+ return sysfsval_open_ex(self, path, O_RDONLY);
+}
+
+static bool
+sysfsval_open_ex(sysfsval_t *self, const char *path, mode_t mode)
+{
+ bool ack = false;
+
+ sysfsval_close(self);
+
+ if( !path )
+ goto EXIT;
+
+ if( (self->sv_path = strdup(path)) == 0 )
+ goto EXIT;
+
+ if( (self->sv_file = open(path, mode)) == -1 ) {
+ if( errno == ENOENT )
+ mce_log(LOG_DEBUG, "%s: open: %m", path);
+ else
+ mce_log(LOG_ERR, "%s: open: %m", path);
+ goto EXIT;
+ }
+
+ mce_log(LOG_DEBUG, "%s: opened", sysfsval_path(self));
+
+ /* Note: Current value is not fetched by default */
+
+ ack = true;
+
+EXIT:
+ if( !ack )
+ sysfsval_close(self);
+
+ return ack;
+}
+
+/** Close file associated with sysfsval_t object and forget file path
+ *
+ * @param self sysfsval_t object pointer
+ */
+void
+sysfsval_close(sysfsval_t *self)
+{
+ if( self->sv_file != -1 ) {
+ mce_log(LOG_DEBUG, "%s: closed", sysfsval_path(self));
+ close(self->sv_file), self->sv_file = -1;
+ }
+
+ free(self->sv_path), self->sv_path = 0;
+}
+
+/** Get file path associated with sysfsval_t object
+ *
+ * Note: This function is meant to be used only for diagnostic
+ * logging and it can be assumed to always return a valid c string.
+ *
+ * @param self sysfsval_t object pointer
+ *
+ * @return file path, or "unset"
+ */
+const char *
+sysfsval_path(const sysfsval_t *self)
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/sysfs-val.h
^
|
@@ -0,0 +1,51 @@
+/** @file sysfs-val.h
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2017 Jolla Ltd.
+ * <p>
+ * @author Simo Piiroinen <simo.piiroinen@jollamobile.com>
+ *
+ * mce-plugin-libhybris is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License.
+ *
+ * mce-plugin-libhybris is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with mce-plugin-libhybris; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef SYSFS_VAL_H_
+# define SYSFS_VAL_H_
+
+#include <stdbool.h>
+
+/* ========================================================================= *
+ * TYPES
+ * ========================================================================= */
+
+typedef struct sysfsval_t sysfsval_t;
+
+/* ========================================================================= *
+ * PROTOS
+ * ========================================================================= */
+
+sysfsval_t *sysfsval_create (void);
+void sysfsval_delete (sysfsval_t *self);
+bool sysfsval_open_rw (sysfsval_t *self, const char *path);
+bool sysfsval_open_ro (sysfsval_t *self, const char *path);
+void sysfsval_close (sysfsval_t *self);
+const char *sysfsval_path (const sysfsval_t *self);
+int sysfsval_get (const sysfsval_t *self);
+bool sysfsval_set (sysfsval_t *self, int value);
+void sysfsval_assume (sysfsval_t *self, int value);
+void sysfsval_invalidate(sysfsval_t *self);
+bool sysfsval_refresh (sysfsval_t *self);
+
+#endif /* SYSFS_VAL_H_ */
|