Exemplo n.º 1
0
    def __init__(self):
        self.switch_port = SwitchPort(self)
        self.switches = [Switch(i, self)
                         for i in range(pifacecad.NUM_SWITCHES)]
        self.lcd = PiFaceLCD(self)

        try:
            cad = pifacecad.PiFaceCAD()
        except (pifacecommon.spi.SPIInitError,
                pifacecad.core.NoPiFaceCADDetectedError) as e:
            print("Error initialising PiFace CAD: ", e)
            print("Running without PiFace CAD.")
            cad = None

        self.proc_comms_q_to_em = Queue()
        self.proc_comms_q_from_em = Queue()

        emulator_sync = Barrier(2)
        # start the gui in another process
        self.emulator = Process(target=run_emulator,
                                args=(sys.argv,
                                      cad,
                                      self.proc_comms_q_to_em,
                                      self.proc_comms_q_from_em,
                                      emulator_sync))
        self.emulator.start()
Exemplo n.º 2
0
 def __init__(self):
     self.cad = pifacecad.PiFaceCAD()
     self.cad.lcd.blink_off()
     self.cad.lcd.backlight_on()
     self.hide_cursor()
     self.width = 16
     self.height = 2
Exemplo n.º 3
0
def initPiFace():
    global cad
    global listener
    global actionHandler
    global gEndBarrier

    if gEndBarrier != None:
        gEndBarrier.wait()
        listener.deactivate()
        del gEndBarrier
        del listener
        gEndBarrier = None
        listener = None

    if cad != None:
        del cad
        cad = None

    gEndBarrier = threading.Barrier(2)
    cad = pifacecad.PiFaceCAD()
    cad.lcd.backlight_on()
    printToLCD('starter v.1.0', 'select file')
    time.sleep(2)

    updateDisplayFiles()

    listener = pifacecad.SwitchEventListener(chip=cad)
    for i in range(8):
        h = actionHandler.get(i, printEvent)
        listener.register(i, pifacecad.IODIR_FALLING_EDGE, h)
    listener.activate()
Exemplo n.º 4
0
def start_camera(start_mode='camera'):
    cad = pifacecad.PiFaceCAD()

    switchlistener = pifacecad.SwitchEventListener(chip=cad)
    switchlistener.register(0, pifacecad.IODIR_ON, next_mode)
    switchlistener.register(1, pifacecad.IODIR_ON, option1)
    switchlistener.register(2, pifacecad.IODIR_ON, option2)
    switchlistener.register(3, pifacecad.IODIR_ON, option3)
    # switchlistener.register(4, pifacecad.IODIR_ON, exit)
    switchlistener.register(5, pifacecad.IODIR_ON, take_picture)
    switchlistener.register(6, pifacecad.IODIR_ON, previous_option)
    switchlistener.register(7, pifacecad.IODIR_ON, next_option)

    cad.lcd.display_off()
    cad.lcd.blink_off()
    cad.lcd.cursor_off()
    cad.lcd.clear()
    cad.lcd.backlight_on()

    splash_screen(cad)

    global camera
    camera = Camera(cad, start_mode)
    camera.current_mode['option'].enter()
    camera.update_display()
    cad.lcd.display_on()

    global should_i_exit
    should_i_exit = threading.Barrier(2)
    switchlistener.activate()
    should_i_exit.wait()
    switchlistener.deactivate()
    cad.lcd.clear()
    cad.lcd.backlight_off()
    print("Good-bye!")
Exemplo n.º 5
0
    def __init__(self, *args, **kwargs):
        """Intitializer function"""
        logging.debug("Initializing the interface.")
        self.cad = pifacecad.PiFaceCAD()
        self.current_page = 1
        self.pages = {1: self.show_time, 2: self.show_stats, 3: self.show_ip}
        logging.debug("Polling for inputs!")
        self.last_page = self.current_page
        # five minute cache
        self.cached_dict = expiringdict.ExpiringDict(max_len=100,
                                                     max_age_seconds=300)

        self.listener = pifacecad.SwitchEventListener(chip=self.cad)
        self.scheduler = BackgroundScheduler()
        self.scheduler.start()
        self.scheduler.add_job(self.update,
                               "interval",
                               seconds=10,
                               id="update_job")
        for i in range(6):
            self.listener.register(i, pifacecad.IODIR_FALLING_EDGE,
                                   logging.debug)

        self.listener.register(6, pifacecad.IODIR_FALLING_EDGE, self.page_left)
        self.listener.register(7, pifacecad.IODIR_FALLING_EDGE,
                               self.page_right)
        self.update()
        logging.debug("Activating the listener.")
        self.listener.activate()
