Skip to content

Commit

Permalink
Touch: Make detection into a library
Browse files Browse the repository at this point in the history
Split the detection script into a library to allow other apps to cleanly
use it. Also add optional Conan support.
  • Loading branch information
tombettany committed Nov 1, 2018
1 parent cf0a151 commit ce77102
Show file tree
Hide file tree
Showing 30 changed files with 359 additions and 35 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ cscope.po.out
reports
.pytest_cache

# Build dirs
touch-detect/release
touch-detect/debug


# Created by https://www.gitignore.io/api/python,c,c++,vim,osx,sublimetext,cmake

Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

REPO:= kano-peripherals

.PHONY: clean docs libs
.PHONY: clean docs libs touch-detect

clean:
cd docs && make clean
Expand All @@ -18,6 +18,10 @@ docs:
libs:
cd libs/pi_hat && cmake . && make

touch-detect:
cd touch-detect && make release
cd touch-detect && make debug

#
# Add test targets
#
Expand Down
1 change: 1 addition & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
kano-peripherals (4.2.0-0) unstable; urgency=low

* Fixed an issue where the sound module wouldn't be loaded when daemon crashed
* Make the touch-detect tool into a library

-- Team Kano <dev@kano.me> Thu, 4 Oct 2018 17:54:00 +0100

Expand Down
14 changes: 14 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,17 @@ Depends:
libxi6
Description: Support for touchscreen detection and flipping

Package: kano-touch-support-dev
Architecture: any
Depends:
${misc:Depends},
kano-touch-support
Description: Development tools to support touchscreen detection and flipping

Package: kano-touch-support-dbg
Architecture: any
Depends:
${misc:Depends},
kano-touch-support
Description: Debug symbols for support for touchscreen detection and flipping

2 changes: 1 addition & 1 deletion debian/copyright
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ Files: kano_peripherals/speaker_leds/driver/pwm_driver.py:
Copyright: 2012-2013 Limor Fried, Kevin Townsend and Mikey Sklar for Adafruit Industries.
Licence: BSD-3-clause

Files: touch-detect/touch-detect.c
Files: touch-detect/lib/platforms/macosx/touch_detect.cpp
Copyright: 1996-1997 by Frederic Lepied, France, 2007 Peter Hutterer, 2009 Red Hat, Inc, 2018 Kano Computing Ltd
Licence: MIT
2 changes: 2 additions & 0 deletions debian/kano-touch-support-dbg.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
touch-detect/build/debug/bin/touch-detect usr/lib/debug/usr/bin/
touch-detect/build/debug/lib/*.so usr/lib/debug/usr/lib
2 changes: 2 additions & 0 deletions debian/kano-touch-support-dev.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
touch-detect/include/* usr/include/
touch-detect/build/release/lib/*.a usr/lib
8 changes: 5 additions & 3 deletions debian/kano-touch-support.install
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
touch-detect/touch-detect usr/bin/
touch-detect/*.sh usr/share/kano-peripherals/scripts/
conf/xorg.conf.d/* usr/share/kano-peripherals/xorg.conf.d/
touch-detect/build/release/bin/touch-detect usr/bin/
touch-detect/build/release/lib/*.so usr/lib/
touch-detect/scripts/*.sh usr/share/kano-peripherals/scripts/
touch-detect/conf/xorg.conf.d/* usr/share/kano-peripherals/xorg.conf.d/
touch-detect/conf/etc/* etc/
2 changes: 1 addition & 1 deletion debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ override_dh_auto_build:
cd libs/pi_hat && cmake . && make
cd po && make messages.pot
cd po && make
cd touch-detect && ./build.sh
make touch-detect

override_dh_fixperms:
dh_fixperms
Expand Down
6 changes: 4 additions & 2 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ flake8-ignore =
F841 # Local variable is assigned to but never used
features/* ALL
tests/* ALL
libs/pi_hat/examples/python/* ALL
kano-doc/* ALL
kano_peripherals/speaker_leds/driver/pwm_driver.py ALL
libs/pi_hat/examples/python/* ALL
kano-doc/* ALL
**/conanfile.py ALL
52 changes: 52 additions & 0 deletions touch-detect/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
cmake_minimum_required(VERSION 2.8)
project(TouchDetect CXX)

if(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
endif()


if (APPLE) # OS X
set(LINK_LIBS "")
set(PLATFORM_SRC lib/platforms/macosx)
elseif (UNIX AND NOT APPLE) # Linux
set(LINK_LIBS X11 Xi)
set(PLATFORM_SRC lib/platforms/linux)
endif()


set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)


add_library(touch_detect_lib SHARED
${PLATFORM_SRC}/touch_detect.cpp
)
target_link_libraries(touch_detect_lib ${LINK_LIBS})
set_target_properties(touch_detect_lib PROPERTIES OUTPUT_NAME "touch_detect")
target_include_directories(touch_detect_lib PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)


add_library(touch_detect_lib_static STATIC
${PLATFORM_SRC}/touch_detect.cpp
)
target_link_libraries(touch_detect_lib_static ${LINK_LIBS})
set_target_properties(touch_detect_lib_static PROPERTIES OUTPUT_NAME "touch_detect")
target_include_directories(touch_detect_lib_static PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)


