Permalink
Browse files

new file: Application.lua

	deleted:    PixelBuffer.lua
	modified:   desktop.ppm
	modified:   test_libev.lua
	renamed:    luaunit.lua -> tests/luaunit.lua
	renamed:    test.lua -> tests/test.lua
	new file:   tests/test_App_Watcher.lua
	new file:   tests/test_bouncing_square.lua
  • Loading branch information...
1 parent c745839 commit e5452d4b119f0ae63d7ce69e932758e66ffd583d @Wiladams committed Oct 30, 2012
View
@@ -0,0 +1,98 @@
+
+local ffi = require "ffi"
+
+local ev = require "ev_utils"
+local S = require "syscall"
+local UI = require "input"
+
+Application = {
+ IdleWatchers = {},
+ MouseWatchers = {},
+ KeyboardWatchers = {},
+ TimerWatchers = {},
+ SocketWatchers = {},
+ FileWatchers = {},
+}
+
+-- Create the primary application event loop
+Application.Loop = ev.ev_loop();
+
+Application.AddIdleObserver = function(onactivity)
+ local watcher = ev.ev_idle(onactivity);
+ table.insert(Application.IdleWatchers, {watcher});
+end
+
+Application.AddKeyboardObserver = function(onactivity, devicename)
+ devicename = devicename or "/dev/input/event0"
+ local fd, err = S.open(devicename, "O_RDONLY");
+ if not fd then
+ return false, err
+ end
+
+ local watcher = ev.ev_io(onactivity, fd:getfd(), ffi.C.EV_READ);
+ table.insert(Application.KeyboardWatchers, {watcher, fd});
+
+ return true;
+end
+
+
+Application.AddMouseObserver = function(onactivity, devicename)
+ devicename = devicename or "/dev/input/event1"
+ local fd = S.open(devicename, "O_RDONLY");
+ if not fd then
+ return false, err
+ end
+
+ local watcher = ev.ev_io(onactivity, fd:getfd(), ffi.C.EV_READ);
+ table.insert(Application.MouseWatchers, {watcher, fd});
+
+ return true;
+end
+
+Application.AddTimerObserver = function(onactivity, after, interval)
+ local watcher = ev.ev_timer(onactivity, after, interval);
+ table.insert(Application.TimerWatchers, {watcher});
+
+ return true;
+end
+
+Application.Run = function()
+ -- Start the various watchers
+ -- Start Mouse Watchers
+ for i,watcher in ipairs(Application.MouseWatchers) do
+ watcher[1]:start(Application.Loop);
+ end
+
+ -- Start Keyboard Watchers
+ for i,watcher in ipairs(Application.KeyboardWatchers) do
+ watcher[1]:start(Application.Loop);
+ end
+
+ -- Start Socket Watchers
+ for i,watcher in ipairs(Application.SocketWatchers) do
+ watcher[1]:start(Application.Loop);
+ end
+
+ -- Start File Watchers
+ for i,watcher in ipairs(Application.FileWatchers) do
+ watcher[1]:start(Application.Loop);
+ end
+
+ -- Start Timer Watchers
+ for i,watcher in ipairs(Application.TimerWatchers) do
+ watcher[1]:start(Application.Loop);
+ end
+
+ -- Start the idle watchers
+ for i,watcher in ipairs(Application.IdleWatchers) do
+ watcher[1]:start(Application.Loop);
+ end
+
+ Application.Loop:run();
+end
+
+Application.Finish = function()
+ Application.Loop:halt();
+end
+
+return Application
View
@@ -1,38 +0,0 @@
-
-local ffi = require "ffi"
-local bit = require "bit"
-local bnot = bit.bnot
-local band = bit.band
-local bor = bit.bor
-local rshift = bit.rshift
-local lshift = bit.lshift
-
-local DMX = require "DisplayManX"
-
-local ALIGN_UP = function(x,y)
- return band((x + y-1), bnot(y-1))
-end
-
-local PixelBuffer = {}
-local PixelBuffer_mt = {
- __index = PixelBuffer
-}
-
-PixelBuffer.new = function(width, height, imgtype)
- imgtype = imgtype or ffi.C.VC_IMAGE_RGB565
-
- local pitch = ALIGN_UP(width*sizeofpixel, 32);
- local aligned_height = ALIGN_UP(height, 16);
-
- local obj = {
- PixelFormat = imgtype;
- Width = width;
- Height = height;
- Pitch = pitch;
- Data = ffi.new("uint8_t[?]", pitch * height);
- }
-
- setmetatable(obj, PixelBuffer_mt);
-
- return obj;
-end
View
Binary file not shown.
View
@@ -51,18 +51,30 @@ function OnKey(loop, w, revents)
if event.value == 1 then
print("KEYDOWN: ", event.code);
elseif event.value == 0 then
+ print("KEYUP: ", event.code);
+
if event.code == KEY_ESC then
loop:halt();
return false;
end
- print("KEYUP: ", event.code);
+ elseif event.value == 2 then
+ print("KEYREP: ", event.code);
end
else
--print("EVENT TYPE: ", UI.EventTypes[event.type][2], "CODE:",event.code, "VALUE: ", string.format("0x%x",event.value));
end
end
+function OnTTY(loop, w, revents)
+ local bufflen = 10;
+ local buff = ffi.new("char[?]", bufflen);
+
+ local bytesread = S.read(w.fd, buff, bufflen);
+ print("TTY: ", ffi.string(buff, bytesread));
+
+end
+
function OnMouse(loop, w, revents)
--print("OnMouse: ", w, revents);
local event = input_event();
@@ -89,6 +101,19 @@ print("FD: ", fd, kfd);
local iowatcher = ev.ev_io(OnKey, kfd, ffi.C.EV_READ);
iowatcher:start(loop, true);
+function watchtty(filename)
+ local tty, err = S.open("/dev/tty0", "O_RDONLY");
+ if not tty then
+ print("TTY ERROR: ", err);
+ return false
+ end
+
+ local ttyfd = tty:getfd();
+ print("TTY FD: ", ttyfd);
+ local ttywatcher = ev.ev_io(OnTTY, ttyfd, ffi.C.EV_READ);
+ ttywatcher:start(loop, true);
+end
+
-- Mouse Tracking
local fd = S.open("/dev/input/event1", "O_RDONLY");
local mfd = fd:getfd();
File renamed without changes.
File renamed without changes.
View
@@ -0,0 +1,93 @@
+package.path = package.path..";../?.lua"
+
+local ffi = require "ffi"
+
+local app = require "Application";
+
+local S = require "syscall"
+
+
+--[[
+ Callback functions
+--]]
+
+function OnTimer(loop, ...)
+ print("OnTimer: ", loop:iteration());
+end
+
+function OnIdle(loop, ...)
+ print("Idling");
+end
+
+
+
+--[[
+ Event type:
+ EV_KEY
+ EV_MSC
+
+ value:
+ 0 == keyup
+ 1 == keydown
+--]]
+
+function OnKey(loop, w, revents)
+ local event = input_event();
+ local bytesread = S.read(w.fd, event, ffi.sizeof(event));
+
+
+ if event.type == EV_MSC then
+ if event.code == MSC_SCAN then
+ --print("MSC_SCAN: ", string.format("0x%x",event.value));
+ else
+ --print("MSC: ", event.code, event.value);
+ end
+ elseif event.type == EV_KEY then
+ if event.value == 1 then
+ print("KEYDOWN: ", event.code);
+ elseif event.value == 0 then
+ print("KEYUP: ", event.code);
+
+ if event.code == KEY_ESC then
+ loop:halt();
+ return false;
+ end
+
+ elseif event.value == 2 then
+ print("KEYREP: ", event.code);
+ end
+ else
+ --print("EVENT TYPE: ", UI.EventTypes[event.type][2], "CODE:",event.code, "VALUE: ", string.format("0x%x",event.value));
+ end
+end
+
+function OnMouse(loop, w, revents)
+ --print("OnMouse: ", w, revents);
+ local event = input_event();
+ local bytesread = S.read(w.fd, event, ffi.sizeof(event));
+
+ print("MOUSE: ", event.type, event.code, event.value);
+end
+
+
+--[[
+ Create Observers
+--]]
+
+--app.AddIdleObserver(OnIdle);
+
+-- Timer Observer
+app.AddTimerObserver(OnTimer, 1, 3);
+
+-- Keyboard Tracking
+app.AddKeyboardObserver(OnKey);
+
+-- Mouse Tracking
+--app.AddMouseObserver(OnMouse);
+
+
+-- Run the Application
+app.Run();
+
+
+
@@ -0,0 +1,93 @@
+package.path = package.path..";../?.lua"
+
+local ffi = require "ffi"
+
+local app = require "Application";
+
+local S = require "syscall"
+
+
+--[[
+ Callback functions
+--]]
+
+function OnTimer(loop, ...)
+ print("OnTimer: ", loop:iteration());
+end
+
+function OnIdle(loop, ...)
+ print("Idling");
+end
+
+
+
+--[[
+ Event type:
+ EV_KEY
+ EV_MSC
+
+ value:
+ 0 == keyup
+ 1 == keydown
+--]]
+
+function OnKey(loop, w, revents)
+ local event = input_event();
+ local bytesread = S.read(w.fd, event, ffi.sizeof(event));
+
+
+ if event.type == EV_MSC then
+ if event.code == MSC_SCAN then
+ --print("MSC_SCAN: ", string.format("0x%x",event.value));
+ else
+ --print("MSC: ", event.code, event.value);
+ end
+ elseif event.type == EV_KEY then
+ if event.value == 1 then
+ print("KEYDOWN: ", event.code);
+ elseif event.value == 0 then
+ print("KEYUP: ", event.code);
+
+ if event.code == KEY_ESC then
+ loop:halt();
+ return false;
+ end
+
+ elseif event.value == 2 then
+ print("KEYREP: ", event.code);
+ end
+ else
+ --print("EVENT TYPE: ", UI.EventTypes[event.type][2], "CODE:",event.code, "VALUE: ", string.format("0x%x",event.value));
+ end
+end
+
+function OnMouse(loop, w, revents)
+ --print("OnMouse: ", w, revents);
+ local event = input_event();
+ local bytesread = S.read(w.fd, event, ffi.sizeof(event));
+
+ print("MOUSE: ", event.type, event.code, event.value);
+end
+
+
+--[[
+ Create Observers
+--]]
+
+--app.AddIdleObserver(OnIdle);
+
+-- Timer Observer
+app.AddTimerObserver(OnTimer, 1, 0.5);
+
+-- Keyboard Tracking
+app.AddKeyboardObserver(OnKey);
+
+-- Mouse Tracking
+--app.AddMouseObserver(OnMouse);
+
+
+-- Run the Application
+app.Run();
+
+
+

0 comments on commit e5452d4

Please sign in to comment.