Skip to content

Commit d369791

Browse files
Merge pull request #21 from laurentalacoque/documentation
Documentation
2 parents f56c4d5 + c38018f commit d369791

File tree

8 files changed

+604
-299
lines changed

8 files changed

+604
-299
lines changed

scripts/configuration.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
"""Configuration module to adapt TouchSelfie behavior"""
12
import json
23
import os
34

45
class Configuration():
6+
"""Configuration class acts as configuration keys/values holder"""
57
# default values
68
user_name = None
79
logo_file = None
@@ -20,6 +22,14 @@ class Configuration():
2022

2123
#init
2224
def __init__(self,configuration_file_name):
25+
"""Creates the configuration object with default values and load the configuration file
26+
27+
__init__ will parse the configuration file given as its argument
28+
After parsing, is_valid property is set to True if no error was encountered
29+
30+
Arguments:
31+
configuration_file_name -- the conf.json file to read from or write to
32+
"""
2333
self.config_file = configuration_file_name
2434
self.is_valid = False
2535
self.__read_config_file()
@@ -60,6 +70,7 @@ def __read_config_file(self):
6070

6171

6272
def write(self):
73+
""" write the configuration object to the configuration file given at creation time"""
6374
myconfig = {
6475
"gmail_user": self.user_name,
6576
"countdown_before_snap": self.countdown1,
@@ -87,4 +98,4 @@ def write(self):
8798

8899
config = Configuration("myconf.conf")
89100
if not config.is_valid:
90-
config.write()
101+
config.write()

scripts/constants.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
"""
2+
Constants for the TouchSelfie program
3+
4+
.. py:data:: SCREEN_H,SCREEN_W
5+
Dimensions in pixels of the screen attached (will be used to compute layout)
6+
.. py:data:: EFFECT_PARAMETERS
7+
A dict of dict data structure to tune acquisition parameters for each snap effct
8+
.. py:data:: SOFTWARE_BUTTONS
9+
A dict of dict data structure to tune software buttons (in case of no hardware buttons)
10+
.. py:data:: HARDWARE_BUTTONS
11+
configuration of the hardware buttons' GPIO pins, pull_up_down state and active state
12+
.. py:data:: EMAIL_BUTTON_IMG
13+
'send_email' button icon
14+
.. py:data:: OAUTH2_REFRESH_PERIOD
15+
interval between two OAuth2 token refresh (ms)
16+
.. py:data:: HARDWARE_POLL_PERIOD = 100
17+
polling interval to detect hardware buttons change (ms)
18+
19+
.. py:data:: CONFIGURATION_FILE
20+
name of the configuration file (relative to scripts/ directory)
21+
.. py:data:: APP_ID_FILE
22+
name of the 'application_secret' file downloaded from console.developers.google.com (relative to scripts/ directory)
23+
.. py:data:: CREDENTIALS_STORE_FILE
24+
name of the automaticaly generated credentials store (relative to scripts/ directory)
25+
26+
"""
127

228
SCREEN_W = 800 ## raspi touch
329
SCREEN_H = 480 ## raspi touch

scripts/hardware_buttons.py

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,31 @@
2222

2323

2424
class Buttons():
25+
"""Hardware Buttons wrapper class"""
26+
2527
def __init__(self, buttons_pins=BUTTONS_PINS, mode=BUTTONS_MODE, active_state=BUTTON_IS_ACTIVE):
28+
"""Constructor for Buttons
29+
30+
Arguments:
31+
button_pins [list(int)] : list of GPIO pins
32+
mode ["pull_up" or "pull_down"] : the pull state of the GPIO
33+
active_state [0 or 1] : GPIO status when activated
34+
35+
Note: this is safe to use this class on systems that don't have GPIO module
36+
in this case, has_buttons() methods returns False
37+
"""
2638
self.buttons_pins = buttons_pins
27-
if mode == "pull_up":
28-
self.mode = GPIO.PUD_UP
29-
elif mode == "pull_down":
30-
self.mode = GPIO.PUD_DOWN
31-
else:
32-
raise ValueError("Unknown pull_up_down mode %s"%mode)
39+
3340

3441
self.active_state = active_state
3542
self._has_buttons = False
3643
if RPI_GPIO_EXISTS:
44+
if mode == "pull_up":
45+
self.mode = GPIO.PUD_UP
46+
elif mode == "pull_down":
47+
self.mode = GPIO.PUD_DOWN
48+
else:
49+
raise ValueError("Unknown pull_up_down mode %s"%mode)
3750
GPIO.setmode(GPIO.BOARD)
3851
for pin in self.buttons_pins:
3952
GPIO.setup(pin, GPIO.IN, pull_up_down = self.mode)
@@ -43,16 +56,39 @@ def __init__(self, buttons_pins=BUTTONS_PINS, mode=BUTTONS_MODE, active_state=BU
4356
self._has_buttons = False
4457

4558
def __del__(self):
59+
"""Cleanup GPIO"""
4660
if self._has_buttons:
4761
GPIO.cleanup()
4862

4963
def has_buttons(self):
64+
"""Wether buttons were configured
65+
66+
returns: True if at lease one button configured
67+
"""
5068
return self._has_buttons
5169

5270
def buttons_number(self):
71+
"""Number of configured hardware buttons
72+
73+
returns: the number of buttons configured
74+
"""
5375
return len(self.buttons_pins)
5476

5577
def state(self):
78+
"""Current state of the hardware buttons
79+
80+
buttons are checked in the order provided to the constructor
81+
as soon as a button state == active_state, the loop ends and the
82+
index of the active button is returned (first items of the buttons list
83+
therefore have higher priority)
84+
85+
returns:
86+
0 if no button currently active
87+
i (i>0) the index of the first active button with:
88+
i=1 => button_pins[0] is active
89+
i=2 => button_pins[1] is active
90+
...
91+
"""
5692
if not self._has_buttons:
5793
return 0
5894

0 commit comments

Comments
 (0)