def __init__(self, camera, output_path, app):
        self.output_path = output_path
        self.last_file_path = None
        self.app = app
        self.camera = camera
        self.camera_overlay = CameraOverlay(self.camera)
        self.printer = Printer()
        self.green_btn = Button(GREEN_BTN_PIN)
        self.red_btn = Button(RED_BTN_PIN)
        self.green_btn.when_pressed = self.pressed_capture_button
        self.red_btn.when_pressed = self.pressed_reject_print_button
        self.ui = UI(self.camera_overlay, camera.picam.resolution)
        self.image_helper = ImageHelper(camera.picam.resolution)
        self.rotary = Rotary(ROTARY_CLK_PIN, ROTARY_DT_PIN, upperBound=5)

        self.camera.show_preview(True)
        self.ui.show_main_screen()

        self.waiting_for_confirm = False
        self.busy = False
Exemplo n.º 2
0
    def __init__(self):

        self.commander = Commander("init")
        self.gpio = pigpio.pi()
        self.rotary = Rotary("init", None)
        self.decoder = Decoder("init")
        self.digitalpots = Digitalpots("init")
        self.static1 = 1
        self.mainwindow = Mainwindow(self.static1,
                                     "passing commander into mainwindow",
                                     commander=self.commander)
        self.rotary = Rotary(self.static1,
                             "passing gpio into rotary",
                             gpio=self.gpio)
        self.decoder = Decoder("passing gpio into decoder", gpio=self.gpio)
        self.static2 = 2
        self.rotary = Rotary(self.static2,
                             "passing decoder into rotary",
                             decoder=self.decoder)
        digitalpots = Digitalpots("passing gpio, decoder into rotary",
                                  gpio=self.gpio,
                                  decoder=self.decoder)
        print("Local static val {}".format(self.rotary.static_val))
Exemplo n.º 3
0
def test_menu():
    from menu import Menu
    from rotary import Rotary

    m = Menu([
        "First line", "A second menu option", "Now to the third",
        "On to the forth", "Follow the fifth", "Support the sixth"
    ])

    r = Rotary(**{'menu': m, 'clk': 11, 'dt': 13, 'btn': 15})

    if len(sys.argv) > 1:
        if sys.argv[1] == 'clear':
            m.blank(True)
        else:
            m.set_highlight(int(sys.argv[1]))
            m.render()
    else:
        m.render()

    while True:
        sleep(1)
import utime as time
from machine import Pin

import ssd1306
# display setup
WIDTH = 128
HEIGHT = 64
clock = machine.Pin(2)
data = machine.Pin(3)
spi = machine.SPI(0, sck=clock, mosi=data)
CS = machine.Pin(1)
DC = machine.Pin(4)
RES = machine.Pin(5)
oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)

rotary = Rotary(16, 17, 22)
val = 0


def rotary_changed(change):
    global val
    oled.fill(0)
    oled.text('Rotery Encoder', 0, 0, 1)
    oled.text('Display Test', 0, 10, 1)
    if change == Rotary.ROT_CW:
        val = val + 1
        print(val)
        oled.text(str(val), 0, 30, 1)
    elif change == Rotary.ROT_CCW:
        val = val - 1
        print(val)
Exemplo n.º 5
0
from rotary import Rotary
import utime as time

rotary = Rotary(0, 1, 2)
val = 0


def rotary_changed(change):
    global val
    if change == Rotary.ROT_CW:
        val = val + 1
        print(val)
    elif change == Rotary.ROT_CCW:
        val = val - 1
        print(val)
    elif change == Rotary.SW_PRESS:
        print('PRESS')
    elif change == Rotary.SW_RELEASE:
        print('RELEASE')


rotary.add_handler(rotary_changed)

while True:
    time.sleep(0.1)
