def cluc_game(message, *something):

    #Initialize lirc
    lirc.init("test05", blocking = False)
    disp_test01.print_disp("READY?","LEVEL 3")

    while True:
        codeIR = lirc.nextcode()
        if(codeIR != [] and codeIR[0] == "PLAY"):
            disp_test01.print_disp("GAME START!","")
            lirc.deinit()
            time.sleep(1)
            total_Number = 0
            for i in range(8):
                disp_Number = random.randint(1,100)
                total_Number = total_Number + disp_Number
                disp_test01.print_disp(str(disp_Number),"")
                time.sleep(0.7)
            disp_test01.print_disp("","")                
            file = open('/home/pi/teamB/SLACK_BOT_QUIZ.txt', 'w')  #書き込みモードでオープン
            file.write(str(total_Number))
            message.send("答えを入力してください")
            break
                
        else:
            time.sleep(3)
Beispiel #2
0
 def run(self):
     try:
         while (True):
             if (self.stopped()):
                 break
             list = lirc.nextcode()
             if len(list) != 0:
                 if list[0] == self.POWER:
                     self._on_power()
                 elif list[0] == self.INPUT:
                     self._on_menu()
                 elif list[0] == self.TREBLE_DOWN:
                     self._on_left()
                 elif list[0] == self.TREBLE_UP:
                     self._on_right()
                 elif list[0] == self.VOL_DOWN:
                     self._on_vol_down()
                 elif list[0] == self.VOL_UP:
                     self._on_vol_up()
                 elif list[0] == self.MUTE:
                     self._on_mute()
                 elif list[0] == self.BASS_DOWN:
                     self._on_preset(-1)
                 elif list[0] == self.BASS_UP:
                     self._on_preset(1)
             else:
                 time.sleep(0.1)
     except Exception as inst:
         logging.error(inst)
     lirc.deinit()
Beispiel #3
0
    def run(self):
        """Loop until main wants to exit."""

        # try:

        import lirc

        self.main.log.write(log.MESSAGE,
                            "[THREAD] Lirc socket starting...")

        conf = self.main.settings.defvars['PYBLASTER_LIRC_CONF']
        self.lircsock = lirc.init("pyblaster2", conf, blocking=False)

        while self.main.keep_run:
            # Nonblocking receive of IR signals
            read = lirc.nextcode()
            if len(read):
                self.queue_lock.acquire()
                self.queue.put(read[0])
                self.queue_lock.release()
            time.sleep(0.05)  # read each 50 ms

        lirc.deinit()

        self.main.log.write(log.MESSAGE,
                            "[THREAD] Lirc socket leaving...")
Beispiel #4
0
def cluc_game(level):

    #Initialize lirc
    lirc.init("test05", blocking = False)
    disp_util.print_disp("READY?","LEVEL "+level)

    while True:
        codeIR = lirc.nextcode()
        # PLAYを押すと処理を開始する
        if(codeIR != [] and codeIR[0] == "PLAY"):
            disp_util.print_disp("GAME START!","")
            lirc.deinit()
            time.sleep(1)
            total_Number = 0
            # 数字をランダムで数回表示し、その値を合算する
            for i in range(int(level)+2):
                disp_Number = random.randint(1,int(level)*int(level)*int(level)+8)
                total_Number = total_Number + disp_Number
                disp_util.print_disp(str(disp_Number),"")
                time.sleep(1.3-0.01*int(level)*int(level))
                disp_util.print_disp("","")
            disp_util.print_disp("","")                

            return str(total_Number)
               
        else:
            time.sleep(1)