Exemplo n.º 6
0
 def __init__(self):
     """Initialises the ``InputDevice`` object and starts ``pifacecad.SwitchEventListener``. Also, registers callbacks to ``press_key`` method. """
     self.cad = pifacecad.PiFaceCAD()
     self.listener = pifacecad.SwitchEventListener(chip=self.cad)
     for i in range(8):
         self.listener.register(i, pifacecad.IODIR_FALLING_EDGE,
                                self.press_key)
     self.listener.activate()
     atexit.register(self.atexit)
Exemplo n.º 7
0
def write(data):
    cad = pifacecad.PiFaceCAD()
    cad.lcd.set_cursor(0, 0)
    cad.lcd.clear()
    cad.lcd.write(data)
    if len(data) >= 16:
        cad.lcd.set_cursor(0, 1)
        cad.lcd.write(data[16:])
    print data
Exemplo n.º 8
0
    def __init__(self, cdDrive, outputPath, timeout, cad):
        self.cdDrive = cdDrive
        self.outputPath = outputPath
        self.timeout = timeout
        self.cdDrive.init()

        # set up cad
        cad = pifacecad.PiFaceCAD()
        cad.lcd.blink_off()
        cad.lcd.cursor_off()
        cad.lcd.backlight_on()
        self.cad = cad
Exemplo n.º 9
0
    def __init__(self, mycall):
        self.listener = pifacecad.SwitchEventListener()
        self.listener.register(0, pifacecad.IODIR_ON, self.grab_and_transmit)
        self.listener.activate()

        self.cad = pifacecad.PiFaceCAD()
        self.mycall = mycall
        self.active = False
        self.cad.lcd.clear()
        self.theircall = "PA0NUL"
        self.cad.lcd.write("SSTVCam " + self.mycall)
        self.cad.lcd.backlight_on()
        self.cad.lcd.cursor_off()
        self.cad.lcd.blink_off()
Exemplo n.º 10
0
    def init(self, revision=2):
        # LED outputs
        self.cad = pifacecad.PiFaceCAD()
        # set up cad
        #self.self.cad = cad
        self.cad.lcd.blink_off()
        self.cad.lcd.cursor_off()
        self.cad.lcd.backlight_on()

        self.cad.lcd.store_custom_bitmap(PLAY_SYMBOL_INDEX, PLAY_SYMBOL)
        self.cad.lcd.store_custom_bitmap(PAUSE_SYMBOL_INDEX, PAUSE_SYMBOL)
        self.cad.lcd.store_custom_bitmap(INFO_SYMBOL_INDEX, INFO_SYMBOL)
        #		self.self.cad = self.cad
        return
Exemplo n.º 11
0
    def __init__(self, server):
        self.events = server
        self.cad = pifacecad.PiFaceCAD()

        self.cad.lcd.set_cursor(3, 0)
        self.cad.lcd.write("started")

        self.cad.lcd.blink_off()
        self.cad.lcd.backlight_on()

        self.switchlistener = pifacecad.SwitchEventListener(chip=self.cad)
        for x in range(8):
            self.switchlistener.register(x, pifacecad.IODIR_ON, self.test)
        self.switchlistener.activate()
Exemplo n.º 12
0
    def __init__(self, rows=2, cols=16):
        """Initialises the ``Screen`` object.  
                                                                               
        Kwargs:

           * ``rows`` (default=2): rows of the connected display
           * ``cols`` (default=16): columns of the connected display

        """
        self.rows = rows
        self.cols = cols
        self.lcd = pifacecad.PiFaceCAD().lcd
        self.backlight = True
        self.busy_flag = False
Exemplo n.º 13
0
    def init(self,callback=None,code_page=0):
        self.code_page = code_page # TO BE IMPLEMENTED
        # LED outputs
        self.cad = pifacecad.PiFaceCAD()
        # set up cad
        self.event = callback   
        self.cad.lcd.blink_off()
        self.cad.lcd.cursor_off()
        self.cad.lcd.backlight_on()

        self.cad.lcd.store_custom_bitmap(PLAY_SYMBOL_INDEX, PLAY_SYMBOL)
        self.cad.lcd.store_custom_bitmap(PAUSE_SYMBOL_INDEX, PAUSE_SYMBOL)
        self.cad.lcd.store_custom_bitmap(INFO_SYMBOL_INDEX, INFO_SYMBOL)
        return
Exemplo n.º 14
0
    def __init__(self, format, custom_values=None, cad=None):
        if cad is None:
            cad = pifacecad.PiFaceCAD()
            cad.lcd.backlight_on()
            cad.lcd.cursor_on()
            cad.lcd.display_off()  # don't want to see slow printing
            self.custom_cad = False
        else:
            self.custom_cad = True

        self.start_offset = cad.lcd.get_cursor()
        self.cad = cad
        self.display_string = ValueSelectString(format, custom_values)
        self.mode = self.ScanfMode.select
        self.wait_for_return_string = None