trigger = Pin(TRIGGER_PIN, Pin.OUT) # send trigger out to sensor
echo = Pin(ECHO_PIN, Pin.IN) # get the delay interval back
# create a Pulse Width Modulation Object on this pin
speaker = PWM(Pin(SPEAKER_PIN))

WIDTH = 128
HEIGHT = 64
clock=machine.Pin(2)
data=machine.Pin(3)
spi=machine.SPI(0,sck=clock, mosi=data)
CS = machine.Pin(1)
DC = machine.Pin(4)
RES = machine.Pin(5)
oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)

rotary = Rotary(ROTARY_A_PIN, ROTARY_B_PIN, ROTARY_BUTTON_PIN)

# our globals
mode = 0 # the program mode
mode_function = 0 # the function to change within a mode
function_value = 0 # the function value (usually a value of 0-to-5)
dist = 0
motor_power = MOTOR_POWER
motor_power_val = 2
turn_dist = TURN_DIST
turn_dist_val = 3
reverse_time = REVERSE_TIME
reverse_time_val = 3
turn_time = TURN_TIME
turn_time_val = 3
class PhotoboothController:
    def __init__(self, camera, output_path, app):
        self.output_path = output_path
        self.last_file_path = None
        self.app = app
        self.camera = camera
        self.camera_overlay = CameraOverlay(self.camera)
        self.printer = Printer()
        self.green_btn = Button(GREEN_BTN_PIN)
        self.red_btn = Button(RED_BTN_PIN)
        self.green_btn.when_pressed = self.pressed_capture_button
        self.red_btn.when_pressed = self.pressed_reject_print_button
        self.ui = UI(self.camera_overlay, camera.picam.resolution)
        self.image_helper = ImageHelper(camera.picam.resolution)
        self.rotary = Rotary(ROTARY_CLK_PIN, ROTARY_DT_PIN, upperBound=5)

        self.camera.show_preview(True)
        self.ui.show_main_screen()

        self.waiting_for_confirm = False
        self.busy = False

    def _reset_state(self):
        self.waiting_for_confirm = False
        self.busy = False
        self.rotary.clearCallback()
        self.rotary.resetCount()

    def pressed_capture_button(self):
        print("\ncapture")
        output_path = None
        if self.waiting_for_confirm:
            self.printer.printFile(self.last_file_path,
                                   copies=self.rotary.getValue())
            self.ui.clear_screen()
            self.ui.show_main_screen()
            self._reset_state()
        elif not self.busy:
            self.busy = True
            # show countdowns
            self.ui.clear_screen()
            self.ui.show_countdown()
            # flash lights
            # self._flash()
            # take photo
            self.last_file_path = self._capture()
            # confirm with user
            self._confirm_print(self.last_file_path)
            self.waiting_for_confirm = True

    def pressed_reject_print_button(self):
        if self.waiting_for_confirm:
            print("\nreject")
            self.last_file_path = None
            self.ui.clear_screen()
            self.ui.show_main_screen()
            self._reset_state()

    def _confirm_print(self, path):
        preview_image = self.image_helper.load_image(path)
        self.camera_overlay.add_overlay(preview_image)
        self.ui.show_confirm_screen(1)
        self.rotary.registerCallback(self.ui.update_confirm_screen)

    def _flash(self):
        pass
        #img = self.image_helper.create_flash_image()
        #self.camera_overlay.add_overlay(img)
        #time.sleep(0.2)register
        #self.camera_overlay.remove_top_overlay()

    def _capture(self):
        output_path = self._new_output_path()
        print("saving photo to " + output_path)
        self.camera.capture(output_path)
        return output_path

    def _new_output_path(self):
        output_path = self.output_path + "image-%d-%mT%H:%M.png"
        return strftime(output_path, gmtime())
Exemplo n.º 8
0
from machine import Pin
from rotary import Rotary
from time import sleep

# GPIO Pins 16 and 17 are for the encoder pins. 18 is the button press switch.
ENCODER_A = 16
ENCODER_B = 17
SWITCH = 18
rotary = Rotary(ENCODER_A, ENCODER_B, SWITCH)
val = 0