add_executable(touch_detect
src/main.cpp
)
set_target_properties(touch_detect PROPERTIES OUTPUT_NAME "touch-detect")
target_link_libraries(touch_detect
touch_detect_lib
)
9 changes: 9 additions & 0 deletions touch-detect/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
all: debug release

release:
mkdir -p build/release
cd build/release && cmake -DCMAKE_BUILD_TYPE=Release ../.. && make

debug:
mkdir -p build/debug
cd build/debug && cmake -DCMAKE_BUILD_TYPE=Debug ../.. && make
44 changes: 44 additions & 0 deletions touch-detect/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Touch Detect

## Building

Create the build directory

```
mkdir -p build
cd build
```

(Optional) Install dependencies with `conan` (otherwise ensure that you have
the dependencies available to the build system)

```
conan install ..
```

Build

```
cmake ..
make
```

## Conan (Experimental)

This package has been created to be (optionally) shipped with a conan package,
hence you can do an operation like:

```
cd build
conan create .. KanoComputing/stable
```

This can then be pushed to the artifactory and used as a dependency of another
project.

To use this package, make sure that your `conanfile.txt` looks like this

```
[requires]
touch-detect/4.2.0@KanoComputing/stable
```
3 changes: 0 additions & 3 deletions touch-detect/build.sh

This file was deleted.

48 changes: 48 additions & 0 deletions touch-detect/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#
# conanfile.py
#
# Copyright (C) 2018 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU GPL v2
#
# Specifies the touch-detect package for Conan
#


from conans import ConanFile, CMake


class TouchdetectConan(ConanFile):
name = "touch-detect"
version = "4.2.0"
license = "<Put the package license here>"
url = "<Package recipe repository url here, for issues about the package>"
description = "<Description of Touchdetect here>"
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False]}
default_options = "shared=False"
generators = "cmake"
exports_sources = "src/*", "lib/*", "include/*", "CMakeLists.txt"

def build(self):
cmake = CMake(self)
cmake.configure(source_folder="")
cmake.build()

def package(self):
self.copy("*.h", dst="include", src="include")
self.copy("*.lib", dst="lib", keep_path=False)
self.copy("*.dll", dst="bin", keep_path=False)
self.copy("*.dylib*", dst="lib", keep_path=False)
self.copy("*.so", dst="lib", keep_path=False)
self.copy("*.a", dst="lib", keep_path=False)

def package_info(self):
self.cpp_info.libs = ["touch_detect"]

def deploy(self):
self.copy("*.h")
self.copy("*.lib")
self.copy("*.dll")
self.copy("*.dylib*")
self.copy("*.so")
self.copy("*.a")
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 23 additions & 0 deletions touch-detect/include/Kano/TouchDetect/touch_detect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* touch_detect.h
*
* Copyright (C) 2018 Kano Computing Ltd.
* License: http://www.gnu.org/licenses/gpl-2.0.txt GNU GPLv2
*
* vim: filetype=cpp
*
* Detect if a touch device is present
*
*/


#pragma once


namespace Kano
{
namespace TouchDetect
{
bool isTouchSupported();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* touch-detect
* touch_detect.cpp
*
* Copyright (C) 2018 Kano Computing Ltd.
* License: MIT
Expand All @@ -17,46 +17,49 @@
*
*/


#include <X11/Xlib.h>
#include <X11/extensions/XInput.h>
#include <X11/extensions/XInput2.h>
#include <stdio.h>
#include <syslog.h>

int isTouch(void) {
int found = 1;
Display *display = XOpenDisplay(NULL);
int ndevices=0, i, j;
if(!display)
{

#include <Kano/TouchDetect/touch_detect.h>


bool Kano::TouchDetect::isTouchSupported() {
bool found = false;
Display *display = XOpenDisplay(nullptr);
int ndevices = 0;

if (!display) {
syslog(LOG_ERR | LOG_USER, "touch-detect: could not connect to display\n");
exit(1);
return false;
}

XIDeviceInfo *info, *dev;
info = XIQueryDevice(display, XIAllDevices, &ndevices);
for(i = 0; i < ndevices; i++)
{
dev = &info[i];
if(dev->use != XISlavePointer)
XIDeviceInfo *info = XIQueryDevice(display, XIAllDevices, &ndevices);

for (int i = 0; i < ndevices; i++) {
XIDeviceInfo *dev = &info[i];

if (dev->use != XISlavePointer)
continue;

dev->classes, dev->num_classes;
for (j = 0; j < dev->num_classes; j++)
{
if(dev->classes[j]->type == XITouchClass)
{

for (int j = 0; j < dev->num_classes; j++) {
if (dev->classes[j]->type == XITouchClass) {
printf("%d\n", dev->deviceid);
found = 0;
found = true;
}
}
}

XIFreeDeviceInfo(info);

if (display)
XCloseDisplay(display);
return found;
}

int main(int argc, char * argv[])
{
return isTouch();
return found;
}
20 changes: 20 additions & 0 deletions touch-detect/lib/platforms/macosx/touch_detect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* touch_detect.cpp
*
* Copyright (C) 2018 Kano Computing Ltd.
* License: http://www.gnu.org/licenses/gpl-2.0.txt GNU GPLv2
*
* Detect if a touch device is present
*
*/


#include <Kano/TouchDetect/touch_detect.h>

#include <iostream>


bool Kano::TouchDetect::isTouchSupported() {
std::cout << "Not implemented for OSX, returning true\n";
return true;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit ce77102

Please sign in to comment.