1.1 --- a/pkg/landfall-examples/letux400_backlight/letux400_backlight.cc Thu Dec 31 19:15:34 2020 +0100
1.2 +++ b/pkg/landfall-examples/letux400_backlight/letux400_backlight.cc Thu Dec 31 19:16:17 2020 +0100
1.3 @@ -1,7 +1,8 @@
1.4 /*
1.5 * Access the keypad to modify the backlight on the Letux 400.
1.6 *
1.7 - * Fn+Volume Down/Up adjusts the brightness.
1.8 + * Fn+Down/Up adjusts the brightness.
1.9 + * Zzz+Down/Up disables/enables the backlight.
1.10 *
1.11 * Copyright (C) 2018, 2020 Paul Boddie <paul@boddie.org.uk>
1.12 *
1.13 @@ -24,14 +25,12 @@
1.14 #include <l4/devices/input-keypad-client.h>
1.15 #include <l4/devices/keypad-loader.h>
1.16
1.17 -#include <l4/re/env>
1.18 -#include <l4/sys/capability>
1.19 +#include <l4/re/env.h>
1.20
1.21 #include <l4/re/event_enums.h>
1.22 #include <l4/util/util.h>
1.23
1.24 -#include <stdio.h>
1.25 -
1.26 +#include "activation_client.h"
1.27 #include "backlight_client.h"
1.28
1.29 /* Backlight level. */
1.30 @@ -48,9 +47,11 @@
1.31 /* Key state. */
1.32
1.33 static int modifier_set = 0;
1.34 +static int enable_modifier_set = 0;
1.35
1.36 /* Backlight references. */
1.37
1.38 +Activation *activation_device;
1.39 Backlight *backlight_device;
1.40
1.41
1.42 @@ -61,12 +62,14 @@
1.43 {
1.44 (void) priv;
1.45
1.46 - /* Track the state of the modifier key. */
1.47 + /* Track the state of the modifier keys. */
1.48
1.49 - if (event.code == L4RE_KEY_SLEEP)
1.50 + if (event.code == L4RE_KEY_FN)
1.51 modifier_set = event.value;
1.52 + else if (event.code == L4RE_KEY_SLEEP)
1.53 + enable_modifier_set = event.value;
1.54
1.55 - if (!event.value || !modifier_set)
1.56 + if (!event.value || !(modifier_set || enable_modifier_set))
1.57 return;
1.58
1.59 /* Upon keypress events, test controls and update the backlight. */
1.60 @@ -74,14 +77,24 @@
1.61 switch (event.code)
1.62 {
1.63 case L4RE_KEY_DOWN:
1.64 - if (backlight_level < Letux400_backlight_min_level + Letux400_backlight_step)
1.65 + if (enable_modifier_set)
1.66 + {
1.67 + activation_device->disable();
1.68 + return;
1.69 + }
1.70 + else if (backlight_level < Letux400_backlight_min_level + Letux400_backlight_step)
1.71 backlight_level = Letux400_backlight_min_level;
1.72 else
1.73 backlight_level -= Letux400_backlight_step;
1.74 break;
1.75
1.76 case L4RE_KEY_UP:
1.77 - if (backlight_level > Letux400_backlight_max_level - Letux400_backlight_step)
1.78 + if (enable_modifier_set)
1.79 + {
1.80 + activation_device->enable();
1.81 + return;
1.82 + }
1.83 + else if (backlight_level > Letux400_backlight_max_level - Letux400_backlight_step)
1.84 backlight_level = Letux400_backlight_max_level;
1.85 else
1.86 backlight_level += Letux400_backlight_step;
1.87 @@ -109,7 +122,11 @@
1.88 l4_cap_idx_t backlight = l4re_env_get_cap("backlight");
1.89 if (!l4_is_valid_cap(backlight)) return 1;
1.90
1.91 - /* Use only the backlight interface with the backlight. */
1.92 + /* NOTE: The component framework should permit the use of a compound client
1.93 + object. */
1.94 +
1.95 + client_Activation activation_obj(backlight);
1.96 + activation_device = &activation_obj;
1.97
1.98 client_Backlight backlight_obj(backlight);
1.99 backlight_device = &backlight_obj;