[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris.changes
|
|
[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris.spec
^
|
|
[-]
[+]
|
Changed |
_service
^
|
@@ -4,11 +4,10 @@
<param name="branch">master</param>
</service>
<service name="tar_git">
- <param name="url">https://github.com/nemomobile/mce-plugin-libhybris.git</param>
- <param name="branch">master</param>
- <param name="revision"/>
- <param name="token"/>
- <param name="debian">N</param>
- <param name="dumb">N</param>
- </service>
-</services>
\ No newline at end of file
+ <param name="url">https://github.com/nemomobile/mce-plugin-libhybris.git</param>
+ <param name="branch">master</param>
+ <param name="revision">7d214b910530f9474331fe2e890ec48081361966</param>
+ <param name="token"/>
+ <param name="debian">N</param>
+ <param name="dumb">N</param>
+</service></services>
|
[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris-1.11.0.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,6 +84,18 @@
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-logging.h\
@@ -100,6 +122,20 @@
sysfs-led-main.h\
sysfs-led-util.h\
+sysfs-led-f5121.o:\
+ sysfs-led-f5121.c\
+ sysfs-led-f5121.h\
+ sysfs-led-main.h\
+ sysfs-led-util.h\
+ sysfs-val.h\
+
+sysfs-led-f5121.pic.o:\
+ sysfs-led-f5121.c\
+ sysfs-led-f5121.h\
+ sysfs-led-main.h\
+ sysfs-led-util.h\
+ sysfs-val.h\
+
sysfs-led-hammerhead.o:\
sysfs-led-hammerhead.c\
sysfs-led-hammerhead.h\
@@ -126,9 +162,12 @@
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 +178,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\
@@ -196,3 +238,13 @@
sysfs-led-util.h\
sysfs-led-white.h\
+sysfs-val.o:\
+ sysfs-val.c\
+ plugin-logging.h\
+ sysfs-val.h\
+
+sysfs-val.pic.o:\
+ sysfs-val.c\
+ plugin-logging.h\
+ sysfs-val.h\
+
|
[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris-1.11.0.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.11.0.tar.bz2/plugin-config.c
^
|
@@ -0,0 +1,59 @@
+/** @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"
+
+/* ========================================================================= *
+ * 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) )
+ goto EXIT;
+
+ if( (res = mce_conf_get_string(group, key, defaultval)) )
+ mce_log(LOG_DEBUG, "[%s] %s = %s", group, key, res ?: "(null)");
+
+EXIT:
+ return res;
+}
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.11.0.tar.bz2/plugin-config.h
^
|
@@ -0,0 +1,46 @@
+/** @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 <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);
+
+#endif /* PLUGIN_CONFIG_H_ */
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.11.0.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.11.0.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_ */
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.11.0.tar.bz2/sysfs-led-f5121.c
^
|
@@ -0,0 +1,320 @@
+/** @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 <stdio.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(self->cached_blink, path->blink) )
+ goto cleanup;
+
+ if( !sysfsval_open(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(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 {
+ sysfsval_set(self->cached_blink, 0);
+ sysfsval_set(self->cached_brightness, value);
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.11.0.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.11.0.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>
@@ -255,44 +259,72 @@
/* 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;
+ 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 +497,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 +506,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);
}
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.11.0.tar.bz2/sysfs-val.c
^
|
@@ -0,0 +1,320 @@
+/** @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>
+
+/* ========================================================================= *
+ * 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 (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_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 attempt to open the file
+ *
+ * @param self sysfsval_t object pointer
+ *
+ * @return true if file was opened succesfully, false otherwise
+ */
+bool
+sysfsval_open(sysfsval_t *self, const char *path)
+{
+ 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, O_RDWR)) == -1 )
+ 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)
+{
+ return self->sv_path ?: "unset";
+}
+
+/** Get integer value associated with sysfsval_t object
+ *
+ * @param self sysfsval_t object pointer
+ *
+ * @return cached content of sysfs file as integer, or -1
+ */
+int
+sysfsval_get(const sysfsval_t *self)
+{
+ return self->sv_curr;
+}
+
+/** Update sysfs content associated with sysfsval_t object
+ *
+ * @param self sysfsval_t object pointer
+ * @param value number to write to sysfs file
+ *
+ * @return false if updating sysfs content failed, true otherwise
+ */
+bool
+sysfsval_set(sysfsval_t *self, int value)
+{
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.11.0.tar.bz2/sysfs-val.h
^
|
@@ -0,0 +1,50 @@
+/** @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 (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_ */
|