Beispiel #5
0
    def start(self):
        while True:
            c = lirc.nextcode()

            if len(c) != 0:
                self.current['dockSignal']['time'] = time.time()

                if c[0] == "power":
                    # consider sending Shutdown here
                    break
                if c[0] == "left_signal":
                    self.current['dockSignal']['left'] = 1
                elif c[0] == "right_signal":
                    self.current['dockSignal']['right'] = 1
                self.subscriber(self.current)
            else:
                t = time.time()
                if t - self.current['dockSignal']['time'] > self.timeToLive:
                    if self.current['dockSignal']['left'] == 1 or \
                            self.current['dockSignal']['right'] == 1:
                        self.current['dockSignal']['time'] = time.time()
                        self.current['dockSignal']['left'] = 0
                        self.current['dockSignal']['right'] = 0
                        self.subscriber(self.current)

            time.sleep(self.sampleInterval)

        lirc.deinit()
        return
Beispiel #6
0
def main():

    while True:
        try:
            print("LIRC Init:")
            lirc.init(lirc_client)
            print("Find Sonos:")
            get_sonos(True)

            while True:
                print("Waiting for IR press")
                codes = lirc.nextcode()
                print("Got code: ", codes)
                for code in codes:
                    print("Key press: ", code)
                    if code in switcher.keys():
                        func = switcher.get(code)
                        func()

        except Exception as e:
            print("Exception:")
            print(e)
            pass

        lirc.deinit()
Beispiel #7
0
 def key_pressed(self, key):
     if key == 'KEY_PLAYPAUSE':
         self.execute(['/usr/bin/mpc', 'toggle'])
     elif key == 'KEY_VOLUMEUP':
         self.execute(['/usr/bin/mpc', 'volume', '+5'])
     elif key == 'KEY_VOLUMEDOWN':
         self.execute(['/usr/bin/mpc', 'volume', '-5'])
     elif key == 'KEY_PREVIOUS':
         self.execute(['/usr/bin/mpc', 'prev'])
     elif key == 'KEY_NEXT':
         self.execute(['/usr/bin/mpc', 'next'])
     elif key == 'KEY_F1':
         self.execute([os.path.join(BASE_DIR, 'screen.sh'), 'on'])
     elif key == 'KEY_F2':
         self.execute([os.path.join(BASE_DIR, 'screen.sh'), 'off'])
     elif key == 'KEY_HOME':
         self.execute(['/usr/bin/mpc', 'shuffle'])
     elif key == 'KEY_MODE':
         self.play_sound('shutdown')
         self.execute(['sudo', 'shutdown', '-h', 'now'])
         lirc.deinit()
         sys.exit(0)
     elif key == 'KEY_CHANNELDOWN':
         i = self.playlist_index - 1
         if i >= 0:
             self.load_playlist(i)
     elif key == 'KEY_CHANNELUP':
         i = self.playlist_index + 1
         if i <= 9:
             self.load_playlist(i)
     elif key in ('KEY_0', 'KEY_1', 'KEY_2', 'KEY_3', 'KEY_4', 'KEY_5', 'KEY_6', 'KEY_7', 'KEY_8', 'KEY_9'):
         self.load_playlist(int(key[4]))
     else:
         logger.info('Received unbinded key: %s', key)
Beispiel #8
0
 def deactivate(self):
     """When deactivated the :class:`IREventListener` will not run
     anything.
     """
     self.event_queue.put(self.TERMINATE_SIGNAL)
     self.dispatcher.join()
     self.detector.terminate()  # maybe use a message queue instead?
     lirc.deinit()
Beispiel #9
0
 def deactivate(self):
     """When deactivated the :class:`IREventListener` will not run
     anything.
     """
     self.event_queue.put(self.TERMINATE_SIGNAL)
     self.dispatcher.join()
     self.detector.terminate()  # maybe use a message queue instead?
     lirc.deinit()
Beispiel #10
0
def main():
    loop = True
    try:
        while loop:
            code = lirc.nextcode()
            if len(code) == 0:
                continue

            if code[0] in g_keypress_mappings:
                g_keypress_mappings[code[0]](code[0])
            else:
                print "Unknown command %s" % (code[0])
    except KeyboardInterrupt:
        print "Received keyboard interrupt..."
    finally:
        lirc.deinit()  # free up resources
