1.1 --- a/pkg/landfall-examples/letux400_keypad_driver/letux400_keypad_driver.cc Fri May 18 17:19:28 2018 +0200
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,251 +0,0 @@
1.4 -/*
1.5 - * Access the keypad on the configured device using an input driver.
1.6 - *
1.7 - * (c) 2018 Paul Boddie <paul@boddie.org.uk>
1.8 - *
1.9 - * This program is free software; you can redistribute it and/or
1.10 - * modify it under the terms of the GNU General Public License as
1.11 - * published by the Free Software Foundation; either version 2 of
1.12 - * the License, or (at your option) any later version.
1.13 - *
1.14 - * This program is distributed in the hope that it will be useful,
1.15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 - * GNU General Public License for more details.
1.18 - *
1.19 - * You should have received a copy of the GNU General Public License
1.20 - * along with this program; if not, write to the Free Software
1.21 - * Foundation, Inc., 51 Franklin Street, Fifth Floor,
1.22 - * Boston, MA 02110-1301, USA
1.23 - *
1.24 - *
1.25 - * Font definitions and licence (see unifont.tff for bitmap data derived from
1.26 - * GNU Unifont's unifont.hex file):
1.27 - *
1.28 - * Copyright (C) 1998-2003 Roman Czyborra (http://czyborra.com/)
1.29 - *
1.30 - * All glyphs are released under the GNU General Public License
1.31 - * (GPL) version 2 or (at your option) a later version, with the
1.32 - * GNU font embedding exception:
1.33 - *
1.34 - * ** GPL v2.0 license with font embedding exception:
1.35 - *
1.36 - * As a special exception, if you create a document which
1.37 - * uses this font, and embed this font or unaltered portions
1.38 - * of this font into the document, this font does not by
1.39 - * itself cause the resulting document to be covered by
1.40 - * the GNU General Public License. This exception does not
1.41 - * however invalidate any other reasons why the document
1.42 - * might be covered by the GNU General Public License.
1.43 - * If you modify this font, you may extend this exception
1.44 - * to your version of the font, but you are not obligated
1.45 - * to do so. If you do not wish to do so, delete this
1.46 - * exception statement from your version.
1.47 - */
1.48 -
1.49 -#include <l4/devices/input-keypad-client.h>
1.50 -
1.51 -#include <l4/re/c/util/video/goos_fb.h>
1.52 -#include <l4/re/c/video/view.h>
1.53 -#include <l4/util/util.h>
1.54 -
1.55 -#include <l4/mag-gfx/canvas>
1.56 -#include <l4/mag-gfx/font>
1.57 -#include <l4/mag-gfx/geometry>
1.58 -#include <l4/mag-gfx/gfx_colors>
1.59 -#include <l4/mag-gfx/mem_factory>
1.60 -
1.61 -#include <stdint.h>
1.62 -#include <string.h>
1.63 -
1.64 -/* Video abstractions. */
1.65 -
1.66 -static l4re_util_video_goos_fb_t gfb;
1.67 -static l4re_video_view_info_t view_info;
1.68 -static void *fb = 0;
1.69 -
1.70 -/* Bundled font data. */
1.71 -
1.72 -extern char const _binary_unifont_tff_start[];
1.73 -
1.74 -/* Screen abstractions. */
1.75 -
1.76 -using namespace Mag_gfx;
1.77 -
1.78 -static Font *_font = 0;
1.79 -static Canvas *_screen = 0;
1.80 -
1.81 -
1.82 -
1.83 -/* Factories for certain pixel formats. */
1.84 -
1.85 -static Mem::Factory<Rgb16> _rgb16;
1.86 -static Mem::Factory<Rgb32> _rgb32;
1.87 -
1.88 -
1.89 -
1.90 -/* Key to character conversion function. */
1.91 -
1.92 -static const char *keys_to_strings[] = {
1.93 -
1.94 - 0, "Escape", "1", "2", "3", "4", "5", "6", "7", "8",
1.95 -
1.96 - "9", "0", "-", "=", "Backspace", "Tab", "Q", "W", "E", "R",
1.97 -
1.98 - "T", "Y", "U", "I", "O", "P", "[", "]", "Enter", "Left Ctrl",
1.99 -
1.100 - "A", "S", "D", "F", "G", "H", "J", "K", "L", ";",
1.101 -
1.102 - "'", "`", "Left Shift", "\\", "Z", "X", "C", "V", "B", "N",
1.103 -
1.104 - "M", ",", ".", "/", "Right Shift", "Keypad *", "Left Alt", "Space",
1.105 - "Caps Lock", "F1",
1.106 -
1.107 - "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "Num Lock",
1.108 -
1.109 - "Scroll Lock", "Keypad 7", "Keypad 8", "Keypad 9", "Keypad -", "Keypad 4",
1.110 - "Keypad 5", "Keypad 6", "Keypad +", "Keypad 1",
1.111 -
1.112 - "Keypad 2", "Keypad 3", "Keypad 0", "Keypad .", 0, 0, "#102", "F11", "F12", 0,
1.113 -
1.114 - 0, 0, 0, 0, 0, 0, "Keypad Enter", "Right Ctrl", "Keypad /", "SysRq",
1.115 -
1.116 - "Right Alt", "Line Feed", "Home", "Up", "Page Up", "Left", "Right", "End",
1.117 - "Down", "Page Down",
1.118 -
1.119 - "Insert", "Delete", "Macro", "Mute", "Volume Down", "Volume Up", "Power",
1.120 - "Keypad =", "Keypad +-", "Pause",
1.121 -};
1.122 -
1.123 -static const char null_string[] = "Unknown";
1.124 -
1.125 -const int keys_to_strings_length = 120;
1.126 -
1.127 -static const char *key_to_string(int key)
1.128 -{
1.129 - return key < keys_to_strings_length ? keys_to_strings[key] : 0;
1.130 -}
1.131 -
1.132 -/* Show the keypad event status on the display. */
1.133 -
1.134 -static uint8_t row = 0;
1.135 -static uint32_t text_x = 0, text_y = 0, next_y = 0;
1.136 -
1.137 -static void handler(Input_event event, void *priv)
1.138 -{
1.139 - uint32_t colsize = view_info.width / 10,
1.140 - rowsize = view_info.height / 20;
1.141 - uint8_t column;
1.142 - uint16_t mask;
1.143 -
1.144 - /* Convert the key code into a bit pattern. */
1.145 -
1.146 - if (!priv)
1.147 - {
1.148 - for (column = 0, mask = (1 << 9); column < 10; column++, mask >>= 1)
1.149 - _screen->draw_box(Rect(Point(column * colsize, row * rowsize), Area(colsize, rowsize)),
1.150 - event.code & mask ? event.value ? Rgb32::Color(0, 255, 0) : Rgb32::Color(255, 0, 0)
1.151 - : Rgb32::Color(0, 0, 0));
1.152 -
1.153 - /* Advance to the next row, wrapping around. */
1.154 -
1.155 - row = (row + 1) % 20;
1.156 - }
1.157 -
1.158 - /* Or produce a string. */
1.159 -
1.160 - else if (event.value)
1.161 - {
1.162 - const char *s = ((const char *(*)(int)) priv)(event.code);
1.163 - Rgba32::Color col;
1.164 -
1.165 - if (!s)
1.166 - {
1.167 - s = null_string;
1.168 - col = Rgba32::Color(255, 0, 0, Rgba32::Color::Amax);
1.169 - }
1.170 - else
1.171 - col = Rgba32::Color(255, 255, 255, Rgba32::Color::Amax);
1.172 -
1.173 - Area box = _font->str_sz(s, strlen(s));
1.174 -
1.175 - /* Test for enough space horizontally. */
1.176 -
1.177 - if (text_x + box.w() > view_info.width)
1.178 - {
1.179 - text_x = 0;
1.180 - text_y = next_y;
1.181 - next_y = text_y + box.h();
1.182 - }
1.183 -
1.184 - /* Expand the line height, if appropriate. */
1.185 -
1.186 - else if (text_y + box.h() > next_y)
1.187 - next_y += box.h();
1.188 -
1.189 - /* Test for enough space vertically. */
1.190 -
1.191 - if (next_y > view_info.height)
1.192 - {
1.193 - text_x = 0;
1.194 - text_y = 0;
1.195 - next_y = box.h();
1.196 - }
1.197 -
1.198 - Point p(text_x, text_y);
1.199 -
1.200 - _screen->draw_box(Rect(p, box), Rgb32::Color(0, 0, 0));
1.201 - _screen->draw_string(p, _font, col, s, strlen(s));
1.202 -
1.203 - /* Move to the next position. */
1.204 -
1.205 - text_x += box.w();
1.206 - }
1.207 -
1.208 - /* Refresh the display. */
1.209 -
1.210 - l4re_util_video_goos_fb_refresh(&gfb, 0, 0, view_info.width, view_info.height);
1.211 -}
1.212 -
1.213 -/* Arguments: [ chars ] */
1.214 -
1.215 -int main(int argc, char *argv[])
1.216 -{
1.217 - Keypad *keypad = Keypad::get_keypad();
1.218 - Input_keypad_client client(keypad);
1.219 -
1.220 - if (l4re_util_video_goos_fb_setup_name(&gfb, "fb"))
1.221 - return 1;
1.222 -
1.223 - if (l4re_util_video_goos_fb_view_info(&gfb, &view_info))
1.224 - return 1;
1.225 -
1.226 - if (!(fb = l4re_util_video_goos_fb_attach_buffer(&gfb)))
1.227 - return 1;
1.228 -
1.229 - /* Obtain a canvas for the framebuffer. */
1.230 -
1.231 - Factory *factory;
1.232 -
1.233 - if (view_info.pixel_info.bytes_per_pixel == 2)
1.234 - factory = &_rgb16;
1.235 - else
1.236 - factory = &_rgb32;
1.237 -
1.238 - Canvas *screen = factory->create_canvas((void *) ((unsigned long) fb + view_info.buffer_offset),
1.239 - Area(view_info.width, view_info.height),
1.240 - view_info.bytes_per_line);
1.241 -
1.242 - Font font(&_binary_unifont_tff_start[0]);
1.243 -
1.244 - _screen = screen;
1.245 - _font = &font;
1.246 -
1.247 - /* Attach the event handler and wait for events. */
1.248 -
1.249 - client.attach(handler, (argc > 1) && (!strcmp(argv[1], "chars")) ? (void *) key_to_string : 0);
1.250 -
1.251 - l4_sleep_forever();
1.252 -
1.253 - return 0;
1.254 -}