Exemplo n.º 15
0
    def __init__(self, question, answers, selector=">", cad=None):
        self.question = question
        self.answers = answers
        self.selector = selector

        if cad is None:
            cad = pifacecad.PiFaceCAD()
            cad.lcd.backlight_on()
            cad.lcd.blink_off()
            cad.lcd.cursor_off()
            cad.lcd.display_off()  # don't want to see slow printing

        self.cad = cad

        self._displayed_answer_index = 0
        self.wait_for_return_string = None
Exemplo n.º 16
0
    def connect(self):
        # Define the CAD board
        try:
            self.__cad = pifacecad.PiFaceCAD()
        except Exception as e:
            # No CAD board found
            return -1

        # Save my pretty custom bitmaps to the memory (max 8 allowed)
        self.__cad.lcd.store_custom_bitmap(self.__temp_symbol_index,
                                           self.__temperature_symbol)

        # Start up the screen
        self.__on = False

        return 1
Exemplo n.º 17
0
 def __init__(self, config):
     """
     Constructor
     :param config: instance of MediaPlayerConfig class
     """
     self._config = config
     self._cad = pifacecad.PiFaceCAD()
     self._cad.lcd.blink_off()
     self._cad.lcd.cursor_off()
     self._media_player = None
     self._switch_listener = None
     self._ir_listener = None
     self._temp_text = None
     self._temp_text_Timer = None
     self._listeners_barrier = None
     self._listeners_wait_for_deactivation_thread = None
     self._write_info_thread = None
Exemplo n.º 18
0
 def __init__(self):
     self.len_of_screen = 16
     self.txt_speed = 0.05
     self.txt_speed_start = 0.8
     self.num_of_pins = 8
     self.set_cities()
     self.cad = pifacecad.PiFaceCAD()
     self.cad.lcd.backlight_on()
     self.cad.lcd.cursor_off()
     self.cad.lcd.blink_off()
     self.city = "Luebeck"
     self.weather = weather_api.weather(self.cities[self.city][0],
                                        self.cities[self.city][1])
     self.spiegel = news_api.spiegel_news()
     self.spiegel_headlines = self.spiegel.get_headlines()
     self.loop_index_weather = 0
     self.loop_index_news = 0
     self.loop_index_cities = 0
     self.turn_off_counter = 0
     self.cad.lcd.write("CAD Ready")
Exemplo n.º 19
0
def main():

    global cad
    cad = pifacecad.PiFaceCAD()

    broker = "192.168.3.14"
    port = 1883

    mypid = os.getpid()
    sub_uniq = "subclient_" + str(mypid)
    mqtts = mosquitto.Mosquitto(sub_uniq)
    mqtts.on_message = on_message

    mqtts.connect(broker, port, 60, True)
    mqtts.subscribe("test/lcd", 0)

    rc = 0
    while rc == 0:
        rc = mqtts.loop()

    return 0
Exemplo n.º 20
0
    def __init__(self):
        self.cad = pifacecad.PiFaceCAD()
        self.cad.lcd.backlight_on()
        self.authMode = 1  # 0 => Safe code / 1 => 1st auth / 2 => 2nd auth
        self.lockCode = [1, 1, 1, 1]  # First auth code
        self.authCode = [0, 0, 0, 0]
        self.lockNumbers = [0, 0, 0, 0]
        self.end_barrier = Barrier(
            2)  # Create two barriers to hold up the threads
        self.errCounter = 0
        self.lockingCounter = 0

        self.cad.lcd.set_cursor(0, 0)
        self.lockStatus = "Locked"
        self.write_display("Status: {}".format(self.lockStatus), cursor_row=0)
        self.write_display(self.lockNumbers, cursor_row=1, input_code=True)

        self.server = 'smtp.gmail.com'
        self.sender = '*****@*****.**'
        self.passwd = 'pxxlkdhmbngmtwrs'
        self.receiver = '*****@*****.**'

        self.port = 587
Exemplo n.º 21
0
def time_now():
    cad.lcd.clear()
    global now
    now = datetime.now()
    cad.lcd.set_cursor(0, 0)
    cad.lcd.write(now.strftime("%m/%d %a %H:%M "))


def weather_print(k):
    cad.lcd.clear()
    cad.lcd.write(City[k])
    cad.lcd.set_cursor(0, 1)
    cad.lcd.write(weather_[k])


cad = pifacecad.PiFaceCAD()
cad.lcd.backlight_on()
cad.lcd.cursor_off()

