|
@@ -153,8 +153,8 @@ and enter something like this:
|
153
|
153
|
import time
|
154
|
154
|
import RPi.GPIO as GPIO
|
155
|
155
|
|
156
|
|
-sleep_timeout = 1000
|
157
|
|
-sleep_toggle = 5.0
|
|
156
|
+hold_timeout = 2000
|
|
157
|
+sleep_toggle = 2000
|
158
|
158
|
pin_button = 5
|
159
|
159
|
pin_power = 3
|
160
|
160
|
|
|
@@ -166,10 +166,12 @@ GPIO.setup(pin_power, GPIO.IN)
|
166
|
166
|
GPIO.setup(pin_power, GPIO.OUT, initial=GPIO.input(pin_power))
|
167
|
167
|
|
168
|
168
|
while True:
|
169
|
|
- channel = GPIO.wait_for_edge(pin_button, GPIO.FALLING, timeout=sleep_timeout)
|
|
169
|
+ channel = GPIO.wait_for_edge(pin_button, GPIO.FALLING)
|
170
|
170
|
if channel is not None:
|
171
|
|
- GPIO.output(pin_power, not GPIO.input(pin_power))
|
172
|
|
- time.sleep(sleep_toggle)
|
|
171
|
+ time.sleep(hold_timeout / 1000.0)
|
|
172
|
+ if not GPIO.input(pin_button):
|
|
173
|
+ GPIO.output(pin_power, not GPIO.input(pin_power))
|
|
174
|
+ time.sleep(sleep_toggle / 1000.0)
|
173
|
175
|
|
174
|
176
|
GPIO.cleanup()
|
175
|
177
|
</pre>
|
|
@@ -193,11 +195,11 @@ Now also make this script executable, register it for execution on boot, and run
|
193
|
195
|
|
194
|
196
|
<pre class="sh_sh">
|
195
|
197
|
sudo chmod a+x /etc/init.d/octopi-power-button
|
196
|
|
-sudo update-rc.d /etc/init.d/octopi-power-button defaults
|
|
198
|
+sudo update-rc.d octopi-power-button defaults
|
197
|
199
|
sudo /etc/init.d/octopi-power-button
|
198
|
200
|
</pre>
|
199
|
201
|
|
200
|
|
-Now every time you press the button (with a 5s debounce delay afterwards) the printer power will be toggled.
|
|
202
|
+Now simply hold your power button for two seconds and the printer power will be toggled.
|
201
|
203
|
|
202
|
204
|
### Automatic Photo Upload
|
203
|
205
|
|