Beispiel #11
0
def main():
    loop = True
    try:
        while loop:
            code = lirc.nextcode()
            if len(code) == 0:
                continue

            if code[0] in g_keypress_mappings:
                g_keypress_mappings[code[0]](code[0])
            else:
                print "Unknown command %s"%(code[0])
    except KeyboardInterrupt:
        print "Received keyboard interrupt..."
    finally:
        lirc.deinit() # free up resources
Beispiel #12
0
 def run(self):
     while True:
         try:
             button = lirc.nextcode()
             if len(button) != 0:
                 if (button[0]) == 'turn_on_alarm':
                     self.logger.info("IR_Remote: encender alarma")
                     self.bot_manager.activar_sistema()
                 elif (button[0]) == 'turn_off_alarm':
                     self.logger.info("IR_Remote: apagar alarma")
                     self.bot_manager.desactivar_sistema()
                 else:
                     pass
             time.sleep(1)
         except KeyboardInterrupt:
             lirc.deinit()
             break
Beispiel #13
0
 def main(fullscreen):
     pygame.init()
     lirc_socket = None
     if HAS_LIRC:
         lirc_socket = lirc.init("pySmartMirror",
                                 config_filename=os.path.join(assets_path, "lircrc"),
                                 blocking=False)
     ml = MainLoop(fullscreen=fullscreen)
     try:
         ml.main_loop(lirc_socket)
     finally:
         if HAS_LIRC:
             lirc.deinit()
         ml.hw.deinit()
         for m in ml.modes:
             m.deinit()
         pygame.quit()
Beispiel #14
0
 def run(self):
     """Main loop of LIRC interface thread."""
     print("LIRC interface thread started")
     while not self.stopped.isSet():
         try:
             code = lirc.nextcode()  # list; empty if no buttons pressed
         except lirc.NextCodeError:
             print("Error reading next code from LIRC")
             code = None
         # interpret result from python-lirc
         if code:
             code = code[0]
             self.the_queue.put(code)
         else:
             time.sleep(0.2)
     lirc.deinit()
     print('LIRC interface thread stopped')
Beispiel #15
0
 def run(self):
     """Run the loop of the LIRC interface thread."""
     _LOGGER.debug("LIRC interface thread started")
     while not self.stopped.isSet():
         try:
             code = lirc.nextcode()  # list; empty if no buttons pressed
         except lirc.NextCodeError:
             _LOGGER.warning("Error reading next code from LIRC")
             code = None
         # interpret result from python-lirc
         if code:
             code = code[0]
             _LOGGER.info("Got new LIRC code %s", code)
             self.hass.bus.fire(EVENT_IR_COMMAND_RECEIVED, {BUTTON_NAME: code})
         else:
             time.sleep(0.2)
     lirc.deinit()
     _LOGGER.debug("LIRC interface thread stopped")
Beispiel #16
0
    def run(self):
        """

        """
        #if not self.main.settings.use_lirc:
        #    return

        self.lircsock = lirc.init("pyblaster", "/root/.lircrc",
                                  blocking=False)

        while self.main.keep_run:
            read = lirc.nextcode()
            if len(read):
                self.queue_lock.acquire()
                self.queue.put(read[0])
                self.queue_lock.release()
            time.sleep(0.05)  # read each 50 ms

        lirc.deinit()
Beispiel #17
0
    def run(self):

        while self.killMe == False:

            self.tSC.Update()
            self.Update()
            if self.tSC.changeSecond:

                # Check the if there is at least an element
                # in `self.irReceivedDuringInterval` array.
                if len(self.irReceivedDuringInterval) > 0:

                    #print(self.irReceivedDuringInterval)

                    self.iDB.mainArray.append(
                        self.SetupStringForDatabase(
                            self.irReceivedDuringInterval))
                    del self.irReceivedDuringInterval[:]

        if self.killMe == True: lirc.deinit()
