Skip to content

Commit

Permalink
(tests) add "interactive/touchtest"
Browse files Browse the repository at this point in the history
  • Loading branch information
cipharius committed May 13, 2023
1 parent be2ee43 commit da00280
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/interactive/README.md
Expand Up @@ -79,6 +79,8 @@ soundtest - deprecated, test sample and streaming playback

switcher - test appl switching

touchtest - test touch input

tracetst - using benchmark function to generate chrome friendly system trace

vidtag - another record testing
Expand Down
53 changes: 53 additions & 0 deletions tests/interactive/touchtest/touchtest.lua
@@ -0,0 +1,53 @@
local devices = {};
local TOUCH_W = 100;
local TOUCH_H = 100;

function touchtest()
image_color(WORLDID, 127, 127, 127);
end

function touchtest_input(iotbl)
if (iotbl.kind ~= "touch") then
return;
end

local device = devices[iotbl.devid];
if (not device) then
local x_axis = inputanalog_query(iotbl.devid, 0);
local y_axis = inputanalog_query(iotbl.devid, 1);

if (not x_axis or not y_axis) then
error("Failed to query for one of input device axis metadata");
end

device = {
x_min = x_axis.lower_bound,
x_max = x_axis.upper_bound,
y_min = y_axis.lower_bound,
y_max = y_axis.upper_bound,
touches = {},
};
devices[iotbl.devid] = device;
end

if (iotbl.active) then
local surface = device.touches[iotbl.subid];
if (not surface) then
surface = color_surface(TOUCH_W, TOUCH_H, 255, 0, 0);
show_image(surface);
device.touches[iotbl.subid] = surface;
end

local x = (iotbl.x - device.x_min) /
(device.x_max - device.x_min) *
VRESW - TOUCH_W / 2;
local y = (iotbl.y - device.y_min) /
(device.y_max - device.y_min) *
VRESH - TOUCH_H / 2;

move_image(surface, x, y)
elseif (device.touches[iotbl.subid]) then
delete_image(device.touches[iotbl.subid]);
device.touches[iotbl.subid] = nil;
end
end

0 comments on commit da00280

Please sign in to comment.