Skip to content

Commit

Permalink
Merge pull request #33 from prtuson/master
Browse files Browse the repository at this point in the history
Changes to make orientation work under systemd
  • Loading branch information
pfps committed Apr 5, 2015
2 parents ff90ed3 + 92c997a commit 60c4724
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 7 deletions.
20 changes: 13 additions & 7 deletions sensors/orientation.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ Use via something like\n\
signal(SIGINT, sigint_callback_handler);
signal(SIGHUP, sigint_callback_handler);
signal(SIGUSR1, sigusr_callback_handler);

error_restart:

/* Find the device requested */
info.device_id = find_type_by_name(device_name, "iio:device");
Expand Down Expand Up @@ -388,14 +390,18 @@ Use via something like\n\

for (i = 0; i != config.iterations; i++) {
if (config.debug_level > 2) printf("Finding orientation %d\n", orientation);
if ((int)(orientation = (OrientationPositions)(prepare_output(&info, dev_dir_name, trigger_name, &process_scan, config))) < 0) break;
if (config.debug_level > 2) printf("Found orientation: or:%d, prev:%d, scr:%d, %d\n", orientation, previous_orientation, screen_orientation, FLAT);
if (config.debug_level > 0) printf("Orientation at %3.1f is %s\n", ((double) config.poll_timeout / 1000000.0) * i, symbolic_orientation(orientation));
if (previous_orientation == orientation /* only rotate when stable */ &&
orientation != screen_orientation && orientation != FLAT && !orientation_lock) {
rotate_to(orientation);
if ((int)(orientation = (OrientationPositions)(prepare_output(&info, dev_dir_name, trigger_name, &process_scan, config))) != -1) {
if (config.debug_level > 2) printf("Found orientation: or:%d, prev:%d, scr:%d, %d\n", orientation, previous_orientation, screen_orientation, FLAT);
if (config.debug_level > 0) printf("Orientation at %3.1f is %s\n", ((double) config.poll_timeout / 1000000.0) * i, symbolic_orientation(orientation));
if (previous_orientation == orientation /* only rotate when stable */ &&
orientation != screen_orientation && orientation != FLAT && !orientation_lock) {
rotate_to(orientation);
previous_orientation = orientation;
} else {
orientation = FLAT;
sleep(10);
goto error_restart;
}
previous_orientation = orientation;
usleep(config.poll_timeout);
}

Expand Down
16 changes: 16 additions & 0 deletions sensors/services/orientation.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# /etc/systemd/system/orientation.service

[Unit]
Description=Authomativally Orientate Screen
Wants=permissions.service
After=permissions.service

[Service]
Group=users
Environment="DISPLAY=:0"
ExecStart=/usr/bin/orientation --debug=-1
ExecStop=/usr/bin/pkill -f orientation
RemainAfterExit=yes

[Install]
WantedBy=graphical.target
22 changes: 22 additions & 0 deletions sensors/services/permissions.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# /etc/systemd/system/permissions.service

[Unit]
Description=Set up Permissions for Automatic Screen Orientation
After=suspend.target

[Service]
Type=oneshot
Environment="DISPLAY=:0"
#
# Re-enable the touchscreen after suspend
ExecStart=/sbin/rmmod usbhid hid_multitouch
ExecStart=/sbin/modprobe usbhid hid_multitouch
#
# Set permissions
ExecStart=/opt/set_permissions.sh

[Install]
#
# Activate on startup and after suspend
WantedBy=suspend.target
WantedBy=graphical.target
8 changes: 8 additions & 0 deletions sensors/services/set_permissions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /bin/sh
#
# /opt/set_permissions.sh

/bin/chgrp users /sys/bus/iio/devices/iio:device*/scan_elements/in_*_en /sys/bus/iio/devices/iio:device*/buffer/* /sys/bus/iio/devices/iio:device*/trigger/current_trigger
/bin/chmod g+w /sys/bus/iio/devices/iio:device*/scan_elements/in_*_en /sys/bus/iio/devices/iio:device*/buffer/* /sys/bus/iio/devices/iio:device*/trigger/current_trigger
/bin/chgrp users /dev/iio:device*
/bin/chmod g+rw /dev/iio:device*

0 comments on commit 60c4724

Please sign in to comment.