diff --git a/led.py b/led.py index f67b268..239bf2b 100755 --- a/led.py +++ b/led.py @@ -5,6 +5,10 @@ import wiringpi import click import time +def setup() -> None: + wiringpi.wiringPiSetupGpio() + wiringpi.pinMode(18, 1) + def pin_on() -> None: # Attiva uscita GPIO18 wiringpi.digitalWrite(18, 1) @@ -31,8 +35,7 @@ def toggle() -> None: @click.command() @click.argument('op') def cli(op): - wiringpi.wiringPiSetupGpio() - wiringpi.pinMode(18, 1) + setup() if op in [ "accendi", "on" ]: pin_on() diff --git a/requirements.txt b/requirements.txt index 2ce2f60..046d3a0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ wiringpi click +flask diff --git a/webapp.py b/webapp.py new file mode 100644 index 0000000..df8bcb7 --- /dev/null +++ b/webapp.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 +# encoding: utf-8 + +from flask import Flask +import led + +app = Flask(__name__) + +@app.route('/') +def index(): + return "Benvenuto nel raspberry." + +@app.route('/accendi') +@app.route('/on') +def accendi() -> None: + led.pin_on() + +@app.route('/spegni') +@app.route('/off') +def spegni() -> None: + led.pin_off() + +@app.route('/toggle') +def toggle() -> None: + led.toggle() + +@app.route('/lampeggia') +def lampeggia(): + led.lampeggia() + +if __name__ == '__main__': + led.setup() + app()