Beispiel #18
0
 def run(self):
     """Run the loop of the LIRC interface thread."""
     import lirc
     _LOGGER.debug("LIRC interface thread started")
     while not self.stopped.isSet():
         try:
             code = lirc.nextcode()  # list; empty if no buttons pressed
         except lirc.NextCodeError:
             _LOGGER.warning("Error reading next code from LIRC")
             code = None
         # interpret result from python-lirc
         if code:
             code = code[0]
             _LOGGER.info("Got new LIRC code %s", code)
             self.hass.bus.fire(
                 EVENT_IR_COMMAND_RECEIVED, {BUTTON_NAME: code})
         else:
             time.sleep(0.2)
     lirc.deinit()
     _LOGGER.debug('LIRC interface thread stopped')
Beispiel #19
0
    def run(self):
        self.__flagstop__ = False
        logger.info("Starting IR Input...")
        try:
            sockid = lirc.init("rpicenter", blocking=False)

            while True:
                if self.__flagstop__:
                    lirc.deinit()
                    return
                try:
                    codeIR = lirc.nextcode()
                    if codeIR:
                        action = codeIR[0]
                        logger.debug("IR Input Received: " + action)
                        if (self.__callback__ != None):
                            for cb in self.__callback__:
                                if cb != None:
                                    try:
                                        #find the command from the dict
                                        command = self.__remote_command__.get(
                                            action, "Empty")
                                        logger.debug("IR Remote Command: " +
                                                     str(command))

                                        if command != "Empty":
                                            cb(msg=command, input=self)
                                    except Exception as ex:
                                        logger.error("IR Input Error: " +
                                                     str(ex),
                                                     exc_info=True)
                                        raise
                except Exception as ex:
                    logger.error("IR Input Error: " + str(ex), exc_info=True)
                    raise
        except KeyboardInterrupt:
            logger.debug("Shutdown requested...exiting IR")
            raise
Beispiel #20
0
    def repeatThis():
        dc = 0  # set dc variable to 0 for 0%
        pwm.start(dc)

        try:
            # Loop until Ctl C is pressed to stop.
            for dc in range(100, -5,
                            -5):  # Loop 0 to 100 stepping dc by 5 each loop
                pwm.ChangeDutyCycle(dc)
                time.sleep(0.05)
                # wait .05 seconds at current LED brightness

        except KeyboardInterrupt:
            print("Ctrl c to exit program")

        messageTwo = "valkirie hit"

        clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        host = socket.gethostname

        port = 50000

        clientsocket.connect(('192.168.1.19', port))
        message = clientsocket.recv(1024)
        clientsocket.send(messageTwo.encode('ascii'))

        print("\nPress Ctl C to quit \n"
              )  # Print blank line before and after message.
        pwm.start(0)
        try:
            # Loop until Ctl C is pressed to stop.
            for dc in range(0, 100,
                            5):  # Loop 0 to 100 stepping dc by 5 each loop
                pwm.ChangeDutyCycle(dc)
                time.sleep(0.05)  # wait .05 seconds at current LED brightness

        except KeyboardInterrupt:
            print("Ctr C to close program")

        print(message.decode('ascii'))

        sockid = lirc.init("myprogram")

        lirc.nextcode()

        three = ''.join(lirc.nextcode()).replace("[|]", "")

        print(three)

        print('sent')

        pygame.mixer.init()
        pygame.init()
        pygame.mixer.music.load('getHit.mp3')
        pygame.mixer.music.play()

        clientsocket.send(three.encode('ascii'))
        clientsocket.send(messageTwo.encode('ascii'))
        number = clientsocket.recv(1024)
        print(number)

        lirc.deinit()
        # stop PWM
        try:
            for dc in range(
                    100, -5,
                    -5):  # Loop 95 to 5 stepping dc down by 5 each loop
                pwm.ChangeDutyCycle(dc)
                time.sleep(0.05)  # wait .05 seconds at current LED brightness
                print(dc)

        except KeyboardInterrupt:
            print("Ctr C to close program")

        time.sleep(10)

        pygame.mixer.init()
        pygame.init()
        pygame.mixer.music.load('revive.mp3')
        pygame.mixer.music.play()

        print('rebooted')