# this function is called whenever the rotory is changed
def rotary_changed(change):
    global val
    if change == Rotary.ROT_CW:
        val = val + 1
        print(val)
    elif change == Rotary.ROT_CCW:
        val = val - 1
        print(val)
    elif change == Rotary.SW_PRESS:
        print('PRESS')
    elif change == Rotary.SW_RELEASE:
        print('RELEASE')


rotary.add_handler(rotary_changed)

while True:
    sleep(0.1)
Exemplo n.º 9
0
def setup():
    loadingControl = None
    try:
        i2c = machine.I2C(-1, machine.Pin(22), machine.Pin(21))
        oled = ssd1306.SSD1306_I2C(128, 64, i2c)

        global ui_manager, zone_scheduler, aws_client, rtc_time

        import ui
        ui_manager = ui.UiManager(oled)
        loadingControl = ui.LoadingControl(ui_manager)
        ui_manager.goto(loadingControl)

        loadingControl.set_status("config")
        from sprinklerConfiguration import SprinklerConfiguration
        configurator = SprinklerConfiguration()
        configurator.load_config()
        ui_manager.configurator = configurator

        loadingControl.set_status("rtc")
        from rtcTime import RtcTime
        rtc_time = RtcTime()
        rtc_time.setup(i2c)
        ui_manager.rtc_time = rtc_time

        loadingControl.set_status("shiftr")
        from shiftR import ShiftR
        shiftR = ShiftR(shiftR_enable_pin, machine.Pin(14, machine.Pin.OUT),
                        machine.Pin(13, machine.Pin.OUT),
                        machine.Pin(27, machine.Pin.OUT),
                        configurator.get_zone_num())
        shiftR.setup()

        loadingControl.set_status("scheduler")
        from zoneScheduler import ZoneScheduler
        zone_scheduler = ZoneScheduler(configurator, shiftR)
        zone_scheduler.queue_changed_event.add_handler(
            lambda q: print('queue changed: {}'.format(q.serialise())))
        ui_manager.zone_scheduler = zone_scheduler

        loadingControl.set_status("server")
        import server
        server.enable_server(configurator, zone_scheduler)

        loadingControl.set_status("rotary")
        from rotary import Rotary
        rotary = Rotary(ui_manager)
        rotary.setup(rotary_sw_pin, rotary_cl_pin, rotary_dt_pin)

        loadingControl.set_status("ap")
        setup_ap()

        loadingControl.set_status("wifi")
        import wifiConnect
        wifiConnect.try_connect()

        loadingControl.set_status("aws")
        from awsClient import AwsClient
        temp_aws_client = AwsClient(configurator, zone_scheduler)
        temp_aws_client.setup()
        aws_client = temp_aws_client

        loadingControl.set_status("display")
        ui_manager.goto(ui.DashboardControl(ui_manager))

    except Exception as e:
        if loadingControl:
            loadingControl.set_detail(repr(e))
        sys.print_exception(e)
        raise
Exemplo n.º 10
0
from flask import Flask, jsonify, request
# from flask_socketio import SocketIO
from flask_cors import CORS
import json
import threading
import sys
import os
import time
import datetime
import requests
from subprocess import check_output

openweathermap_url = "https://api.openweathermap.org/data/2.5/forecast?q=kortrijk,BE&appid=5ab3cf66921da480525dffd751748008&units=metric&lang=nl"

# rotary encoder
rotary_encoder = Rotary()

# PIR sensor
pir = PIR(14)

# temperature sensor: name of the one-wire bus file
sensor_filename = "/sys/bus/w1/devices/28-0317977998cd/w1_slave"

# ledstrip (32 leds)
ledstrip = Ledstrip(16)

current_user = None

# flask
app = Flask(__name__)
# app.config['SECRET_KEY'] = 'S4cr4tK4y'