City = [
    'Harbin,CN', 'Tokyo,JP', 'Seoul,KR', 'Bangkok,TH', 'Vancouver,CA',
    'Paris,FR'
]
mykey = 'fbfe70688650a2d288b6cceba3812496'
owm = OWM(mykey)
mgr = owm.weather_manager()
weather_ = ['0', '0', '0', '0', '0', '0']
for i in range(6):
    obs = mgr.weather_at_place(City[i])
    weather = obs.weather
    weather_[i] = weather.status
Exemplo n.º 22
0
 def setUp(self):
     self.cad = pifacecad.PiFaceCAD()
     self.cad.lcd.set_cursor(1, 1)
Exemplo n.º 23
0
#!/usr/bin/python3
import snapcamera
import argparse
import pifacecad


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('--clear', help='Clears the LCD.', action='store_true')
    parser.add_argument('--mode', help='Mode to start in.', choices=[
        'camera',
        'effects',
        'overlay',
        'timelapse',
        'ir',
        'network',
        'viewer'])
    args = parser.parse_args()
    if args.clear:
        cad = pifacecad.PiFaceCAD(init_board=False)
        cad.lcd.display_off()
        cad.lcd.clear()
        cad.lcd.backlight_off()
    elif args.mode:
        #---------------------------------------------------------------
        # MAKE SURE YOU UPDATE snapcampera/camera.py WHEN YOU CHANGE THE MODES
        snapcamera.start_camera(args.mode)
        #---------------------------------------------------------------
    else:
        snapcamera.start_camera()
Exemplo n.º 24
0
 def setup(self):
     super().setup()
     self._pi_face = pifacecad.PiFaceCAD()
Exemplo n.º 25
0
 def setUp(self):
     self.cad = pifacecad.PiFaceCAD()
Exemplo n.º 26
0
    for x in range(0, len(postStringArray)):
        try:
            p = requests.post(postStringArray[x])
            postStringArray.remove(postStringArray[x])
            print(p.text)
            cad.lcd.write(str(p.status_code))
        except requests.exceptions.RequestException as e:
            print("A connection error occured")
            cad.lcd.clear()
            cad.lcd.set_cursor(0, 0)
            cad.lcd.write("\Conn.Err.")
            cad.lcd.write("\nTry again")
            print(postStringArray)
    print_instructions()
    print_instructions_rasperry()


postStringArray = []
cad = pifacecad.PiFaceCAD()  # display
cad.lcd.backlight_on()  # Hintergrundbeleuchtung
cad.lcd.set_cursor(0, 0)  # set the cursor to the initial position
listener = pifacecad.SwitchEventListener(chip=cad)
listener.register(0, pifacecad.IODIR_FALLING_EDGE, qr_reader)
listener.register(2, pifacecad.IODIR_FALLING_EDGE, finish_aplication)
listener.register(3, pifacecad.IODIR_FALLING_EDGE, presented)
listener.register(4, pifacecad.IODIR_FALLING_EDGE, not_presented)
listener.register(1, pifacecad.IODIR_FALLING_EDGE, push_offline)
listener.activate()
print_instructions_rasperry()
print_instructions()
Exemplo n.º 27
0
 def __init__(self):
     """Initialises the ``InputDevice`` object and starts ``pifacecad.SwitchEventListener``. Also, registers callbacks to ``press_key`` method. """
     self.cad = pifacecad.PiFaceCAD()
Exemplo n.º 28
0
 def __init__(self, word):
     self.cad = pifacecad.PiFaceCAD()
     self.hangman = Hangman(self.cad)
     self.word = word
     self.correct_guesses = list()
Exemplo n.º 29
0
 def __init__(self):
     self.cad = pifacecad.PiFaceCAD()
     self.lcd = self.cad.lcd
     self.lcd.backlight_on()
     self.lcd.blink_off()
     self.get_word_of_the_day()
Exemplo n.º 30
0
                nextStationUrl = value
                nextStation = key
                break

            if key == currentStation:
                found = True

        player.stop()
        currentStation = nextStation
        player.load(nextStationUrl)
        player.play()

        print(currentStation)


piface = pifacecad.PiFaceCAD()  # initialize a PiFace Control and Display board

# basic buttuns handling
listener = pifacecad.SwitchEventListener(chip=piface)

#for i in range(1,8):
#    listener.register(i, pifacecad.IODIR_FALLING_EDGE, update_pin_text)

listener.register(0, pifacecad.IODIR_FALLING_EDGE, play_mp3)
listener.register(1, pifacecad.IODIR_FALLING_EDGE, play_radio)

listener.register(6, pifacecad.IODIR_FALLING_EDGE, previousAction)
listener.register(7, pifacecad.IODIR_FALLING_EDGE, nextAction)

listener.activate()