Beispiel #21
0
    def repeatThis():
        ledFreq = 0
        ##        while ledFreq < 255:
        ##            ledFreq += 1
        ##            pi.set_PWM_dutycycle(18, ledFreq)
        ##            time.sleep(0.01)
        ##            print(ledFreq)
        ##            if ledFreq == 255:
        ##                break
        ##        while ledFreq != 0:
        ##            ledFreq -= 1
        ##            pi.set_PWM_dutycycle(18, ledFreq)
        ##            time.sleep(0.01)
        ##            print(ledFreq)

        pygame.mixer.init()
        pygame.init()
        pygame.mixer.music.load('poweringUpSound.mp3')
        pygame.mixer.music.play()

        while ledFreq < 255:
            ledFreq += 1
            pi.set_PWM_dutycycle(18, ledFreq)
            time.sleep(0.01)
            print(ledFreq)
            if ledFreq == 255:
                break
        sockid = lirc.init("myprogram")

        lirc.nextcode()

        three = ''.join(lirc.nextcode()).replace("[|]", "")

        print(three)

        print('sent')

        pygame.mixer.init()
        pygame.init()
        pygame.mixer.music.load('getHit.mp3')
        pygame.mixer.music.play()

        clientsocket.send(three.encode('ascii'))
        clientsocket.send(messageTwo.encode('ascii'))

        while ledFreq != 0:
            ledFreq -= 1
            pi.set_PWM_dutycycle(18, ledFreq)
            time.sleep(0.001)
            print(ledFreq)
            if ledFreq == 0:
                break

        number = clientsocket.recv(1024)
        print(number)

        lirc.deinit()

        time.sleep(10)

        pygame.mixer.init()
        pygame.init()
        pygame.mixer.music.load('revive.mp3')
        pygame.mixer.music.play()

        print('rebooted')
Beispiel #22
0
 def shutdown(self):
     src.logger.logInfo("Deinitializing IRInterface...")
     if lircinstalled:
         lirc.deinit()
     src.logger.logOk("IRInterface deinitalized.")
Beispiel #23
0
def signal_term_handler(signal, frame=""):
    log.info("Got " + str(signal))
    log.info("Closing lirc connection")
    lirc.deinit()
    log.info("So long, sucker!")
    sys.exit(0)
Beispiel #24
0
def teardown():
  lirc.deinit()
Beispiel #25
0
 def exit_menu():
     lirc.deinit()
     watch_proc.terminate()
     sys.exit()
Beispiel #26
0
 def tearDown(self):
     lirc.deinit()
Beispiel #27
0
 def __del__(self):
     lirc.deinit()
 def com_lirc_close(self):
     lirc.deinit()
Beispiel #29
0
import lirc
import time
import RPi.GPIO as GPIO
print "Setting up GPIO"
LED_PIN = 17 
GPIO.setmode(GPIO.BCM)
GPIO.setup(LED_PIN, GPIO.OUT)
GPIO.output(LED_PIN, True)


sockid = lirc.init("rcled", blocking=False)
while True:
    try:
        button = lirc.nextcode()
        print("Press RC button , die geconfigureerd staat in etc/lirc/lircrc!")
        GPIO.output(LED_PIN, True)
        if len(button) == 0: continue
        print(button[0])
        print (len(button))
        GPIO.output(LED_PIN, False)
        
        time.sleep(1)
    except KeyboardInterrupt:
        lirc.deinit()
        break
Beispiel #30
0
    def done(self):
        """ """
###########################################################################
        if sys.platform == "linux":  # Only for Raspberry Pi
            lirc.deinit()
Beispiel #31
0
import lirc

sockid = lirc.init("myprogram")
# lirc.load_config_file("/root/lircd.conf")
lirc.nextcode()  # press 1 on remote after this
lirc.deinit()
Beispiel #32
0
 def lirc_process(q):
     filename = get_asset_filename('lircrc')
     lirc.init('nr_view', filename, verbose=True)
     while True:
         q.put(lirc.nextcode())
     lirc.deinit()