-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
209 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
from EPD_json import main | ||
from EPD_json import main | ||
from EPD import * | ||
from EPD_ip import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#! /usr/bin/env python | ||
# EPD_button : python script for probing the EPD button. | ||
# More in /usr/local/lib/python2.7/dist-packages/ea_epd_sensor_values/README . | ||
|
||
# To introduce your own reaction to pressing the button create use a copy of this file, change the marked | ||
# service routine part and, when needed, the modules to be imported. | ||
|
||
import logging | ||
import logging.handlers | ||
import argparse | ||
import sys | ||
import time # this is only being used as part of the example,import time | ||
import RPi.GPIO as GPIO | ||
from ea_epd_sensor_values import * | ||
|
||
# Deafults | ||
LOG_FILENAME = "/tmp/epd_button.log" | ||
LOG_LEVEL = logging.INFO # Could be e.g. "DEBUG" or "WARNING" | ||
|
||
# Define and parse command line arguments | ||
parser = argparse.ArgumentParser(description="Python service for probing the EPD button.") | ||
parser.add_argument("-l", "--log", help="file to write log to (default '" + LOG_FILENAME + "')") | ||
|
||
# If the log file is specified on the command line then override the default | ||
args = parser.parse_args() | ||
if args.log: | ||
LOG_FILENAME = args.log | ||
|
||
# Configure logging to log to a file, making a new file at midnight and keeping the last 3 day's data | ||
# Give the logger a unique name (good practice) | ||
logger = logging.getLogger(__name__) | ||
# Set the log level to LOG_LEVEL | ||
logger.setLevel(LOG_LEVEL) | ||
# Make a handler that writes to a file, making a new file at midnight and keeping 3 backups | ||
handler = logging.handlers.TimedRotatingFileHandler(LOG_FILENAME, when="midnight", backupCount=3) | ||
# Format each log message like this | ||
formatter = logging.Formatter('%(asctime)s %(levelname)-8s %(message)s') | ||
# Attach the formatter to the handler | ||
handler.setFormatter(formatter) | ||
# Attach the handler to the logger | ||
logger.addHandler(handler) | ||
|
||
# Make a class we can use to capture stdout and sterr in the log | ||
class MyLogger(object): | ||
def __init__(self, logger, level): | ||
"""Needs a logger and a logger level.""" | ||
self.logger = logger | ||
self.level = level | ||
|
||
def write(self, message): | ||
# Only log if there is a message (not just a new line) | ||
if message.rstrip() != "": | ||
self.logger.log(self.level, message.rstrip()) | ||
|
||
# Replace stdout with logging to file at INFO level | ||
sys.stdout = MyLogger(logger, logging.INFO) | ||
# Replace stderr with logging to file at ERROR level | ||
sys.stderr = MyLogger(logger, logging.ERROR) | ||
|
||
###################################### | ||
# Your service routine below # | ||
###################################### | ||
|
||
GPIO.setmode(GPIO.BOARD) | ||
GPIO.setup(15, GPIO.IN) | ||
logger.info("Pins initialized.") | ||
|
||
epd = EPD() | ||
logger.info("EPD initialized. Probing starts.") | ||
while True: | ||
if ( not GPIO.input(15)): | ||
EPD_ip(epd) | ||
time.sleep(1) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#! /bin/sh | ||
### BEGIN INIT INFO | ||
# Provides: epd_button | ||
# Required-Start: $remote_fs $syslog | ||
# Required-Stop: $remote_fs $syslog | ||
# Should-Start: $portmap | ||
# Should-Stop: $portmap | ||
# X-Start-Before: nis | ||
# X-Stop-After: nis | ||
# Default-Start: 2 3 4 5 | ||
# Default-Stop: 0 1 6 | ||
# X-Interactive: true | ||
# Short-Description: Enable printing IP and MAC at the EPD with a press of the button of EPD. | ||
# Description: Execute a python script to probe the EPD button in an infinite loop. | ||
### END INIT INFO | ||
|
||
# Change the next 3 lines to suit where you install your script and what you want to call it | ||
DIR=/usr/local/bin/ | ||
DAEMON=$DIR/EPD_button | ||
DAEMON_NAME=epd_button | ||
|
||
# Add any command line options for your daemon here | ||
DAEMON_OPTS="" | ||
|
||
# This next line determines what user the script runs as. | ||
# Root generally not recommended but necessary if you are using the Raspberry Pi GPIO from Python. | ||
DAEMON_USER=root | ||
|
||
# The process ID of the script when it runs is stored here: | ||
PIDFILE=/var/run/$DAEMON_NAME.pid | ||
|
||
. /lib/lsb/init-functions | ||
|
||
do_start () { | ||
log_daemon_msg "Starting system $DAEMON_NAME daemon" | ||
start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile --user $DAEMON_USER --chuid $DAEMON_USER --startas $DAEMON -- $DAEMON_OPTS | ||
log_end_msg $? | ||
} | ||
do_stop () { | ||
log_daemon_msg "Stopping system $DAEMON_NAME daemon" | ||
start-stop-daemon --stop --pidfile $PIDFILE --retry 10 | ||
log_end_msg $? | ||
} | ||
|
||
case "$1" in | ||
|
||
start|stop) | ||
do_${1} | ||
;; | ||
|
||
restart|reload|force-reload) | ||
do_stop | ||
do_start | ||
;; | ||
|
||
status) | ||
status_of_proc "$DAEMON_NAME" "$DAEMON" && exit 0 || exit $? | ||
;; | ||
|
||
*) | ||
echo "Usage: /etc/init.d/$DAEMON_NAME {start|stop|restart|status}" | ||
exit 1 | ||
;; | ||
|
||
esac | ||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
# | ||
sudo bash ./install_epd_driver.sh | ||
sudo python setup.py install | ||
sudo bash ./install_button_service.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
sudo cp ea_epd_sensor_values/bin/EPD_button /usr/local/bin/ | ||
sudo chmod 755 /usr/local/bin/EPD_button | ||
sudo cp ea_epd_sensor_values/daemon/epd_button /etc/init.d | ||
sudo chmod 755 /etc/init.d/epd_button | ||
sudo update-rc.d epd_button defaults |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,15 +3,15 @@ | |
from setuptools import setup | ||
|
||
setup(name='ea_epd_sensor_values', | ||
version='1.0', | ||
version='1.01', | ||
description='Display .json file on Embedded Artists 2.7" EPD', | ||
url='https://gitlab.ips.biba.uni-bremen.de/iotfablab/ea-epd-sensor-values', | ||
author='Mikolaj Dobielewski', | ||
author_email='[email protected]', | ||
license='MIT', | ||
license='Apache License, Version 2.0', | ||
packages=['ea_epd_sensor_values'], | ||
zip_safe=False, | ||
include_package_data=True, | ||
install_requires=['Pillow'], | ||
scripts=['ea_epd_sensor_values/bin/EPD_json'] | ||
scripts=['ea_epd_sensor_values/bin/EPD_json', 'ea_epd_sensor_values/bin/EPD_button'] | ||
) |