[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris.changes
|
|
[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris.spec
^
|
|
[-]
[+]
|
Changed |
_service
^
|
@@ -2,6 +2,6 @@
<service name="tar_git">
<param name="url">https://github.com/nemomobile/mce-plugin-libhybris.git</param>
<param name="branch">master</param>
- <param name="revision">c536e79e45f993253302036c8ae9a5b2874831f8</param>
+ <param name="revision">HEAD</param>
</service>
</services>
\ No newline at end of file
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/.depend
^
|
@@ -0,0 +1,290 @@
+hybris-fb.o:\
+ hybris-fb.c\
+ hybris-fb.h\
+ plugin-api.h\
+ plugin-logging.h\
+
+hybris-fb.pic.o:\
+ hybris-fb.c\
+ hybris-fb.h\
+ plugin-api.h\
+ plugin-logging.h\
+
+hybris-lights.o:\
+ hybris-lights.c\
+ hybris-lights.h\
+ plugin-api.h\
+ plugin-logging.h\
+
+hybris-lights.pic.o:\
+ hybris-lights.c\
+ hybris-lights.h\
+ plugin-api.h\
+ plugin-logging.h\
+
+hybris-sensors.o:\
+ hybris-sensors.c\
+ hybris-sensors.h\
+ hybris-thread.h\
+ plugin-api.h\
+ plugin-logging.h\
+
+hybris-sensors.pic.o:\
+ hybris-sensors.c\
+ hybris-sensors.h\
+ hybris-thread.h\
+ plugin-api.h\
+ plugin-logging.h\
+
+hybris-thread.o:\
+ hybris-thread.c\
+ hybris-thread.h\
+ plugin-logging.h\
+
+hybris-thread.pic.o:\
+ hybris-thread.c\
+ hybris-thread.h\
+ plugin-logging.h\
+
+plugin-api.o:\
+ plugin-api.c\
+ hybris-fb.h\
+ hybris-lights.h\
+ hybris-sensors.h\
+ plugin-api.h\
+ plugin-logging.h\
+ sysfs-led-main.h\
+
+plugin-api.pic.o:\
+ plugin-api.c\
+ hybris-fb.h\
+ hybris-lights.h\
+ hybris-sensors.h\
+ plugin-api.h\
+ 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\
+ plugin-logging.h\
+
+plugin-logging.pic.o:\
+ plugin-logging.c\
+ 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\
+ sysfs-led-util.h\
+
+sysfs-led-bacon.pic.o:\
+ sysfs-led-bacon.c\
+ plugin-config.h\
+ plugin-logging.h\
+ sysfs-led-bacon.h\
+ sysfs-led-main.h\
+ sysfs-led-util.h\
+
+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\
+ sysfs-led-redgreen.h\
+ sysfs-led-util.h\
+ sysfs-led-vanilla.h\
+ sysfs-led-white.h\
|
[-]
[+]
|
Changed |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/Makefile
^
|
@@ -28,7 +28,7 @@
$(RM) $(TARGETS)
distclean:: clean
- $(RM) *.so *.p *.q
+ $(RM) *.so *.p *.q *.i
mostlyclean::
$(RM) *.o *~ *.bak
@@ -40,12 +40,14 @@
CPPFLAGS += -D_GNU_SOURCE
CPPFLAGS += -D_FILE_OFFSET_BITS=64
CPPFLAGS += -D_THREAD_SAFE
+CPPFLAGS += -DMCE_HYBRIS_INTERNAL=2
COMMON += -Wall
-COMMON += -W
+COMMON += -Wextra
COMMON += -Wmissing-prototypes
COMMON += -Os
COMMON += -g
+COMMON += -fvisibility=hidden
CFLAGS += $(COMMON)
CFLAGS += -std=c99
@@ -90,25 +92,50 @@
.SUFFIXES: %.pic.o
.PRECIOUS: %.pic.o
-%.so : %.pic.o
+%.so :
$(CC) -o $@ -shared $^ $(LDFLAGS) $(LDLIBS)
%.pic.o : %.c
$(CC) -c -o $@ $< -fPIC $(CPPFLAGS) $(CFLAGS)
%.q : %.c
- $(CC) -E -o $@ $<
+ $(CC) -E -o $@ $(CPPFLAGS) $<
%.p : %.q
- cat $< | cproto | sed -e 's/_Bool/bool/g' > $@
-# cat $< | cproto -S | sed -e 's/_Bool/bool/g' > $@
+ cat $< | cproto | prettyproto.py > $@
+%.i : %.q
+ cat $< | cproto -s | prettyproto.py > $@
+
+preprocess: $(patsubst %.c,%.q,$(wildcard *.c))
+prototypes: $(patsubst %.c,%.p,$(wildcard *.c))
+locals: $(patsubst %.c,%.i,$(wildcard *.c))
# ----------------------------------------------------------------------------
# Explicit dependencies
# ----------------------------------------------------------------------------
+hybris_OBJS += hybris-fb.pic.o
+hybris_OBJS += hybris-lights.pic.o
+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
+hybris_OBJS += sysfs-led-redgreen.pic.o
+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.pic.o
+hybris.so : $(hybris_OBJS)
install:: hybris.so
install -d -m755 $(DESTDIR)$(_LIBDIR)/mce/modules
@@ -122,3 +149,41 @@
normalize::
normalize_whitespace -M Makefile
normalize_whitespace -a $(wildcard *.[ch] *.cc *.cpp)
+
+# ----------------------------------------------------------------------------
+# AUTOMATIC HEADER DEPENDENCIES
+# ----------------------------------------------------------------------------
+
+.PHONY: depend
+depend::
+ @echo "Updating .depend"
+ $(CC) -MM $(CPPFLAGS) $(MCE_CFLAGS) $(wildcard *.c) |\
+ ./depend_filter.py > .depend
+
+ifneq ($(MAKECMDGOALS),depend) # not while: make depend
+ifneq (,$(wildcard .depend)) # not if .depend does not exist
+include .depend
+endif
+endif
+
+# ----------------------------------------------------------------------------
+# Hunt for excess include statements
+# ----------------------------------------------------------------------------
+
+.PHONY: headers
+.SUFFIXES: %.checked
+
+headers:: c_headers c_sources
+
+%.checked : %
+ find_unneeded_includes.py $(CPPFLAGS) $(CFLAGS) -- $<
+ @touch $@
+
+clean::
+ $(RM) *.checked *.order
+
+c_headers:: $(patsubst %,%.checked,$(wildcard *.h))
+c_sources:: $(patsubst %,%.checked,$(wildcard *.c))
+
+order::
+ find_unneeded_includes.py -- $(wildcard *.h) $(wildcard *.c)
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/depend_filter.py
^
|
@@ -0,0 +1,70 @@
+#!/usr/bin/env python
+# -*- encoding: utf8 -*-
+
+# ----------------------------------------------------------------------------
+# Copyright (C) 2012-2017 Jolla Ltd.
+# Contact: Simo Piiroinen <simo.piiroinen@jollamobile.com>
+# License: GPLv2
+# ----------------------------------------------------------------------------
+
+import sys,os
+
+def is_local(path):
+ return not path.startswith("/")
+
+def print_rule(dest, srce):
+ print "%s\\\n" % "\\\n\t".join(["%s:" % dest] + srce)
+
+def set_extension(path, ext):
+ return os.path.splitext(path)[0] + ext
+
+def normalize_path(srce):
+ return os.path.normpath(srce)
+
+def fix_directory(dest, srce):
+ srce = os.path.dirname(srce)
+ dest = os.path.basename(dest)
+ return os.path.join(srce, dest)
+
+if __name__ == "__main__":
+
+ data = sys.stdin.readlines()
+ data = map(lambda x:x.rstrip(), data)
+ data.reverse()
+
+ deps = []
+
+ # Note: dependencies are sorted only to keep
+ # future diffs cleaner
+
+ while data:
+ line = data.pop()
+ while line.endswith('\\'):
+ line = line[:-1] + data.pop()
+ if not ':' in line:
+ continue
+
+ dest,srce = line.split(":",1)
+ srce = srce.split()
+ srce,temp = srce[0],srce[1:]
+
+ # take dest path primary srce
+ dest = fix_directory(dest, srce)
+
+ # remove secondary deps with absolute path
+ temp = filter(is_local, temp)
+
+ # sort secondary sources
+ temp.sort()
+
+ srce = [srce] + temp
+ srce = map(normalize_path, srce)
+
+ deps.append((dest,srce))
+
+ for dest,srce in sorted(deps):
+ # emit normal compilation dependencies
+ print_rule(dest, srce)
+ # and for -fPIC in case it is needed
+ dest = set_extension(dest, ".pic.o")
+ print_rule(dest, srce)
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/hybris-fb.c
^
|
@@ -0,0 +1,216 @@
+/** @file hybris-fb.c
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2013-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 "hybris-fb.h"
+#include "plugin-logging.h"
+
+#include "plugin-api.h"
+
+#include <system/window.h>
+#include <hardware/fb.h>
+
+/* ========================================================================= *
+ * PROTOTYPES
+ * ========================================================================= */
+
+/* ------------------------------------------------------------------------- *
+ * FRAMEBUFFER_PLUGIN
+ * ------------------------------------------------------------------------- */
+
+bool hybris_plugin_fb_load (void);
+void hybris_plugin_fb_unload (void);
+
+static int hybris_plugin_fb_open_device (struct framebuffer_device_t **pdevice);
+static void hybris_plugin_fb_close_device (struct framebuffer_device_t **pdevice);
+
+/* ------------------------------------------------------------------------- *
+ * FRAMEBUFFER_DEVICE
+ * ------------------------------------------------------------------------- */
+
+bool hybris_device_fb_init (void);
+void hybris_device_fb_quit (void);
+bool hybris_device_fb_set_power (bool state);
+
+/* ========================================================================= *
+ * FRAMEBUFFER_PLUGIN
+ * ========================================================================= */
+
+/** Handle for libhybris framebuffer plugin */
+static const struct hw_module_t *hybris_plugin_fb_handle = 0;
+
+/** Load libhybris framebuffer plugin
+ *
+ * @return true on success, false on failure
+ */
+bool
+hybris_plugin_fb_load(void)
+{
+ static bool done = false;
+
+ if( done ) {
+ goto cleanup;
+ }
+
+ done = true;
+
+ hw_get_module(GRALLOC_HARDWARE_FB0, &hybris_plugin_fb_handle);
+
+ if( !hybris_plugin_fb_handle ) {
+ mce_log(LL_WARN, "failed to open frame buffer module");
+ goto cleanup;
+ }
+
+ mce_log(LL_DEBUG, "hybris_plugin_fb_handle = %p",
+ hybris_plugin_fb_handle);
+
+cleanup:
+
+ return hybris_plugin_fb_handle != 0;
+}
+
+/** Unload libhybris framebuffer plugin
+ */
+void
+hybris_plugin_fb_unload(void)
+{
+ /* Close devices related to the plugin */
+ hybris_device_fb_quit();
+
+ /* actually unload the module */
+ // FIXME: how to unload libhybris modules?
+}
+
+/** Convenience function for opening frame buffer device
+ *
+ * Similar to what we might or might not have available from hardware/fb.h
+ */
+static int
+hybris_plugin_fb_open_device(struct framebuffer_device_t ** pdevice)
+{
+ int ack = false;
+
+ if( !hybris_plugin_fb_load() ) {
+ goto cleanup;
+ }
+
+ const struct hw_module_t *mod = hybris_plugin_fb_handle;
+ const char *id = GRALLOC_HARDWARE_FB0;
+ struct hw_device_t *dev = 0;
+
+ if( !mod->methods->open(mod, id, &dev) ) {
+ goto cleanup;
+ }
+
+ *pdevice = (struct framebuffer_device_t*)dev;
+
+ ack = true;
+
+cleanup:
+
+ return ack;
+}
+
+/** Convenience function for closing frame buffer device
+ *
+ * Similar to what we might or might not have available from hardware/fb.h
+ */
+static void
+hybris_plugin_fb_close_device(struct framebuffer_device_t **pdevice)
+{
+ struct framebuffer_device_t *device;
+
+ if( (device = *pdevice) ) {
+ *pdevice = 0, device->common.close(&device->common);
+ }
+}
+
+/* ========================================================================= *
+ * FRAMEBUFFER_DEVICE
+ * ========================================================================= */
+
+/** Pointer to libhybris frame buffer device object */
+static struct framebuffer_device_t *hybris_device_fb_handle = 0;
+
+/** Initialize libhybris frame buffer device object
+ *
+ * @return true on success, false on failure
+ */
+bool
+hybris_device_fb_init(void)
+{
+ static bool done = false;
+
+ if( done ) {
+ goto cleanup;
+ }
+
+ done = true;
+
+ hybris_plugin_fb_open_device(&hybris_device_fb_handle);
+
+ if( !hybris_device_fb_handle ) {
+ mce_log(LL_ERR, "failed to open framebuffer device");
+ goto cleanup;
+ }
+
+ mce_log(LL_DEBUG, "hybris_device_fb_handle = %p",
+ hybris_device_fb_handle);
+
+cleanup:
+
+ return hybris_device_fb_handle != 0;
+}
+
+/** Release libhybris frame buffer device object
+ */
+void
+hybris_device_fb_quit(void)
+{
+ hybris_plugin_fb_close_device(&hybris_device_fb_handle);
+}
+
+/** Set frame buffer power state via libhybris
+ *
+ * @param state true to power on, false to power off
+ *
+ * @return true on success, false on failure
+ */
+bool
+hybris_device_fb_set_power(bool state)
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/hybris-fb.h
^
|
@@ -0,0 +1,36 @@
+/** @file hybris-fb.h
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2013-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 HYBRIS_FB_H_
+# define HYBRIS_FB_H_
+
+# include <stdbool.h>
+
+bool hybris_plugin_fb_load (void);
+void hybris_plugin_fb_unload (void);
+
+bool hybris_device_fb_init (void);
+void hybris_device_fb_quit (void);
+bool hybris_device_fb_set_power (bool state);
+
+#endif /* HYBRIS_FB_H_ */
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/hybris-lights.c
^
|
@@ -0,0 +1,466 @@
+/** @file hybris-lights.c
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2013-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 "hybris-lights.h"
+#include "plugin-logging.h"
+
+#include "plugin-api.h"
+
+#include <system/window.h>
+#include <hardware/lights.h>
+
+/* ========================================================================= *
+ * PROTOTYPES
+ * ========================================================================= */
+
+/* ------------------------------------------------------------------------- *
+ * UTILITIES
+ * ------------------------------------------------------------------------- */
+
+static int clamp_to_range (int lo, int hi, int val);
+
+/* ------------------------------------------------------------------------- *
+ * LIGHTS_PLUGIN
+ * ------------------------------------------------------------------------- */
+
+bool hybris_plugin_lights_load (void);
+void hybris_plugin_lights_unload (void);
+
+static int hybris_plugin_lights_open_device (const char *id, struct light_device_t **pdevice);
+static void hybris_plugin_lights_close_device (struct light_device_t **pdevice);
+
+/* ------------------------------------------------------------------------- *
+ * DISPLAY_BACKLIGHT
+ * ------------------------------------------------------------------------- */
+
+bool hybris_device_backlight_init (void);
+void hybris_device_backlight_quit (void);
+bool hybris_device_backlight_set_brightness(int level);
+
+/* ------------------------------------------------------------------------- *
+ * KEYBOARD_BACKLIGHT
+ * ------------------------------------------------------------------------- */
+
+bool hybris_device_keypad_init (void);
+void hybris_device_keypad_quit (void);
+bool hybris_device_keypad_set_brightness (int level);
+
+/* ------------------------------------------------------------------------- *
+ * INDICATOR_LED
+ * ------------------------------------------------------------------------- */
+
+bool hybris_device_indicator_init (void);
+void hybris_device_indicator_quit (void);
+bool hybris_device_indicator_set_pattern (int r, int g, int b, int ms_on, int ms_off);
+
+/* ========================================================================= *
+ * UTILITIES
+ * ========================================================================= */
+
+/** Clamp integer values to given range
+ *
+ * @param lo minimum value allowed
+ * @param hi maximum value allowed
+ * @param val value to clamp
+ *
+ * @return val clamped to [lo, hi]
+ */
+static int
+clamp_to_range(int lo, int hi, int val)
+{
+ return val <= lo ? lo : val <= hi ? val : hi;
+}
+
+/* ========================================================================= *
+ * LIGHTS_PLUGIN
+ * ========================================================================= */
+
+/** Handle for libhybris lights plugin */
+static const struct hw_module_t *hybris_plugin_lights_handle = 0;
+
+/** Load libhybris lights plugin
+ *
+ * @return true on success, false on failure
+ */
+bool
+hybris_plugin_lights_load(void)
+{
+ static bool done = false;
+
+ if( done ) {
+ goto cleanup;
+ }
+
+ done = true;
+
+ hw_get_module(LIGHTS_HARDWARE_MODULE_ID, &hybris_plugin_lights_handle);
+ if( !hybris_plugin_lights_handle ) {
+ mce_log(LL_WARN, "failed to open lights module");
+ goto cleanup;
+ }
+
+ mce_log(LL_DEBUG, "hybris_plugin_lights_handle = %p",
+ hybris_plugin_lights_handle);
+
+cleanup:
+
+ return hybris_plugin_lights_handle != 0;
+}
+
+/** Unload libhybris lights plugin
+ */
+void
+hybris_plugin_lights_unload(void)
+{
+ /* cleanup dependencies */
+ hybris_device_backlight_quit();
+ hybris_device_keypad_quit();
+ hybris_device_indicator_quit();
+
+ /* actually unload the module */
+ // FIXME: how to unload libhybris modules?
+}
+
+/** Convenience function for opening a light device
+ *
+ * Similar to what we might or might not have available from hardware/lights.h
+ */
+static int
+hybris_plugin_lights_open_device(const char *id, struct light_device_t **pdevice)
+{
+ int ack = false;
+
+ if( !id || !pdevice ) {
+ goto cleanup;
+ }
+
+ if( !hybris_plugin_lights_load() ) {
+ goto cleanup;
+ }
+
+ const struct hw_module_t *module = hybris_plugin_lights_handle;
+
+ if( !module->methods->open(module, id, (struct hw_device_t**)pdevice) ) {
+ goto cleanup;
+ }
+
+ ack = true;
+
+cleanup:
+
+ return ack;
+}
+
+/** Convenience function for closing a light device
+ *
+ * Similar to what we might or might not have available from hardware/lights.h
+ */
+static void
+hybris_plugin_lights_close_device(struct light_device_t **pdevice)
+{
+ struct light_device_t *device;
+
+ if( (device = *pdevice) ) {
+ *pdevice = 0, device->common.close(&device->common);
+ }
+}
+
+/* ========================================================================= *
+ * DISPLAY_BACKLIGHT
+ * ========================================================================= */
+
+/** Pointer to libhybris frame display backlight device object */
+static struct light_device_t *hybris_device_backlight_handle = 0;
+
+/** Initialize libhybris display backlight device object
+ *
+ * @return true on success, false on failure
+ */
+bool
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/hybris-lights.h
^
|
@@ -0,0 +1,44 @@
+/** @file hybris-lights.h
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2013-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 HYBRIS_LIGHTS_H_
+# define HYBRIS_LIGHTS_H_
+
+# include <stdbool.h>
+
+bool hybris_plugin_lights_load (void);
+void hybris_plugin_lights_unload (void);
+
+bool hybris_device_backlight_init (void);
+void hybris_device_backlight_quit (void);
+bool hybris_device_backlight_set_brightness (int level);
+
+bool hybris_device_keypad_init (void);
+void hybris_device_keypad_quit (void);
+bool hybris_device_keypad_set_brightness (int level);
+
+bool hybris_device_indicator_init (void);
+void hybris_device_indicator_quit (void);
+bool hybris_device_indicator_set_pattern (int r, int g, int b, int ms_on, int ms_off);
+
+#endif /* HYBRIS_LIGHTS_H_ */
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/hybris-sensors.c
^
|
@@ -0,0 +1,497 @@
+/** @file hybris-sensors.c
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2013-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 "hybris-sensors.h"
+#include "plugin-logging.h"
+#include "hybris-thread.h"
+
+#include <hardware/sensors.h>
+
+#include <glib.h>
+
+/* ========================================================================= *
+ * PROTOTYPES
+ * ========================================================================= */
+
+/* ------------------------------------------------------------------------- *
+ * SENSORS_PLUGIN
+ * ------------------------------------------------------------------------- */
+
+static const struct sensor_t *hybris_plugin_sensors_get_sensor (int type);
+
+bool hybris_plugin_sensors_load (void);
+void hybris_plugin_sensors_unload (void);
+
+static bool hybris_plugin_sensors_open_device (struct sensors_poll_device_t **pdevice);
+static void hybris_plugin_sensors_close_device (struct sensors_poll_device_t **pdevice);
+
+/* ------------------------------------------------------------------------- *
+ * SENSORS_DEVICE
+ * ------------------------------------------------------------------------- */
+
+static void hybris_device_sensors_thread_cb (void *aptr);
+
+static bool hybris_device_sensors_init (void);
+static void hybris_device_sensors_quit (void);
+
+/* ------------------------------------------------------------------------- *
+ * PROXIMITY_SENSOR
+ * ------------------------------------------------------------------------- */
+
+bool hybris_sensor_ps_init (void);
+void hybris_sensor_ps_quit (void);
+void hybris_sensor_ps_set_hook (mce_hybris_ps_fn cb);
+bool hybris_sensor_ps_set_active (bool state);
+
+/* ------------------------------------------------------------------------- *
+ * AMBIENT_LIGHT_SENSOR
+ * ------------------------------------------------------------------------- */
+
+bool hybris_device_als_init (void);
+void hybris_device_als_quit (void);
+void hybris_device_als_set_hook (mce_hybris_als_fn cb);
+bool hybris_device_als_set_active (bool state);
+
+/* ========================================================================= *
+ * SENSORS_PLUGIN
+ * ========================================================================= */
+
+/** Handle for libhybris sensors plugin */
+static struct sensors_module_t *hybris_plugin_sensors_handle = 0;
+
+/** Array of sensors available via hybris_plugin_sensors_handle */
+static const struct sensor_t *hybris_plugin_sensors_lut = 0;
+
+/** Number of sensors available via hybris_plugin_sensors_handle */
+static int hybris_plugin_sensors_cnt = 0;
+
+/** Pointer to libhybris proximity sensor object */
+static const struct sensor_t *hybris_plugin_sensors_ps_sensor = 0;
+
+/** Pointer to libhybris ambient light sensor object */
+static const struct sensor_t *hybris_plugin_sensors_als_sensor = 0;
+
+/** Helper for locating sensor objects by type
+ *
+ * @param type SENSOR_TYPE_LIGHT etc
+ *
+ * @return sensor pointer, or NULL if not available
+ */
+static const struct sensor_t *
+hybris_plugin_sensors_get_sensor(int type)
+{
+ const struct sensor_t *res = 0;
+
+ for( int i = 0; i < hybris_plugin_sensors_cnt; ++i ) {
+
+ if( hybris_plugin_sensors_lut[i].type == type ) {
+ res = &hybris_plugin_sensors_lut[i];
+ break;
+ }
+ }
+
+ return res;
+}
+
+/** Load libhybris sensors plugin
+ *
+ * Also initializes look up table for supported sensors.
+ *
+ * @return true on success, false on failure
+ */
+bool
+hybris_plugin_sensors_load(void)
+{
+ static bool done = false;
+
+ if( done ) {
+ goto cleanup;
+ }
+
+ done = true;
+
+ {
+ const struct hw_module_t *mod = 0;
+ hw_get_module(SENSORS_HARDWARE_MODULE_ID, &mod);
+ hybris_plugin_sensors_handle = (struct sensors_module_t *)mod;
+ }
+
+ if( !hybris_plugin_sensors_handle ) {
+ mce_log(LL_WARN, "failed top open sensors module");
+ }
+ else {
+ mce_log(LL_DEBUG, "hybris_plugin_sensors_handle = %p",
+ hybris_plugin_sensors_handle);
+ }
+
+ if( !hybris_plugin_sensors_handle ) {
+ goto cleanup;
+ }
+
+ hybris_plugin_sensors_cnt = hybris_plugin_sensors_handle->get_sensors_list(hybris_plugin_sensors_handle,
+ &hybris_plugin_sensors_lut);
+
+ hybris_plugin_sensors_als_sensor = hybris_plugin_sensors_get_sensor(SENSOR_TYPE_LIGHT);
+ hybris_plugin_sensors_ps_sensor = hybris_plugin_sensors_get_sensor(SENSOR_TYPE_PROXIMITY);
+
+cleanup:
+
+ return hybris_plugin_sensors_handle != 0;
+}
+
+/** Unload libhybris sensors plugin
+ */
+void
+hybris_plugin_sensors_unload(void)
+{
+ /* cleanup dependencies */
+ hybris_device_sensors_quit();
+
+ /* actually unload the module */
+ // FIXME: how to unload libhybris modules?
+}
+
+/** Convenience function for opening sensors device
+ *
+ * Similar to what we might or might not have available from hardware/sensors.h
+ */
+static bool
+hybris_plugin_sensors_open_device(struct sensors_poll_device_t **pdevice)
+{
+ bool ack = false;
+
+ if( !hybris_plugin_sensors_load() ) {
+ goto cleanup;
+ }
+
+ const struct hw_module_t *mod = &hybris_plugin_sensors_handle->common;
+ const char *id = SENSORS_HARDWARE_POLL;
+ struct hw_device_t *dev = 0;
+
+ if( !mod->methods->open(mod, id, &dev) ) {
+ goto cleanup;
+ }
+
+ *pdevice = (struct sensors_poll_device_t *)dev;
+
+ ack = true;
+
+cleanup:
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/hybris-sensors.h
^
|
@@ -0,0 +1,42 @@
+/** @file hybris-sensors.h
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2013-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 HYBRIS_SENSORS_H_
+# define HYBRIS_SENSORS_H_
+
+# include "plugin-api.h"
+
+bool hybris_plugin_sensors_load (void);
+void hybris_plugin_sensors_unload (void);
+
+bool hybris_sensor_ps_init (void);
+void hybris_sensor_ps_quit (void);
+bool hybris_sensor_ps_set_active (bool state);
+void hybris_sensor_ps_set_hook (mce_hybris_ps_fn cb);
+
+bool hybris_device_als_init (void);
+void hybris_device_als_quit (void);
+bool hybris_device_als_set_active (bool state);
+void hybris_device_als_set_hook (mce_hybris_als_fn cb);
+
+#endif /* HYBRIS_SENSORS_H_ */
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/hybris-thread.c
^
|
@@ -0,0 +1,217 @@
+/** @file hybris-thread.c
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2013-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 "hybris-thread.h"
+#include "plugin-logging.h"
+
+#include <stdlib.h>
+
+/* ========================================================================= *
+ * PROTOTYPES
+ * ========================================================================= */
+
+/* ------------------------------------------------------------------------- *
+ * THREAD_GATE
+ * ------------------------------------------------------------------------- */
+
+/** Thread start details; used for inserting custom thread setup code
+ */
+typedef struct
+{
+ /** Function to call from initialized thread */
+ void (*func)(void *);
+
+ /** Parameter to pass to the thread function */
+ void *data;
+} thread_gate_t;
+
+static void *thread_gate_start_cb (void *aptr);
+
+static thread_gate_t *thread_gate_create (void (*func)(void *), void *data);
+static void thread_gate_delete (thread_gate_t *self);
+
+/* ------------------------------------------------------------------------- *
+ * GENERIC
+ * ------------------------------------------------------------------------- */
+
+pthread_t hybris_thread_start (void (*start)(void *), void *arg);
+void hybris_thread_stop (pthread_t tid);
+
+/* ========================================================================= *
+ * DATA
+ * ========================================================================= */
+
+/** Mutex used for synchronous worker thread startup */
+static pthread_mutex_t hybris_thread_gate_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+/** Condition used for signaling worker thread startup */
+static pthread_cond_t hybris_thread_gate_cond = PTHREAD_COND_INITIALIZER;
+
+/* ========================================================================= *
+ * THREAD_GATE
+ * ========================================================================= */
+
+/** Wrapper for starting new worker thread
+ *
+ * For use from hybris_thread_start().
+ *
+ * Before the actual thread start routine is called, the
+ * new thread is put in to asynchronously cancellabe state
+ * and the starter is woken up via condition.
+ *
+ * @param aptr wrapper data as void pointer
+ *
+ * @return 0 on thread exit - via pthread_join()
+ */
+static void *
+thread_gate_start_cb(void *aptr)
+{
+ thread_gate_t *gate = aptr;
+
+ void (*func)(void*);
+ void *data;
+
+ /* Allow quick and dirty cancellation */
+ pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0);
+ pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0);
+
+ /* Tell thread gate we're up and running */
+ pthread_mutex_lock(&hybris_thread_gate_mutex);
+ pthread_cond_broadcast(&hybris_thread_gate_cond);
+ pthread_mutex_unlock(&hybris_thread_gate_mutex);
+
+ /* Collect data we need, release rest */
+ func = gate->func;
+ data = gate->data;
+
+ thread_gate_delete(gate),gate = 0;
+
+ /* Call the real thread start */
+ func(data);
+
+ return 0;
+}
+
+/** Construct a thread gate object
+ *
+ * @param func Thread function
+ * @param data Data to pass to the thread function
+ *
+ * @return gate object, or NULL
+ */
+static thread_gate_t *
+thread_gate_create(void (*func)(void *), void *data)
+{
+ thread_gate_t *self = calloc(1, sizeof *self);
+
+ if( self ) {
+ self->func = func;
+ self->data = data;
+ }
+
+ return self;
+}
+
+/** Destroy a thread gate object
+ *
+ * @param self Gate object, or NULL
+ */
+static void
+thread_gate_delete(thread_gate_t *self)
+{
+ if( self ) {
+ free(self);
+ }
+}
+
+/* ========================================================================= *
+ * GENERIC
+ * ========================================================================= */
+
+/** Helper for starting new worker thread
+ *
+ * @param start function to call from new thread
+ * @param arg data to pass to start function
+ *
+ * @return thread id on success, or 0 on error
+ */
+pthread_t
+hybris_thread_start(void (*start)(void *), void* arg)
+{
+ pthread_t tid = 0;
+ thread_gate_t *gate = 0;
+
+ if( !(gate = thread_gate_create(start, arg)) ) {
+ goto EXIT;
+ }
+
+ pthread_mutex_lock(&hybris_thread_gate_mutex);
+
+ if( pthread_create(&tid, 0, thread_gate_start_cb, gate) != 0 ) {
+ mce_log(LL_ERR, "could not start worker thread");
+
+ /* content of tid is undefined on failure, force to zero */
+ tid = 0;
+ }
+ else {
+ /* wait until thread has had time to start and set
+ * up the cancellation parameters */
+ mce_log(LL_DEBUG, "waiting worker to start ...");
+ pthread_cond_wait(&hybris_thread_gate_cond, &hybris_thread_gate_mutex);
+ mce_log(LL_DEBUG, "worker started");
+
+ /* the thread owns the gate now */
+ gate = 0;
+ }
+
+ pthread_mutex_unlock(&hybris_thread_gate_mutex);
+
+EXIT:
+
+ thread_gate_delete(gate);
+
+ return tid;
+}
+
+/** Helper for terminating worker thread
+ *
+ * @param tid Thread id from hybris_thread_start()
+ */
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/hybris-thread.h
^
|
@@ -0,0 +1,32 @@
+/** @file hybris-thread.h
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2013-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 HYBRIS_THREAD_H_
+# define HYBRIS_THREAD_H_
+
+# include <pthread.h>
+
+pthread_t hybris_thread_start (void (*start)(void *), void* arg);
+void hybris_thread_stop (pthread_t tid);
+
+#endif /* HYBRIS_THREAD_H_ */
|
[-]
[+]
|
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-api.c
^
|
@@ -0,0 +1,512 @@
+/** @file plugin-api.c
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2013-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
+ */
+
+/* ========================================================================= *
+ * This module implements "mce-libhybris-plugin" for use from
+ * "mce-libhybris-module" within mce.
+ *
+ * The idea of "hybris-plugin" is shortly:
+ * - it uses no mce functions or data types
+ * - it can be compiled independently from mce
+ * - it exposes no libhybris/android datatypes / functions
+ *
+ * And the idea of "hybris-module" is:
+ * - it contains functions with the same names as "hybris-plugin"
+ * - if called, the functions will load & call "hybris-plugin" code
+ * - if "hybris-plugin" is not present "hybris-module" functions
+ * still work, but return failures for everything
+ *
+ * Put together:
+ * - mce code can assume that libhybris code is always available and
+ * callable during hw probing activity
+ * - if hybris plugin is not installed (or if some hw is not supported
+ * by the underlying android code), failures will be reported and mce
+ * can try other existing ways to proble hw controls
+ * ========================================================================= */
+
+#include "plugin-api.h"
+
+#include "plugin-logging.h"
+#include "hybris-fb.h"
+#include "hybris-lights.h"
+#include "hybris-sensors.h"
+
+#include "sysfs-led-main.h"
+
+/* ========================================================================= *
+ * PROTOTYPES
+ * ========================================================================= */
+
+/* ------------------------------------------------------------------------- *
+ * FRAME_BUFFER_POWER_STATE
+ * ------------------------------------------------------------------------- */
+
+bool mce_hybris_framebuffer_init (void);
+void mce_hybris_framebuffer_quit (void);
+bool mce_hybris_framebuffer_set_power (bool state);
+
+/* ------------------------------------------------------------------------- *
+ * DISPLAY_BACKLIGHT_BRIGHTNESS
+ * ------------------------------------------------------------------------- */
+
+bool mce_hybris_backlight_init (void);
+void mce_hybris_backlight_quit (void);
+bool mce_hybris_backlight_set_brightness (int level);
+
+/* ------------------------------------------------------------------------- *
+ * KEYPAD_BACKLIGHT_BRIGHTNESS
+ * ------------------------------------------------------------------------- */
+
+bool mce_hybris_keypad_init (void);
+void mce_hybris_keypad_quit (void);
+bool mce_hybris_keypad_set_brightness (int level);
+
+/* ------------------------------------------------------------------------- *
+ * INDICATOR_LED_PATTERN
+ * ------------------------------------------------------------------------- */
+
+bool mce_hybris_indicator_init (void);
+void mce_hybris_indicator_quit (void);
+bool mce_hybris_indicator_set_pattern (int r, int g, int b, int ms_on, int ms_off);
+bool mce_hybris_indicator_can_breathe (void);
+void mce_hybris_indicator_enable_breathing(bool enable);
+bool mce_hybris_indicator_set_brightness (int level);
+
+/* ------------------------------------------------------------------------- *
+ * PROXIMITY_SENSOR
+ * ------------------------------------------------------------------------- */
+
+bool mce_hybris_ps_init (void);
+void mce_hybris_ps_quit (void);
+bool mce_hybris_ps_set_active (bool state);
+void mce_hybris_ps_set_hook (mce_hybris_ps_fn cb);
+
+/* ------------------------------------------------------------------------- *
+ * AMBIENT_LIGHT_SENSOR
+ * ------------------------------------------------------------------------- */
+
+bool mce_hybris_als_init (void);
+void mce_hybris_als_quit (void);
+bool mce_hybris_als_set_active (bool state);
+void mce_hybris_als_set_hook (mce_hybris_als_fn cb);
+
+/* ------------------------------------------------------------------------- *
+ * GENERIC
+ * ------------------------------------------------------------------------- */
+
+void mce_hybris_quit (void);
+
+/* ========================================================================= *
+ * FRAME_BUFFER_POWER_STATE
+ * ========================================================================= */
+
+/** Initialize libhybris frame buffer device object
+ *
+ * @return true on success, false on failure
+ */
+bool
+mce_hybris_framebuffer_init(void)
+{
+ return hybris_device_fb_init();
+}
+
+/** Release libhybris frame buffer device object
+ */
+void
+mce_hybris_framebuffer_quit(void)
+{
+ hybris_device_fb_quit();
+}
+
+/** Set frame buffer power state via libhybris
+ *
+ * @param state true to power on, false to power off
+ *
+ * @return true on success, false on failure
+ */
+bool
+mce_hybris_framebuffer_set_power(bool state)
+{
+ return hybris_device_fb_set_power(state);
+}
+
+/* ========================================================================= *
+ * DISPLAY_BACKLIGHT_BRIGHTNESS
+ * ========================================================================= */
+
+/** Initialize libhybris display backlight device object
+ *
+ * @return true on success, false on failure
+ */
+bool
+mce_hybris_backlight_init(void)
+{
+ return hybris_device_backlight_init();
+}
+
+/** Release libhybris display backlight device object
+ */
+void
+mce_hybris_backlight_quit(void)
+{
+ hybris_device_backlight_quit();
+}
+
+/** Set display backlight brightness via libhybris
+ *
+ * @param level 0=off ... 255=maximum brightness
+ *
+ * @return true on success, false on failure
+ */
+bool
+mce_hybris_backlight_set_brightness(int level)
+{
+ return hybris_device_backlight_set_brightness(level);
+}
+
+/* ========================================================================= *
+ * KEYPAD_BACKLIGHT_BRIGHTNESS
+ * ========================================================================= */
+
+/** Initialize libhybris keypad backlight device object
+ *
+ * @return true on success, false on failure
+ */
+bool
+mce_hybris_keypad_init(void)
+{
+ return hybris_device_keypad_init();
+}
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/plugin-api.h
^
|
@@ -0,0 +1,131 @@
+/** @file plugin-api.h
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2013-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
+ */
+
+/* FIXME: This header is included in sourcetrees of both mce and
+ * mce-plugin-libhybris. For now it must be kept in sync
+ * manually.
+ */
+
+#ifndef MCE_HYBRIS_H_
+# define MCE_HYBRIS_H_
+
+# ifndef MCE_HYBRIS_INTERNAL
+# define MCE_HYBRIS_INTERNAL 0
+# endif
+
+# include <stdint.h>
+# include <stdbool.h>
+
+# ifdef __cplusplus
+extern "C" {
+# elif 0
+} /* fool JED indentation ... */
+# endif
+
+# pragma GCC visibility push(default)
+
+/* - - - - - - - - - - - - - - - - - - - *
+ * frame buffer power state
+ * - - - - - - - - - - - - - - - - - - - */
+
+bool mce_hybris_framebuffer_init(void);
+void mce_hybris_framebuffer_quit(void);
+bool mce_hybris_framebuffer_set_power(bool on);
+
+/* - - - - - - - - - - - - - - - - - - - *
+ * display backlight brightness
+ * - - - - - - - - - - - - - - - - - - - */
+
+bool mce_hybris_backlight_init(void);
+void mce_hybris_backlight_quit(void);
+bool mce_hybris_backlight_set_brightness(int level);
+
+/* - - - - - - - - - - - - - - - - - - - *
+ * keypad backlight brightness
+ * - - - - - - - - - - - - - - - - - - - */
+
+bool mce_hybris_keypad_set_brightness(int level);
+void mce_hybris_keypad_quit(void);
+bool mce_hybris_keypad_init(void);
+
+/* - - - - - - - - - - - - - - - - - - - *
+ * indicator led pattern
+ * - - - - - - - - - - - - - - - - - - - */
+
+bool mce_hybris_indicator_init(void);
+void mce_hybris_indicator_quit(void);
+bool mce_hybris_indicator_set_pattern(int r, int g, int b, int ms_on, int ms_off);
+void mce_hybris_indicator_enable_breathing(bool enable);
+bool mce_hybris_indicator_set_brightness(int level);
+bool mce_hybris_indicator_can_breathe(void);
+
+/* - - - - - - - - - - - - - - - - - - - *
+ * proximity sensor
+ * - - - - - - - - - - - - - - - - - - - */
+
+typedef void (*mce_hybris_ps_fn)(int64_t timestamp, float distance);
+
+bool mce_hybris_ps_init(void);
+void mce_hybris_ps_quit(void);
+bool mce_hybris_ps_set_active(bool active);
+bool mce_hybris_ps_set_callback(mce_hybris_ps_fn cb);
+
+/* - - - - - - - - - - - - - - - - - - - *
+ * ambient light sensor
+ * - - - - - - - - - - - - - - - - - - - */
+
+typedef void (*mce_hybris_als_fn)(int64_t timestamp, float light);
+
+bool mce_hybris_als_init(void);
+void mce_hybris_als_quit(void);
+bool mce_hybris_als_set_active(bool active);
+bool mce_hybris_als_set_callback(mce_hybris_als_fn cb);
+
+/* - - - - - - - - - - - - - - - - - - - *
+ * generic
+ * - - - - - - - - - - - - - - - - - - - */
+
+void mce_hybris_quit(void);
+
+/* - - - - - - - - - - - - - - - - - - - *
+ * internal to module <--> plugin
+ * - - - - - - - - - - - - - - - - - - - */
+
+# if MCE_HYBRIS_INTERNAL >= 1
+typedef void (*mce_hybris_log_fn)(int lev, const char *file, const char *func,
+ const char *text);
+# endif
+
+# if MCE_HYBRIS_INTERNAL >= 2
+void mce_hybris_set_log_hook(mce_hybris_log_fn cb);
+void mce_hybris_ps_set_hook(mce_hybris_ps_fn cb);
+void mce_hybris_als_set_hook(mce_hybris_als_fn cb);
+# endif
+
+# pragma GCC visibility pop
+
+# ifdef __cplusplus
+};
+# endif
+
+#endif /* MCE_HYBRIS_H_ */
|
[-]
[+]
|
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-logging.c
^
|
@@ -0,0 +1,88 @@
+/** @file plugin-logging.c
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2013-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-logging.h"
+
+#include "plugin-api.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+/* ========================================================================= *
+ * PROTOTYPES
+ * ========================================================================= */
+
+void mce_hybris_set_log_hook(mce_hybris_log_fn cb);
+void mce_hybris_log (int lev, const char *file, const char *func, const char *fmt, ...);
+
+/* ========================================================================= *
+ * DATA
+ * ========================================================================= */
+
+/** Callback function for diagnostic output, or NULL for stderr output */
+static mce_hybris_log_fn mce_hybris_log_cb = 0;
+
+/* ========================================================================= *
+ * FUNCTIONS
+ * ========================================================================= */
+
+/** Set diagnostic output forwarding callback
+ *
+ * @param cb The callback function to use, or NULL for stderr output
+ */
+void
+mce_hybris_set_log_hook(mce_hybris_log_fn cb)
+{
+ mce_hybris_log_cb = cb;
+}
+
+/** Wrapper for diagnostic logging
+ *
+ * @param lev syslog priority (=mce_log level) i.e. LL_ERR etc
+ * @param file source code path
+ * @param func name of function within file
+ * @param fmt printf compatible format string
+ * @param ... parameters required by the format string
+ */
+void
+mce_hybris_log(int lev, const char *file, const char *func,
+ const char *fmt, ...)
+{
+ char *msg = 0;
+ va_list va;
+
+ va_start(va, fmt);
+ if( vasprintf(&msg, fmt, va) < 0 ) msg = 0;
+ va_end(va);
+
+ if( msg ) {
+ if( mce_hybris_log_cb ) {
+ mce_hybris_log_cb(lev, file, func, msg);
+ }
+ else {
+ fprintf(stderr, "%s: %s: %s\n", file, func, msg);
+ }
+ free(msg);
+ }
+}
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/plugin-logging.h
^
|
@@ -0,0 +1,48 @@
+/** @file plugin-logging.h
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2013-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_LOGGING_H_
+# define PLUGIN_LOGGING_H_
+
+# include <syslog.h>
+
+/** MCE logging priorities
+ */
+enum
+{
+ LL_CRIT = LOG_CRIT, /**< Critical error */
+ LL_ERR = LOG_ERR, /**< Error */
+ LL_WARN = LOG_WARNING, /**< Warning */
+ LL_NOTICE = LOG_NOTICE, /**< Normal but noteworthy */
+ LL_INFO = LOG_INFO, /**< Informational message */
+ LL_DEBUG = LOG_DEBUG, /**< Useful when debugging */
+};
+
+void mce_hybris_log(int lev, const char *file, const char *func,
+ const char *fmt, ...) __attribute__ ((format (printf, 4, 5)));
+
+/** Logging from hybris plugin mimics mce-log.h API */
+# define mce_log(LEV,FMT,ARGS...) \
+ mce_hybris_log(LEV, __FILE__, __FUNCTION__ ,FMT, ## ARGS)
+
+#endif /* PLUGIN_LOGGING_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_ */
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/sysfs-led-bacon.c
^
|
@@ -0,0 +1,365 @@
+/** @file sysfs-led-bacon.c
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2017 Jolla Ltd.
+ * <p>
+ * @Author Willem-Jan de Hoog <wdehoog@exalondelft.nl>
+ * @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
+ */
+
+/* ========================================================================= *
+ * RGB led control: bacon backend
+ *
+ * Three channels, all of which:
+ * - must have 'brightness' control file
+ * - must have 'grpfreq', 'grppwm' and 'blink' to blink delay control file
+ * - must have 'reset' control file
+ *
+ * Based on code from device/oneplus/bacon/liblight/lights.c
+ * ========================================================================= */
+
+#include "sysfs-led-bacon.h"
+
+#include "sysfs-led-util.h"
+#include "plugin-logging.h"
+#include "plugin-config.h"
+
+#include <stdio.h>
+#include <string.h>
+
+#include <glib.h>
+
+/* ========================================================================= *
+ * PROTOTYPES
+ * ========================================================================= */
+
+typedef struct
+{
+ const char *brightness;
+ const char *grpfreq;
+ const char *grppwm;
+ const char *blink;
+ const char *ledreset;
+} led_paths_bacon_t;
+
+typedef struct
+{
+ int fd_brightness;
+ int fd_grpfreq;
+ int fd_grppwm;
+ int fd_blink;
+ int fd_ledreset;
+
+ int brightness;
+ int freq;
+ int pwm;
+ int blink;
+ int maxval;
+} led_channel_bacon_t;
+
+/* ------------------------------------------------------------------------- *
+ * ONE_CHANNEL
+ * ------------------------------------------------------------------------- */
+
+static void led_channel_bacon_init (led_channel_bacon_t *self);
+static void led_channel_bacon_close (led_channel_bacon_t *self);
+static bool led_channel_bacon_probe (led_channel_bacon_t *self, const led_paths_bacon_t *path);
+
+/* ------------------------------------------------------------------------- *
+ * ALL_CHANNELS
+ * ------------------------------------------------------------------------- */
+
+static void led_control_bacon_enable_cb (void *data, bool enable);
+static void led_control_bacon_blink_cb (void *data, int on_ms, int off_ms);
+static void led_control_bacon_value_cb (void *data, int r, int g, int b);
+static void led_control_bacon_close_cb (void *data);
+
+bool led_control_bacon_probe (led_control_t *self);
+
+/* ========================================================================= *
+ * ONE_CHANNEL
+ * ========================================================================= */
+
+static void
+led_channel_bacon_init(led_channel_bacon_t *self)
+{
+ self->fd_brightness = -1;
+ self->fd_grpfreq = -1;
+ self->fd_grppwm = -1;
+ self->fd_blink = -1;
+ self->fd_ledreset = -1;
+
+ self->blink = 0;
+ self->maxval = 255; // load from max_brightness?
+}
+
+static void
+led_channel_bacon_close(led_channel_bacon_t *self)
+{
+ led_util_close_file(&self->fd_brightness);
+ led_util_close_file(&self->fd_grpfreq);
+ led_util_close_file(&self->fd_grppwm);
+ led_util_close_file(&self->fd_blink);
+ led_util_close_file(&self->fd_ledreset);
+}
+
+static bool
+led_channel_bacon_probe(led_channel_bacon_t *self,
+ const led_paths_bacon_t *path)
+{
+ bool res = false;
+
+ led_channel_bacon_close(self);
+
+ if( !led_util_open_file(&self->fd_brightness, path->brightness) ||
+ !led_util_open_file(&self->fd_grpfreq, path->grpfreq) ||
+ !led_util_open_file(&self->fd_grppwm, path->grppwm) ||
+ !led_util_open_file(&self->fd_blink, path->blink) ||
+ !led_util_open_file(&self->fd_ledreset, path->ledreset))
+ {
+ goto cleanup;
+ }
+
+ res = true;
+
+cleanup:
+
+ if( !res ) led_channel_bacon_close(self);
+
+ return res;
+}
+
+/* ========================================================================= *
+ * ALL_CHANNELS
+ * ========================================================================= */
+
+#define BACON_CHANNELS 3
+
+static void
+led_control_bacon_enable_cb(void *data, bool enable)
+{
+ const led_channel_bacon_t *channel = data;
+ mce_log(LL_INFO, "led_control_bacon_enable_cb(%d)", enable);
+
+ if(!enable)
+ dprintf(channel->fd_ledreset, "%d", 1);
+}
+
+static void
+led_control_bacon_blink_cb(void *data, int on_ms, int off_ms)
+{
+ led_channel_bacon_t *channel = data;
+ mce_log(LL_INFO, "led_control_bacon_blink_cb(%d,%d)", on_ms, off_ms);
+
+ if( on_ms > 0 && off_ms > 0 ) {
+ int totalMS = on_ms + off_ms;
+
+ // the LED appears to blink about once per second if freq is 20
+ // 1000ms / 20 = 50
+ channel->freq = totalMS / 50;
+
+ // pwm specifies the ratio of ON versus OFF
+ // pwm = 0 -> always off
+ // pwm = 255 => always on
+ channel->pwm = (on_ms * 255) / totalMS;
+
+ // the low 4 bits are ignored, so round up if necessary
+ if( channel->pwm > 0 && channel->pwm < 16 )
+ channel->pwm = 16;
+
+ channel->blink = 1;
+ } else {
+ channel->blink = 0;
+ channel->freq = 0;
+ channel->pwm = 0;
+ }
+
+ if( channel->blink ) {
+ dprintf(channel->fd_grpfreq, "%d", channel->freq);
+ dprintf(channel->fd_grppwm, "%d", channel->pwm);
+ }
+ dprintf(channel->fd_blink, "%d", channel->blink);
+}
+
+static void
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/sysfs-led-bacon.h
^
|
@@ -0,0 +1,31 @@
+/** @file sysfs-led-bacon.h
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2013-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_BACON_H_
+# define SYSFS_LED_BACON_H_
+
+# include "sysfs-led-main.h"
+
+bool led_control_bacon_probe(led_control_t *self);
+
+#endif /* SYSFS_LED_BACON_H_ */
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/sysfs-led-binary.c
^
|
@@ -0,0 +1,268 @@
+/** @file sysfs-led-binary.c
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2013-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
+ */
+
+/* ========================================================================= *
+ * Binary led control: Jolla C backend
+ *
+ * One channel, which:
+ * - must have 'brightness' control file
+ *
+ * Assumptions built into code:
+ * - Using zero brightness disables led, any non-zero value enables it -> If
+ * mce requests "black" rgb value, use brightness of zero - otherwise 255.
+ * ========================================================================= */
+
+#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>
+
+/* ========================================================================= *
+ * PROTOTYPES
+ * ========================================================================= */
+
+typedef struct
+{
+ const char *brightness;
+ const char *max_brightness;
+} led_paths_binary_t;
+
+typedef struct
+{
+ sysfsval_t *cached_max_brightness;
+ sysfsval_t *cached_brightness;
+} led_channel_binary_t;
+
+/* ------------------------------------------------------------------------- *
+ * ONE_CHANNEL
+ * ------------------------------------------------------------------------- */
+
+static void led_channel_binary_init (led_channel_binary_t *self);
+static void led_channel_binary_close (led_channel_binary_t *self);
+static bool led_channel_binary_probe (led_channel_binary_t *self, const led_paths_binary_t *path);
+static void led_channel_binary_set_value (led_channel_binary_t *self, int value);
+
+/* ------------------------------------------------------------------------- *
+ * ALL_CHANNELS
+ * ------------------------------------------------------------------------- */
+
+static void led_control_binary_map_color (int r, int g, int b, int *mono);
+static void led_control_binary_value_cb (void *data, int r, int g, int b);
+static void led_control_binary_close_cb (void *data);
+
+bool led_control_binary_probe (led_control_t *self);
+
+/* ========================================================================= *
+ * ONE_CHANNEL
+ * ========================================================================= */
+
+static void
+led_channel_binary_init(led_channel_binary_t *self)
+{
+ self->cached_max_brightness = sysfsval_create();
+ self->cached_brightness = sysfsval_create();
+}
+
+static void
+led_channel_binary_close(led_channel_binary_t *self)
+{
+ 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;
+
+ 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:
+
+ /* 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;
+}
+
+static void
+led_channel_binary_set_value(led_channel_binary_t *self, int value)
+{
+ 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;
+}
+
+static void
+led_control_binary_value_cb(void *data, int r, int g, int b)
+{
+ 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);
+}
+
+static void
+led_control_binary_close_cb(void *data)
+{
+ led_channel_binary_t *channel = data;
+ led_channel_binary_close(channel + 0);
+}
+
+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[][BINARY_CHANNELS] =
+ {
+ // binary
+ {
+ {
+ .brightness = "/sys/class/leds/button-backlight/brightness",
+ },
+ },
+ };
+
+ bool ack = false;
+
+ for( size_t i = 0; i < G_N_ELEMENTS(paths); ++i ) {
+ if( (ack = led_channel_binary_probe(channel+0, &paths[i][0])) )
+ break;
+ }
+
+ return ack;
+}
+
+static bool
+led_control_binary_dynamic_probe(led_channel_binary_t *channel)
+{
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/sysfs-led-binary.h
^
|
@@ -0,0 +1,31 @@
+/** @file sysfs-led-binary.h
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2013-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_BINARY_H_
+# define SYSFS_LED_BINARY_H_
+
+# include "sysfs-led-main.h"
+
+bool led_control_binary_probe(led_control_t *self);
+
+#endif /* SYSFS_LED_BINARY_H_ */
|
[-]
[+]
|
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_ */
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/sysfs-led-hammerhead.c
^
|
@@ -0,0 +1,343 @@
+/** @file sysfs-led-hammerhead.c
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2013-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
+ */
+
+/* ========================================================================= *
+ * RGB led control: Hammerhead backend
+ *
+ * Three channels, all of which:
+ * - must have 'brightness' control file
+ * - must have 'max_brightness' control file
+ * - must have 'on_off_ms' blink delay control file
+ * - must have 'rgb_start' enable/disable control file
+ *
+ * Assumptions built into code:
+ * - Blinking is always soft, handled by kernel driver / hw.
+ * - The sysfs writes will block until change is finished -> Intensity
+ * changes are slow. Breathing from userspace can't be used as it
+ * would constantly block mce mainloop.
+ * ========================================================================= */
+
+#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>
+
+/* ========================================================================= *
+ * PROTOTYPES
+ * ========================================================================= */
+
+typedef struct
+{
+ const char *max_brightness;
+ const char *brightness;
+ const char *on_off_ms;
+ const char *rgb_start;
+} led_paths_hammerhead_t;
+
+typedef struct
+{
+ int cached_max_brightness;
+ int fd_brightness;
+ int fd_on_off_ms;
+ int fd_rgb_start;
+} led_channel_hammerhead_t;
+
+/* ------------------------------------------------------------------------- *
+ * ONE_CHANNEL
+ * ------------------------------------------------------------------------- */
+
+static void led_channel_hammerhead_init (led_channel_hammerhead_t *self);
+static void led_channel_hammerhead_close (led_channel_hammerhead_t *self);
+static bool led_channel_hammerhead_probe (led_channel_hammerhead_t *self, const led_paths_hammerhead_t *path);
+static void led_channel_hammerhead_set_enabled(const led_channel_hammerhead_t *self, bool enable);
+static void led_channel_hammerhead_set_value (const led_channel_hammerhead_t *self, int value);
+static void led_channel_hammerhead_set_blink (const led_channel_hammerhead_t *self, int on_ms, int off_ms);
+
+/* ------------------------------------------------------------------------- *
+ * ALL_CHANNELS
+ * ------------------------------------------------------------------------- */
+
+static void led_control_hammerhead_enable_cb (void *data, bool enable);
+static void led_control_hammerhead_blink_cb (void *data, int on_ms, int off_ms);
+static void led_control_hammerhead_value_cb (void *data, int r, int g, int b);
+static void led_control_hammerhead_close_cb (void *data);
+
+bool led_control_hammerhead_probe (led_control_t *self);
+
+/* ========================================================================= *
+ * ONE_CHANNEL
+ * ========================================================================= */
+
+static void
+led_channel_hammerhead_init(led_channel_hammerhead_t *self)
+{
+ 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_brightness);
+ led_util_close_file(&self->fd_on_off_ms);
+ led_util_close_file(&self->fd_rgb_start);
+}
+
+static bool
+led_channel_hammerhead_probe(led_channel_hammerhead_t *self,
+ const led_paths_hammerhead_t *path)
+{
+ bool res = false;
+
+ led_channel_hammerhead_close(self);
+
+ if( (self->cached_max_brightness = led_util_read_number(path->max_brightness)) <= 0 )
+ {
+ goto cleanup;
+ }
+
+ 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;
+ }
+
+ res = true;
+
+cleanup:
+
+ if( !res ) led_channel_hammerhead_close(self);
+
+ return res;
+}
+
+static void
+led_channel_hammerhead_set_enabled(const led_channel_hammerhead_t *self,
+ bool enable)
+{
+ if( self->fd_rgb_start != -1 )
+ {
+ dprintf(self->fd_rgb_start, "%d", enable);
+ }
+}
+
+static void
+led_channel_hammerhead_set_value(const led_channel_hammerhead_t *self,
+ int value)
+{
+ if( self->fd_brightness != -1 )
+ {
+ dprintf(self->fd_brightness, "%d", led_util_scale_value(value, self->cached_max_brightness));
+ }
+}
+
+static void
+led_channel_hammerhead_set_blink(const led_channel_hammerhead_t *self,
+ int on_ms, int off_ms)
+{
+ 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_ms, tmp, len) < 0 ) {
+ // dontcare, keep compiler from complaining too
+ }
+ }
+ }
+}
+
+/* ========================================================================= *
+ * ALL_CHANNELS
+ * ========================================================================= */
+
+#define HAMMERHEAD_CHANNELS 3
+
+static void
+led_control_hammerhead_enable_cb(void *data, bool enable)
+{
+ const led_channel_hammerhead_t *channel = data;
+ led_channel_hammerhead_set_enabled(channel + 0, enable);
+ led_channel_hammerhead_set_enabled(channel + 1, enable);
+ led_channel_hammerhead_set_enabled(channel + 2, enable);
+}
+
+static void
+led_control_hammerhead_blink_cb(void *data, int on_ms, int off_ms)
+{
+ const led_channel_hammerhead_t *channel = data;
+ led_channel_hammerhead_set_blink(channel + 0, on_ms, off_ms);
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/sysfs-led-hammerhead.h
^
|
@@ -0,0 +1,31 @@
+/** @file sysfs-led-hammerhead.h
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2013-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_HAMMERHEAD_H_
+# define SYSFS_LED_HAMMERHEAD_H_
+
+# include "sysfs-led-main.h"
+
+bool led_control_hammerhead_probe(led_control_t *self);
+
+#endif /* SYSFS_LED_HAMMERHEAD_H_ */
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/sysfs-led-htcvision.c
^
|
@@ -0,0 +1,336 @@
+/** @file sysfs-led-htcvision.c
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2013-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
+ */
+
+/* ========================================================================= *
+ * Amber/green led control: Htcvision backend
+ *
+ * Two channels (amber and green), both of which:
+ * - must have 'brightness' control file
+ * - must have 'max_brightness' control file
+ * - must have 'blink' enable/disable control file
+ *
+ * Assumptions built into code:
+ * - while there are two channels, kernel and/or hw only allows one of them
+ * to be active -> Map rgb form request from mce to amber/green and try
+ * to minimize color error.
+ * ========================================================================= */
+
+#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>
+
+/* ========================================================================= *
+ * PROTOTYPES
+ * ========================================================================= */
+
+typedef struct
+{
+ const char *max_brightness;
+ const char *brightness;
+ const char *blink;
+} led_paths_htcvision_t;
+
+typedef struct
+{
+ sysfsval_t * cached_max_brightness;
+ sysfsval_t * cached_brightness;
+ sysfsval_t * cached_blink;
+} led_channel_htcvision_t;
+
+/* ------------------------------------------------------------------------- *
+ * ONE_CHANNEL
+ * ------------------------------------------------------------------------- */
+
+static void led_channel_htcvision_init (led_channel_htcvision_t *self);
+static void led_channel_htcvision_close (led_channel_htcvision_t *self);
+static bool led_channel_htcvision_probe (led_channel_htcvision_t *self, const led_paths_htcvision_t *path);
+static void led_channel_htcvision_set_value (const led_channel_htcvision_t *self, int value);
+static void led_channel_htcvision_set_blink (const led_channel_htcvision_t *self, int blink);
+
+/* ------------------------------------------------------------------------- *
+ * ALL_CHANNELS
+ * ------------------------------------------------------------------------- */
+
+static void led_control_htcvision_map_color (int r, int g, int b, int *amber, int *green);
+static void led_control_htcvision_blink_cb (void *data, int on_ms, int off_ms);
+static void led_control_htcvision_value_cb (void *data, int r, int g, int b);
+static void led_control_htcvision_close_cb (void *data);
+
+bool led_control_htcvision_probe (led_control_t *self);
+
+/* ========================================================================= *
+ * ONE_CHANNEL
+ * ========================================================================= */
+
+static void
+led_channel_htcvision_init(led_channel_htcvision_t *self)
+{
+ 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)
+{
+ 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_htcvision_probe(led_channel_htcvision_t *self,
+ const led_paths_htcvision_t *path)
+{
+ bool res = false;
+
+ if( !sysfsval_open_rw(self->cached_blink, path->blink) )
+ goto cleanup;
+
+ 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:
+
+ /* 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;
+}
+
+static void
+led_channel_htcvision_set_value(const led_channel_htcvision_t *self,
+ int value)
+{
+ 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)
+{
+ 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)
+{
+ /* Only "amber" or "green" color can be used.
+ *
+ * Assume amber = r:ff g:7f b:00
+ * green = r:00 g:ff b:00
+ *
+ * Try to choose the one with smaller delta to the
+ * requested rgb color by using the 'r':'g' ratio.
+ *
+ * The 'b' is used for intensity preservation only.
+ */
+
+ if( r * 3 < g * 4)
+ {
+ *amber = 0;
+ *green = (g > b) ? g : b;
+ }
+ else
+ {
+ *amber = (r > b) ? r : b;
+ *green = 0;
+ }
+}
+
+static void
+led_control_htcvision_blink_cb(void *data, int on_ms, int off_ms)
+{
+ const led_channel_htcvision_t *channel = data;
+
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/sysfs-led-htcvision.h
^
|
@@ -0,0 +1,31 @@
+/** @file sysfs-led-htcvision.h
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2013-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_HTCVISION_H_
+# define SYSFS_LED_HTCVISION_H_
+
+# include "sysfs-led-main.h"
+
+bool led_control_htcvision_probe(led_control_t *self);
+
+#endif /* SYSFS_LED_HTCVISION_H_ */
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/sysfs-led-main.c
^
|
@@ -0,0 +1,941 @@
+/** @file sysfs-led-main.c
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2013-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-led-main.h"
+
+#include "sysfs-led-util.h"
+#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>
+
+#include <glib.h>
+
+/* ========================================================================= *
+ * CONSTANTS
+ * ========================================================================= */
+
+/** Questimate of the duration of the kernel delayed work */
+#define SYSFS_LED_KERNEL_DELAY 10 // [ms]
+
+/** Minimum delay between breathing steps */
+#define SYSFS_LED_STEP_DELAY 50 // [ms]
+
+/** Maximum number of breathing steps; rise and fall time combined */
+#define SYSFS_LED_MAX_STEPS 256
+
+/** Minimum number of breathing steps on rise/fall time */
+#define SYSFS_LED_MIN_STEPS 5
+
+/* ========================================================================= *
+ * PROTOTYPES
+ * ========================================================================= */
+
+/* ------------------------------------------------------------------------- *
+ * LED_CONTROL
+ *
+ * Frontend for controlling (assumed to be RGB) led via sysfs
+ * ------------------------------------------------------------------------- */
+
+static void led_control_enable (led_control_t *self, bool enable);
+static void led_control_blink (led_control_t *self, int on_ms, int off_ms);
+static void led_control_value (led_control_t *self, int r, int g, int b);
+static void led_control_init (led_control_t *self);
+
+static bool led_control_can_breathe (const led_control_t *self);
+static led_ramp_t led_control_breath_type (const led_control_t *self);
+
+static bool led_control_probe (led_control_t *self);
+void led_control_close (led_control_t *self);
+
+/* ------------------------------------------------------------------------- *
+ * LED_STATE
+ *
+ * Managing logical state of indicator led
+ * ------------------------------------------------------------------------- */
+
+/** Led state
+ */
+typedef struct
+{
+ int r,g,b; // color
+ int on,off; // blink timing
+ int level; // brightness [0 ... 255]
+ bool breathe; // breathe instead of blinking
+} led_state_t;
+
+/** Different styles of led patterns
+ */
+typedef enum
+{
+ STYLE_OFF, // led is off
+ STYLE_STATIC, // led has constant color
+ STYLE_BLINK, // led is blinking with on/off periods
+ STYLE_BREATH, // led is breathing with rise/fall times
+} led_style_t;
+
+static bool led_state_has_equal_timing (const led_state_t *self, const led_state_t *that);
+static bool led_state_is_equal (const led_state_t *self, const led_state_t *that);
+static bool led_state_has_color (const led_state_t *self);
+static void led_state_sanitize (led_state_t *self);
+static led_style_t led_state_get_style (const led_state_t *self);
+
+/* ------------------------------------------------------------------------- *
+ * SYSFS_LED
+ *
+ * Top level sysfs led functionality used by mce hybris plugin.
+ * ------------------------------------------------------------------------- */
+
+static void sysfs_led_close_files (void);
+static bool sysfs_led_probe_files (void);
+
+static void sysfs_led_set_rgb_blink (int on, int off);
+static void sysfs_led_set_rgb_value (int r, int g, int b);
+
+static void sysfs_led_generate_ramp_half_sin (int ms_on, int ms_off);
+static void sysfs_led_generate_ramp_hard_step (int ms_on, int ms_off);
+static void sysfs_led_generate_ramp_dummy (void);
+static void sysfs_led_generate_ramp (int ms_on, int ms_off);
+
+static gboolean sysfs_led_static_cb (gpointer aptr);
+static gboolean sysfs_led_step_cb (gpointer aptr);
+static gboolean sysfs_led_stop_cb (gpointer aptr);
+static void sysfs_led_start (const led_state_t *next);
+
+static void sysfs_led_wait_kernel (void);
+
+bool sysfs_led_init (void);
+void sysfs_led_quit (void);
+
+bool sysfs_led_set_pattern (int r, int g, int b, int ms_on, int ms_off);
+bool sysfs_led_can_breathe (void);
+void sysfs_led_set_breathing (bool enable);
+void sysfs_led_set_brightness (int level);
+
+/* ========================================================================= *
+ * LED_CONTROL
+ * ========================================================================= */
+
+/** Set RGB LED enabled/disable
+ *
+ * @param self control object
+ * @param enable true for enable, or false for disable
+ */
+static void
+led_control_enable(led_control_t *self, bool enable)
+{
+ if( self->enable )
+ {
+ self->enable(self->data, enable);
+ }
+}
+
+/** Set RGB LED blinking period
+ *
+ * If both on and off are greater than zero, then the PWM generator
+ * is used to full intensity blinking. Otherwise it is used for
+ * adjusting the LED brightness.
+ *
+ * @param self control object
+ * @param on milliseconds on
+ * @param off milliseconds off
+ */
+static void
+led_control_blink(led_control_t *self, int on_ms, int off_ms)
+{
+ if( self->blink )
+ {
+ led_control_enable(self, false);
+ self->blink(self->data, on_ms, off_ms);
+ }
+}
+
+/** Set RGB LED color
+ *
+ * @param self control object
+ * @param r red intensity (0 ... 255)
+ * @param g green intensity (0 ... 255)
+ * @param b blue intensity (0 ... 255)
+ */
+static void
+led_control_value(led_control_t *self, int r, int g, int b)
+{
+ if( self->value )
+ {
+ led_control_enable(self, false);
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/sysfs-led-main.h
^
|
@@ -0,0 +1,72 @@
+/** @file sysfs-led-main.h
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2013-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_MAIN_H_
+# define SYSFS_LED_MAIN_H_
+
+# include <stdbool.h>
+
+/* ------------------------------------------------------------------------- *
+ * LED_CONTROL - Common RGB LED control API
+ * ------------------------------------------------------------------------- */
+
+/** Brightness ramp type used for SW-breathing
+ */
+typedef enum {
+ /** Used when sw breathing is not used */
+ LED_RAMP_DISABLED = 0,
+
+ /** The default half sine curve */
+ LED_RAMP_HALF_SINE = 1,
+
+ /** Step function used for emulating blinking via sw breathing */
+ LED_RAMP_HARD_STEP = 2,
+} led_ramp_t;
+
+typedef struct led_control_t led_control_t;
+
+/** Led control backend
+ */
+struct led_control_t
+{
+ 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);
+ void (*value) (void *data, int r, int g, int b);
+ void (*close) (void *data);
+};
+
+bool sysfs_led_init (void);
+void sysfs_led_quit (void);
+bool sysfs_led_set_pattern (int r, int g, int b, int ms_on, int ms_off);
+bool sysfs_led_can_breathe (void);
+void sysfs_led_set_breathing (bool enable);
+void sysfs_led_set_brightness (int level);
+
+void led_control_close (led_control_t *self);
+
+#endif /* SYSFS_LED_MAIN_H_ */
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/sysfs-led-redgreen.c
^
|
@@ -0,0 +1,292 @@
+/** @file sysfs-led-redgreen.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
+ */
+
+/* ========================================================================= *
+ * Red + green led control
+ *
+ * Two channels (red and green), both of which:
+ * - must have 'brightness' control file
+ * - must have 'max_brightness' control file
+ *
+ * Notes:
+ * - despite having wide max_brightness range, the brightness control
+ * is binary: zero for off and any non-zero value for on.
+ * ========================================================================= */
+
+#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>
+
+/* ========================================================================= *
+ * PROTOTYPES
+ * ========================================================================= */
+
+typedef struct
+{
+ const char *max_brightness;
+ const char *brightness;
+} led_paths_redgreen_t;
+
+typedef struct
+{
+ sysfsval_t *cached_max_brightness;
+ sysfsval_t *cached_brightness;
+} led_channel_redgreen_t;
+
+/* ------------------------------------------------------------------------- *
+ * ONE_CHANNEL
+ * ------------------------------------------------------------------------- */
+
+static void led_channel_redgreen_init (led_channel_redgreen_t *self);
+static void led_channel_redgreen_close (led_channel_redgreen_t *self);
+static bool led_channel_redgreen_probe (led_channel_redgreen_t *self, const led_paths_redgreen_t *path);
+static void led_channel_redgreen_set_value (const led_channel_redgreen_t *self, int value);
+
+/* ------------------------------------------------------------------------- *
+ * ALL_CHANNELS
+ * ------------------------------------------------------------------------- */
+
+static void led_control_redgreen_map_color (int r, int g, int b, int *red, int *green);
+static void led_control_redgreen_value_cb (void *data, int r, int g, int b);
+static void led_control_redgreen_close_cb (void *data);
+
+bool led_control_redgreen_probe (led_control_t *self);
+
+/* ========================================================================= *
+ * ONE_CHANNEL
+ * ========================================================================= */
+
+static void
+led_channel_redgreen_init(led_channel_redgreen_t *self)
+{
+ self->cached_max_brightness = sysfsval_create();
+ self->cached_brightness = sysfsval_create();
+}
+
+static void
+led_channel_redgreen_close(led_channel_redgreen_t *self)
+{
+ 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)
+{
+ bool res = false;
+
+ 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 )
+ goto cleanup;
+
+ res = true;
+
+cleanup:
+
+ /* 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;
+}
+
+static void
+led_channel_redgreen_set_value(const led_channel_redgreen_t *self, int value)
+{
+ 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;
+ }
+}
+
+static void
+led_control_redgreen_value_cb(void *data, int r, int g, int b)
+{
+ const led_channel_redgreen_t *channel = data;
+
+ 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);
+}
+
+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);
+}
+
+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[][REDGREEN_CHANNELS] =
+ {
+ // "standard" paths
+ {
+ {
+ .max_brightness = "/sys/class/leds/red/max_brightness",
+ .brightness = "/sys/class/leds/red/brightness",
+ },
+ {
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/sysfs-led-redgreen.h
^
|
@@ -0,0 +1,31 @@
+/** @file sysfs-led-redgreen.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_REDGREEN_H_
+# define SYSFS_LED_REDGREEN_H_
+
+# include "sysfs-led-main.h"
+
+bool led_control_redgreen_probe(led_control_t *self);
+
+#endif /* SYSFS_LED_REDGREEN_H_ */
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/sysfs-led-util.c
^
|
@@ -0,0 +1,147 @@
+/** @file sysfs-led-util.c
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2013-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-led-util.h"
+
+#include "plugin-logging.h"
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+
+/* ========================================================================= *
+ * PROTOTYPES
+ * ========================================================================= */
+
+int led_util_read_number(const char *path);
+void led_util_close_file (int *fd_ptr);
+bool led_util_open_file (int *fd_ptr, const char *path);
+int led_util_scale_value(int in, int max);
+int led_util_gcd (int a, int b);
+int led_util_roundup (int val, int range);
+
+/* ========================================================================= *
+ * FUNCTIONS
+ * ========================================================================= */
+
+/** Read number from file
+ */
+int
+led_util_read_number(const char *path)
+{
+ int res = -1;
+ int fd = -1;
+ char tmp[64];
+
+ if( (fd = open(path, O_RDONLY)) == -1 ) {
+ goto cleanup;
+ }
+ int rc = read(fd, tmp, sizeof tmp - 1);
+ if( rc < 0 ) {
+ goto cleanup;
+ }
+ tmp[rc] = 0;
+ res = strtol(tmp, 0, 0);
+
+cleanup:
+
+ if( fd != -1 ) close(fd);
+
+ return res;
+}
+
+/** Close led sysfs control file
+ */
+void
+led_util_close_file(int *fd_ptr)
+{
+ if( fd_ptr && *fd_ptr != -1 )
+ {
+ close(*fd_ptr), *fd_ptr = -1;
+ }
+}
+
+/** Open led sysfs control file in append mode
+ */
+bool
+led_util_open_file(int *fd_ptr, const char *path)
+{
+ bool res = false;
+
+ led_util_close_file(fd_ptr);
+
+ if( fd_ptr && path )
+ {
+ if( (*fd_ptr = open(path, O_WRONLY|O_APPEND)) != -1 )
+ {
+ res = true;
+ }
+ else if( errno != ENOENT )
+ {
+ mce_log(LL_WARN, "%s: %s: %m", path, "open");
+ }
+ }
+
+ return res;
+}
+
+/** Scale value from 0...255 to 0...max range
+ */
+int
+led_util_scale_value(int in, int max)
+{
+ int out = (in * max + 128) / 255;
+
+ return (out < 0) ? 0 : (out < max) ? out : max;
+}
+
+/** Calculate the greatest common divisor of two integer numbers
+ */
+int
+led_util_gcd(int a, int b)
+{
+ int t;
+ /* Use abs values; will fail if a or b < -INT_MAX */
+ if( a < 0 ) a = -a;
+ if( b < 0 ) b = -b;
+
+ /* Make it so that: a >= b */
+ if( a < b ) t = a, a = b, b = t;
+
+ /* Iterate until a mod b reaches zero */
+ while( b ) t = a % b, a = b, b = t;
+
+ /* Do not return zero even on a == b == 0 */
+ return a ?: 1;
+}
+
+/** Round up number to the next multiple of given step size
+ */
+int
+led_util_roundup(int val, int range)
+{
+ int extra = val % range;
+ if( extra ) extra = range - extra;
+ return val + extra;
+}
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/sysfs-led-util.h
^
|
@@ -0,0 +1,36 @@
+/** @file sysfs-led-util.h
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2013-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_UTIL_H_
+# define SYSFS_LED_UTIL_H_
+
+# include <stdbool.h>
+
+int led_util_read_number (const char *path);
+void led_util_close_file (int *fd_ptr);
+bool led_util_open_file (int *fd_ptr, const char *path);
+int led_util_scale_value (int in, int max);
+int led_util_gcd (int a, int b);
+int led_util_roundup (int val, int range);
+
+#endif /* SYSFS_LED_UTIL_H_ */
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/sysfs-led-vanilla.c
^
|
@@ -0,0 +1,426 @@
+/** @file sysfs-led-vanilla.c
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2013-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: Jolla 1 backend
+ *
+ * Three channels, all of which:
+ * - must have 'brightness' control file
+ * - must have 'max_brightness' control file or nonzero fixed maximum
+ * - can have either
+ * o blink on/off delay control files
+ * o blink enabled/disable control control file
+ *
+ * Assumptions built into code:
+ *
+ * - The write() calls to sysfs controls return immediately from kernel to
+ * userspace, but the kernel side can stay busy with the change for few
+ * milliseconds -> Frequent intensity changes do not block mce process,
+ * so sw breathing is feasible. Minimum delay between led state changes
+ * must be enforced.
+ *
+ * - Blink controls for the R, G and B channels are independent. To avoid
+ * "rainbow patterns" when more than one channel is used the blink enabling
+ * for all of the channels as simultaneously as possible.
+ * ========================================================================= */
+
+#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>
+
+/* ========================================================================= *
+ * PROTOTYPES
+ * ========================================================================= */
+
+typedef struct
+{
+ 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
+{
+ 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;
+
+/* ------------------------------------------------------------------------- *
+ * ONE_CHANNEL
+ * ------------------------------------------------------------------------- */
+
+static void led_channel_vanilla_init (led_channel_vanilla_t *self);
+static void led_channel_vanilla_close (led_channel_vanilla_t *self);
+static bool led_channel_vanilla_probe (led_channel_vanilla_t *self, const led_paths_vanilla_t *path);
+static void led_channel_vanilla_set_value (led_channel_vanilla_t *self, int value);
+static void led_channel_vanilla_set_blink (led_channel_vanilla_t *self, int on_ms, int off_ms);
+
+/* ------------------------------------------------------------------------- *
+ * ALL_CHANNELS
+ * ------------------------------------------------------------------------- */
+
+static void led_control_vanilla_blink_cb (void *data, int on_ms, int off_ms);
+static void led_control_vanilla_value_cb (void *data, int r, int g, int b);
+static void led_control_vanilla_close_cb (void *data);
+
+bool led_control_vanilla_probe (led_control_t *self);
+
+/* ========================================================================= *
+ * ONE_CHANNEL
+ * ========================================================================= */
+
+static void
+led_channel_vanilla_init(led_channel_vanilla_t *self)
+{
+ 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)
+{
+ 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
+led_channel_vanilla_probe(led_channel_vanilla_t *self,
+ const led_paths_vanilla_t *path)
+{
+ bool res = false;
+
+ // maximum brightness can be read from file or given in config
+ if( sysfsval_open_ro(self->cached_max_brightness, path->max_brightness) )
+ sysfsval_refresh(self->cached_max_brightness);
+
+ 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( !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( 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
+ sysfsval_open_rw(self->cached_blink, path->blink);
+
+ res = true;
+
+cleanup:
+
+ /* 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)
+{
+ 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);
+
+}
+static void
+led_channel_vanilla_set_blink(led_channel_vanilla_t *self,
+ int on_ms, int off_ms)
+{
+ /* Note: Blinking config is taken in use when brightness
+ * sysfs is written to -> we need to invalidate
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/sysfs-led-vanilla.h
^
|
@@ -0,0 +1,31 @@
+/** @file sysfs-led-vanilla.h
+ *
+ * mce-plugin-libhybris - Libhybris plugin for Mode Control Entity
+ * <p>
+ * Copyright (C) 2013-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_VANILLA_H_
+# define SYSFS_LED_VANILLA_H_
+
+# include "sysfs-led-main.h"
+
+bool led_control_vanilla_probe(led_control_t *self);
+
+#endif /* SYSFS_LED_VANILLA_H_ */
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/sysfs-led-white.c
^
|
@@ -0,0 +1,267 @@
+/** @file sysfs-led-white.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
+ */
+
+/* ========================================================================= *
+ * White / single color led control
+ *
+ * One channel, which:
+ * - must have 'brightness' control file
+ * - must have 'max_brightness' control file
+ * ========================================================================= */
+
+#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>
+
+/* ========================================================================= *
+ * PROTOTYPES
+ * ========================================================================= */
+
+typedef struct
+{
+ const char *max_brightness; // R
+ const char *brightness; // W
+} led_paths_white_t;
+
+typedef struct
+{
+ sysfsval_t *cached_max_brightness;
+ sysfsval_t *cached_brightness;
+} led_channel_white_t;
+
+/* ------------------------------------------------------------------------- *
+ * ONE_CHANNEL
+ * ------------------------------------------------------------------------- */
+
+static void led_channel_white_init (led_channel_white_t *self);
+static void led_channel_white_close (led_channel_white_t *self);
+static bool led_channel_white_probe (led_channel_white_t *self, const led_paths_white_t *path);
+static void led_channel_white_set_value (const led_channel_white_t *self, int value);
+
+/* ------------------------------------------------------------------------- *
+ * ALL_CHANNELS
+ * ------------------------------------------------------------------------- */
+
+static void led_control_white_map_color (int r, int g, int b, int *white);
+static void led_control_white_value_cb (void *data, int r, int g, int b);
+static void led_control_white_close_cb (void *data);
+
+bool led_control_white_probe (led_control_t *self);
+
+/* ========================================================================= *
+ * ONE_CHANNEL
+ * ========================================================================= */
+
+static void
+led_channel_white_init(led_channel_white_t *self)
+{
+ self->cached_max_brightness = sysfsval_create();
+ self->cached_brightness = sysfsval_create();
+}
+
+static void
+led_channel_white_close(led_channel_white_t *self)
+{
+ 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;
+
+ if( !sysfsval_open_rw(self->cached_brightness, path->brightness) )
+ goto cleanup;
+
+ if( !sysfsval_open_ro(self->cached_max_brightness, path->max_brightness) )
+ goto cleanup;
+
+ sysfsval_refresh(self->cached_max_brightness);
+
+ if( sysfsval_get(self->cached_max_brightness) <= 0 )
+ goto cleanup;
+
+ res = true;
+
+cleanup:
+
+ /* 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;
+}
+
+static void
+led_channel_white_set_value(const led_channel_white_t *self, int value)
+{
+ 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;
+}
+
+static void
+led_control_white_value_cb(void *data, int r, int g, int b)
+{
+ const led_channel_white_t *channel = data;
+
+ int white = 0;
+ led_control_white_map_color(r, g, b, &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);
+}
+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;
+ }
+
+ return ack;
+}
+
+static bool
+led_control_white_dynamic_probe(led_channel_white_t *channel)
+{
|
[-]
[+]
|
Added |
_service:tar_git:mce-plugin-libhybris-1.12.1.tar.bz2/sysfs-led-white.h
^
|
@@ -0,0 +1,31 @@
+/** @file sysfs-led-white.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_WHITE_H_
+# define SYSFS_LED_WHITE_H_
+
+# include "sysfs-led-main.h"
+
+bool led_control_white_probe(led_control_t *self);
+
+#endif /* SYSFS_LED_WHITE_H_ */
|
[-]
[+]
|
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_ */
|
[-]
[+]
|
Deleted |
_service:tar_git:mce-plugin-libhybris-1.7.0.tar.bz2/hybris.c
^
|
@@ -1,2955 +0,0 @@
-/* ------------------------------------------------------------------------- *
- * Copyright (C) 2013 Jolla Ltd.
- * Contact: Simo Piiroinen <simo.piiroinen@jollamobile.com>
- * License: LGPLv2.1
- * ------------------------------------------------------------------------- */
-
-/* ========================================================================= *
- * This module implements "mce-libhybris-plugin" for use from
- * "mce-libhybris-module" within mce.
- *
- * The idea of "hybris-plugin" is shortly:
- * - it uses no mce functions or data types
- * - it can be compiled independently from mce
- * - it exposes no libhybris/android datatypes / functions
- *
- * And the idea of "hybris-module" is:
- * - it contains functions with the same names as "hybris-plugin"
- * - if called, the functions will load & call "hybris-plugin" code
- * - if "hybris-plugin" is not present "hybris-module" functions
- * still work, but return failures for everything
- *
- * Put together:
- * - mce code can assume that libhybris code is always available and
- * callable during hw probing activity
- * - if hybris plugin is not installed (or if some hw is not supported
- * by the underlying android code), failures will be reported and mce
- * can try other existing ways to proble hw controls
- * ========================================================================= */
-
-#define MCE_HYBRIS_INTERNAL 2
-#include "mce-hybris.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <syslog.h>
-#include <pthread.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <math.h>
-#include <errno.h>
-
-#include <glib.h>
-
-#include <system/window.h>
-#include <hardware/lights.h>
-#include <hardware/fb.h>
-#include <hardware/sensors.h>
-
-static void mce_hybris_sensors_quit(void);
-
-static void mce_hybris_log(int lev, const char *file,
- const char *func, const char *fmt,
- ...) __attribute__ ((format (printf, 4, 5)));
-
-/* ========================================================================= *
- * LOGGING
- * ========================================================================= */
-
-/** Callback function for diagnostic output, or NULL for stderr output */
-static mce_hybris_log_fn log_cb = 0;
-
-/** Set diagnostic output forwarding callback
- *
- * @param cb The callback function to use, or NULL for stderr output
- */
-void mce_hybris_set_log_hook(mce_hybris_log_fn cb)
-{
- log_cb = cb;
-}
-
-/** Wrapper for diagnostic logging
- *
- * @param lev syslog priority (=mce_log level) i.e. LOG_ERR etc
- * @param file source code path
- * @param func name of function within file
- * @param fmt printf compatible format string
- * @param ... parameters required by the format string
- */
-static void mce_hybris_log(int lev, const char *file, const char *func,
- const char *fmt, ...)
-{
- char *msg = 0;
- va_list va;
-
- va_start(va, fmt);
- if( vasprintf(&msg, fmt, va) < 0 ) msg = 0;
- va_end(va);
-
- if( msg ) {
- if( log_cb ) log_cb(lev, file, func, msg);
- else fprintf(stderr, "%s: %s: %s\n", file, func, msg);
- free(msg);
- }
-}
-
-/** Logging from hybris plugin mimics mce-log.h API */
-#define mce_log(LEV,FMT,ARGS...) \
- mce_hybris_log(LEV, __FILE__, __FUNCTION__ ,FMT, ## ARGS)
-
-/* ========================================================================= *
- * THREAD helpers
- * ========================================================================= */
-
-/** Thread start details; used for inserting custom thread setup code */
-typedef struct
-{
- void *data;
- void (*func)(void *);
-} gate_t;
-
-/** Mutex used for synchronous worker thread startup */
-static pthread_mutex_t gate_mutex = PTHREAD_MUTEX_INITIALIZER;
-
-/** Condition used for signaling worker thread startup */
-static pthread_cond_t gate_cond = PTHREAD_COND_INITIALIZER;
-
-/** Wrapper for starting new worker thread
- *
- * For use from mce_hybris_start_thread().
- *
- * Before the actual thread start routine is called, the
- * new thread is put in to asynchronously cancellabe state
- * and the starter is woken up via condition.
- *
- * @param aptr wrapper data as void pointer
- *
- * @return 0 on thread exit - via pthread_join()
- */
-static void *gate_start(void *aptr)
-{
- gate_t *gate = aptr;
-
- void (*func)(void*);
- void *data;
-
- /* Allow quick and dirty cancellation */
- pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0);
- pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0);
-
- /* Tell thread gate we're up and running */
- pthread_mutex_lock(&gate_mutex);
- pthread_cond_broadcast(&gate_cond);
- pthread_mutex_unlock(&gate_mutex);
-
- /* Collect data we need, release rest */
- func = gate->func;
- data = gate->data;
- free(gate), gate = 0;
-
- /* Call the real thread start */
- func(data);
-
- return 0;
-}
-
-/** Helper for starting new worker thread
- *
- * @param start function to call from new thread
- * @param arg data to pass to start function
- *
- * @return thread id on success, or 0 on error
- */
-static pthread_t mce_hybris_start_thread(void (*start)(void *),
- void* arg)
-{
- pthread_t res = 0;
- gate_t *gate = 0;
-
- if( !(gate = calloc(1, sizeof gate)) ) {
- goto EXIT;
- }
-
- gate->data = arg;
- gate->func = start;
-
- pthread_mutex_lock(&gate_mutex);
-
- if( pthread_create(&res, 0, gate_start, gate) != 0 ) {
- mce_log(LOG_ERR, "could not start worker thread");
-
- /* content of res is undefined on failure, force to zero */
- res = 0;
- }
- else {
- /* wait until thread has had time to start and set
- * up the cancellation parameters */
- mce_log(LOG_DEBUG, "waiting worker to start ...");
- pthread_cond_wait(&gate_cond, &gate_mutex);
- mce_log(LOG_DEBUG, "worker started");
-
- /* the thread owns the gate now */
- gate = 0;
- }
-
- pthread_mutex_unlock(&gate_mutex);
-
-EXIT:
|
[-]
[+]
|
Deleted |
_service:tar_git:mce-plugin-libhybris-1.7.0.tar.bz2/mce-hybris.h
^
|
@@ -1,110 +0,0 @@
-/* ------------------------------------------------------------------------- *
- * Copyright (C) 2013 Jolla Ltd.
- * Contact: Simo Piiroinen <simo.piiroinen@jollamobile.com>
- * License: LGPLv2.1
- * ------------------------------------------------------------------------- */
-
-/* FIXME: This header is included in sourcetrees of both mce and
- * mce-plugin-libhybris. For now it must be kept in sync
- * manually.
- */
-
-#ifndef MCE_HYBRIS_H_
-# define MCE_HYBRIS_H_
-
-# ifndef MCE_HYBRIS_INTERNAL
-# define MCE_HYBRIS_INTERNAL 0
-# endif
-
-# include <stdbool.h>
-# include <stdint.h>
-
-# ifdef __cplusplus
-extern "C" {
-# elif 0
-} /* fool JED indentation ... */
-# endif
-
-/* - - - - - - - - - - - - - - - - - - - *
- * frame buffer power state
- * - - - - - - - - - - - - - - - - - - - */
-
-bool mce_hybris_framebuffer_init(void);
-void mce_hybris_framebuffer_quit(void);
-bool mce_hybris_framebuffer_set_power(bool on);
-
-/* - - - - - - - - - - - - - - - - - - - *
- * display backlight brightness
- * - - - - - - - - - - - - - - - - - - - */
-
-bool mce_hybris_backlight_init(void);
-void mce_hybris_backlight_quit(void);
-bool mce_hybris_backlight_set_brightness(int level);
-
-/* - - - - - - - - - - - - - - - - - - - *
- * keypad backlight brightness
- * - - - - - - - - - - - - - - - - - - - */
-
-bool mce_hybris_keypad_set_brightness(int level);
-void mce_hybris_keypad_quit(void);
-bool mce_hybris_keypad_init(void);
-
-/* - - - - - - - - - - - - - - - - - - - *
- * indicator led pattern
- * - - - - - - - - - - - - - - - - - - - */
-
-bool mce_hybris_indicator_init(void);
-void mce_hybris_indicator_quit(void);
-bool mce_hybris_indicator_set_pattern(int r, int g, int b, int ms_on, int ms_off);
-void mce_hybris_indicator_enable_breathing(bool enable);
-bool mce_hybris_indicator_set_brightness(int level);
-bool mce_hybris_indicator_can_breathe(void);
-
-/* - - - - - - - - - - - - - - - - - - - *
- * proximity sensor
- * - - - - - - - - - - - - - - - - - - - */
-
-typedef void (*mce_hybris_ps_fn)(int64_t timestamp, float distance);
-
-bool mce_hybris_ps_init(void);
-void mce_hybris_ps_quit(void);
-bool mce_hybris_ps_set_active(bool active);
-bool mce_hybris_ps_set_callback(mce_hybris_ps_fn cb);
-
-/* - - - - - - - - - - - - - - - - - - - *
- * ambient light sensor
- * - - - - - - - - - - - - - - - - - - - */
-
-typedef void (*mce_hybris_als_fn)(int64_t timestamp, float light);
-
-bool mce_hybris_als_init(void);
-void mce_hybris_als_quit(void);
-bool mce_hybris_als_set_active(bool active);
-bool mce_hybris_als_set_callback(mce_hybris_als_fn cb);
-
-/* - - - - - - - - - - - - - - - - - - - *
- * generic
- * - - - - - - - - - - - - - - - - - - - */
-
-void mce_hybris_quit(void);
-
-/* - - - - - - - - - - - - - - - - - - - *
- * internal to module <--> plugin
- * - - - - - - - - - - - - - - - - - - - */
-
-# if MCE_HYBRIS_INTERNAL >= 1
-typedef void (*mce_hybris_log_fn)(int lev, const char *file, const char *func,
- const char *text);
-# endif
-
-# if MCE_HYBRIS_INTERNAL >= 2
-void mce_hybris_set_log_hook(mce_hybris_log_fn cb);
-void mce_hybris_ps_set_hook(mce_hybris_ps_fn cb);
-void mce_hybris_als_set_hook(mce_hybris_als_fn cb);
-# endif
-
-# ifdef __cplusplus
-};
-# endif
-
-#endif /* MCE_HYBRIS_H_ */
|