mirror of
https://github.com/Yours3lf/rpi-vk-driver.git
synced 2024-11-29 11:24:14 +01:00
added input handler, doesn't work
This commit is contained in:
parent
b2b6acabdb
commit
ba46123aab
135
test/inputHandler/inputHandler.c
Normal file
135
test/inputHandler/inputHandler.c
Normal file
@ -0,0 +1,135 @@
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "inputHandler.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <libinput.h>
|
||||
#include <libudev.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include "../../driver/CustomAssert.h"
|
||||
|
||||
struct libinput *li;
|
||||
struct udev* _udev;
|
||||
|
||||
static int open_restricted(const char *path, int flags, void *user_data)
|
||||
{
|
||||
int fd = open(path, flags);
|
||||
return fd < 0 ? -errno : fd;
|
||||
}
|
||||
|
||||
static void close_restricted(int fd, void *user_data)
|
||||
{
|
||||
close(fd);
|
||||
}
|
||||
|
||||
const static struct libinput_interface interface = {
|
||||
.open_restricted = open_restricted,
|
||||
.close_restricted = close_restricted,
|
||||
};
|
||||
|
||||
void initInputHandler()
|
||||
{
|
||||
_udev = udev_new();
|
||||
udev_ref(_udev);
|
||||
li = libinput_udev_create_context(&interface, NULL, _udev); assert(li);
|
||||
uint32_t res = libinput_udev_assign_seat(li, "seat0"); assert(res == 0);
|
||||
|
||||
libinput_dispatch(li);
|
||||
|
||||
//configure devices
|
||||
// libinput_device_config_accel_set_speed()
|
||||
// libinput_device_config_accel_set_profile()
|
||||
// libinput_device_config_scroll_set_natural_scroll_enabled()
|
||||
|
||||
struct libinput_event* event = 0;
|
||||
while ((event = libinput_get_event(li)) != 0)
|
||||
{
|
||||
uint32_t type = libinput_event_get_type(event);
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case LIBINPUT_EVENT_DEVICE_ADDED:
|
||||
{
|
||||
struct libinput_device* dev = libinput_event_get_device(event);
|
||||
printf("Device name: %s\n", libinput_device_get_name(dev));
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
libinput_event_destroy(event);
|
||||
libinput_dispatch(li);
|
||||
}
|
||||
}
|
||||
|
||||
void handleInput()
|
||||
{
|
||||
assert(li);
|
||||
|
||||
struct libinput_event* event = 0;
|
||||
while ((event = libinput_get_event(li)) != 0)
|
||||
{
|
||||
uint32_t type = libinput_event_get_type(event);
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case LIBINPUT_EVENT_DEVICE_ADDED:
|
||||
{
|
||||
struct libinput_device* dev = libinput_event_get_device(event);
|
||||
printf("Device name: %s\n", libinput_device_get_name(dev));
|
||||
break;
|
||||
}
|
||||
case LIBINPUT_EVENT_KEYBOARD_KEY:
|
||||
{
|
||||
uint32_t keyCode = libinput_event_keyboard_get_key(libinput_event_get_keyboard_event(event));
|
||||
enum libinput_key_state keyState = libinput_event_keyboard_get_key_state(libinput_event_get_keyboard_event(event));
|
||||
printf("Keypress keycode %u state %u\n", keyCode, keyState);
|
||||
break;
|
||||
}
|
||||
case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
|
||||
{
|
||||
double xCoord = libinput_event_pointer_get_absolute_x(libinput_event_get_pointer_event(event));
|
||||
double yCoord = libinput_event_pointer_get_absolute_y(libinput_event_get_pointer_event(event));
|
||||
printf("Pointer motion xcoord %lf ycoord %lf\n", xCoord, yCoord);
|
||||
break;
|
||||
}
|
||||
case LIBINPUT_EVENT_POINTER_BUTTON:
|
||||
{
|
||||
uint32_t button = libinput_event_pointer_get_button(libinput_event_get_pointer_event(event));
|
||||
enum libinput_button_state buttonState = libinput_event_pointer_get_button_state(libinput_event_get_pointer_event(event));
|
||||
printf("Pointer button button %u, state %u\n", button, buttonState);
|
||||
break;
|
||||
}
|
||||
case LIBINPUT_EVENT_POINTER_AXIS:
|
||||
{
|
||||
enum libinput_pointer_axis_source axisSource = libinput_event_pointer_get_axis_source(libinput_event_get_pointer_event(event));
|
||||
double axisValueVertical = libinput_event_pointer_get_axis_value(libinput_event_get_pointer_event(event), LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
|
||||
double axisValueHorizontal = libinput_event_pointer_get_axis_value(libinput_event_get_pointer_event(event), LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
|
||||
printf("Pointer axis source %u, value vertical %lf, value horizontal %lf\n", axisSource, axisValueVertical, axisValueHorizontal);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
libinput_event_destroy(event);
|
||||
libinput_dispatch(li);
|
||||
}
|
||||
}
|
||||
|
||||
void uninitInputHandler()
|
||||
{
|
||||
libinput_unref(li);
|
||||
udev_unref(_udev);
|
||||
}
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
#endif
|
14
test/inputHandler/inputHandler.h
Normal file
14
test/inputHandler/inputHandler.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void initInputHandler();
|
||||
void handleInput();
|
||||
void uninitInputHandler();
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
@ -1,6 +1,7 @@
|
||||
file(GLOB testSrc
|
||||
"*.h"
|
||||
"*.cpp"
|
||||
"../inputHandler/inputHandler.c"
|
||||
)
|
||||
|
||||
add_executable(inputTest ${testSrc})
|
||||
|
@ -3,66 +3,17 @@
|
||||
#include <algorithm>
|
||||
#include <string.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <libinput.h>
|
||||
#include <libudev.h>
|
||||
|
||||
static int open_restricted(const char *path, int flags, void *user_data)
|
||||
{
|
||||
int fd = open(path, flags);
|
||||
return fd < 0 ? -errno : fd;
|
||||
}
|
||||
|
||||
static void close_restricted(int fd, void *user_data)
|
||||
{
|
||||
close(fd);
|
||||
}
|
||||
|
||||
const static struct libinput_interface interface = {
|
||||
.open_restricted = open_restricted,
|
||||
.close_restricted = close_restricted,
|
||||
};
|
||||
|
||||
#include "../inputHandler/inputHandler.h"
|
||||
|
||||
int main(void) {
|
||||
struct libinput *li;
|
||||
struct libinput_event *event;
|
||||
struct udev* udev;
|
||||
initInputHandler();
|
||||
|
||||
udev = udev_new();
|
||||
li = libinput_udev_create_context(&interface, NULL, udev);
|
||||
libinput_udev_assign_seat(li, "seat0");
|
||||
libinput_dispatch(li);
|
||||
|
||||
while (true)
|
||||
while(true)
|
||||
{
|
||||
event = libinput_get_event(li);
|
||||
|
||||
if(event)
|
||||
{
|
||||
uint32_t type = libinput_event_get_type(event);
|
||||
struct libinput_device* dev = libinput_event_get_device(event);
|
||||
|
||||
// handle the event here
|
||||
std::cout << "Event type: " << type << std::endl;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case LIBINPUT_EVENT_DEVICE_ADDED:
|
||||
{
|
||||
std::cout << "Device name: " << libinput_device_get_name(dev) << std::endl;
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
libinput_event_destroy(event);
|
||||
libinput_dispatch(li);
|
||||
}
|
||||
handleInput();
|
||||
}
|
||||
|
||||
libinput_unref(li);
|
||||
uninitInputHandler();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
file(GLOB testSrc
|
||||
"*.h"
|
||||
"*.cpp"
|
||||
../inputHandler/inputHandler.c
|
||||
)
|
||||
|
||||
add_executable(mipmapping ${testSrc} )
|
||||
@ -8,4 +9,5 @@ target_compile_options(mipmapping PRIVATE -Wall -std=c++11
|
||||
-march=${RPI_ARCH} -fPIC
|
||||
)
|
||||
|
||||
target_link_libraries(mipmapping vulkan $<TARGET_OBJECTS:QPUassembler>)
|
||||
#target_link_libraries(mipmapping vulkan $<TARGET_OBJECTS:QPUassembler>)
|
||||
target_link_libraries(mipmapping rpi-vk-driver mtdev evdev udev input)
|
||||
|
@ -10,6 +10,8 @@
|
||||
#include "driver/vkExt.h"
|
||||
#include "QPUassembler/qpu_assembler.h"
|
||||
|
||||
#include "../inputHandler/inputHandler.h"
|
||||
|
||||
//#define GLFW_INCLUDE_VULKAN
|
||||
//#define VK_USE_PLATFORM_WIN32_KHR
|
||||
//#include <GLFW/glfw3.h>
|
||||
@ -177,26 +179,7 @@ void cleanup() {
|
||||
vkDestroyInstance(instance, nullptr);
|
||||
}
|
||||
|
||||
void run() {
|
||||
// Note: dynamically loading loader may be a better idea to fail gracefully when Vulkan is not supported
|
||||
|
||||
// Create window for Vulkan
|
||||
//glfwInit();
|
||||
|
||||
//glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
//glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
|
||||
|
||||
//window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "The 630 line cornflower blue window", nullptr, nullptr);
|
||||
|
||||
// Use Vulkan
|
||||
setupVulkan();
|
||||
|
||||
mainLoop();
|
||||
|
||||
cleanup();
|
||||
}
|
||||
|
||||
void setupVulkan() {
|
||||
void setupVulkan() {
|
||||
createInstance();
|
||||
findPhysicalDevice();
|
||||
createWindowSurface();
|
||||
@ -217,11 +200,11 @@ void setupVulkan() {
|
||||
}
|
||||
|
||||
void mainLoop() {
|
||||
//while (!glfwWindowShouldClose(window)) {
|
||||
for(int c = 0; c < 300; ++c){
|
||||
while(true)
|
||||
{
|
||||
draw();
|
||||
|
||||
//glfwPollEvents();
|
||||
handleInput();
|
||||
}
|
||||
}
|
||||
|
||||
@ -804,7 +787,7 @@ void draw() {
|
||||
assert(0);
|
||||
}
|
||||
|
||||
std::cout << "acquired image" << std::endl;
|
||||
//std::cout << "acquired image" << std::endl;
|
||||
|
||||
// Wait for image to be available and draw
|
||||
VkSubmitInfo submitInfo = {};
|
||||
@ -824,7 +807,7 @@ void draw() {
|
||||
assert(0);
|
||||
}
|
||||
|
||||
std::cout << "submitted draw command buffer" << std::endl;
|
||||
//std::cout << "submitted draw command buffer" << std::endl;
|
||||
|
||||
// Present drawn image
|
||||
// Note: semaphore here is not strictly necessary, because commands are processed in submission order within a single queue
|
||||
@ -844,7 +827,7 @@ void draw() {
|
||||
assert(0);
|
||||
}
|
||||
|
||||
std::cout << "submitted presentation command buffer" << std::endl;
|
||||
//std::cout << "submitted presentation command buffer" << std::endl;
|
||||
}
|
||||
|
||||
void CreateRenderPass()
|
||||
@ -1805,15 +1788,7 @@ void CreateVertexBuffer()
|
||||
}
|
||||
|
||||
int main() {
|
||||
// Note: dynamically loading loader may be a better idea to fail gracefully when Vulkan is not supported
|
||||
|
||||
// Create window for Vulkan
|
||||
//glfwInit();
|
||||
|
||||
//glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
//glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
|
||||
|
||||
//window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "The 630 line cornflower blue window", nullptr, nullptr);
|
||||
initInputHandler();
|
||||
|
||||
// Use Vulkan
|
||||
setupVulkan();
|
||||
@ -1822,6 +1797,8 @@ int main() {
|
||||
|
||||
cleanup();
|
||||
|
||||
uninitInputHandler();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user