예제 #1
0
def GoPressed(pin):
    global time_stamp       # put in to debounce
    global debounce
    global PoweredOff
    global Scanning
    global Going
    global commandString

    time_now = time.time()
    if (time_now - time_stamp) >= debounce and PoweredOff==False and Scanning==False and Going==False:
        Going = True
        print("Go Button pressed")
        if (bFoundQR == True and commandString != ""):
            # Play a sound to show that we are scanning
            audio.playSound(10) # play start sound

            arduinoComms.parseCommandString(commandString)

            # Play sound that we found one
            audio.playSound(10)

            # Success GO operation, turn LED off and flag QR found as FALSE for next go
            GPIO.output(ledPinFoundQR, False)
            bFoundQR = False
            # Pass command to motor controller here
        else:
            print("No QR Found, scan again please")
        Going = False
    time_stamp = time_now
예제 #2
0
def HornPressed(pin):
    global time_stamp       # put in to debounce
    global debounce
    global PoweredOff
    global Scanning
    global Going
    global Horn
    time_now = time.time()
    if (time_now - time_stamp) >= debounce and PoweredOff==False and Scanning==False and Horn==False:
        Horn = True
        print("Horn Pressed")
        audio.playSound(11)
        Horn = False
    time_stamp = time_now
예제 #3
0
def ScanPressed(pin):
    global time_stamp       # put in to debounce
    global debounce
    global PoweredOff
    global Scanning
    global Going
    global camera
    global ledPinScanning
    global ledPinFoundQR
    global bFoundQR
    global commandString

    time_now = time.time()
    if (time_now - time_stamp) >= debounce and PoweredOff==False and Scanning==False and Going==False:
        # Play a sound to show that we are scanning
        audio.playSound(0)
        # Flag that we are scanning
        Scanning = True
        print("Scan Button pressed")
        # Call python script to try and find QR code from webcam image
        GPIO.output(ledPinScanning, True) # Turn on the "Scanning" LED
        GPIO.output(ledPinFoundQR, False) # Ensure Found QR LED OFF

        # Try to find a QR code from the camera.
        QRCode = qrscanner.FindQRCode(ledPinScanning, camera, 10)
        if (QRCode != ""):
            # Play sound that we found one
            audio.playSound(10)

            # Found a QR Code, Strip out the command portion of the string
            commandString = parseQR.parseOutCommand(QRCode)
            # Flag that we found a QR code
            bFoundQR = True
            # Ensure Found QR LED OFF
            GPIO.output(ledPinFoundQR, True)

        # Turn off the "Scanning" LED
        GPIO.output(ledPinScanning, False)
        Scanning = False
    time_stamp = time_now
예제 #4
0
def repeatSend(serial, commandChar, nSeconds, nInterval):
    # Send a single char repeatedly at a specific
    # interval for a specific length of time.
    # Have to play fireing sound here as it sounds as it lights LED
    if (commandChar == 'P'):
        # Play a sound to show that we are scanning
        audio.playSound(11)

    if (commandChar == 'Z'):
        # Uppercase 'Z' to turn LED ON
        print(commandChar)
        print(commandChar)
        print(commandChar)
        print(commandChar)
        print(commandChar)
        serial.write('Z')
        serial.write('Z')
        serial.write('Z')
        serial.write('Z')
        serial.write('Z')
        # Play sound
        audio.playSound(11)
        # Lowert case 'z' to turn LED OFF
        serial.write('z')
        serial.write('z')
        serial.write('z')
        serial.write('z')
        serial.write('z')
        print('z')
        print('z')
        print('z')
        print('z')
        print('z')
        sleep(0.3)
    else:
        while (nSeconds > 0.0):
            print(commandChar)
            serial.write(commandChar)
            sleep(nInterval)
            nSeconds = nSeconds - nInterval
예제 #5
0
    def track(self, frame, mask):
        """
        Track the position of the laser pointer.

        Code taken from
        http://www.pyimagesearch.com/2015/09/14/ball-tracking-with-opencv/
        """
        center = None

        countours = cv2.findContours(mask, cv2.RETR_EXTERNAL,
                                     cv2.CHAIN_APPROX_SIMPLE)[-2]

        self.bounds = []
        
        # only proceed if at least one contour was found
        if len(countours) > 0:
            # find the largest contour in the mask, then use
            # it to compute the minimum enclosing circle and
            # centroid
            c = max(countours, key=cv2.contourArea)
            ((x, y), radius) = cv2.minEnclosingCircle(c)
            moments = cv2.moments(c)
            if moments["m00"] > 0:
                center = int(moments["m10"] / moments["m00"]), \
                         int(moments["m01"] / moments["m00"])
            else:
                center = int(x), int(y)

            ## Create the bounds for cropping the frame
            if center[1]-60 < 0:
                y1 = 0
            else:
                y1 = center[1]-60

            if center[1]+20 > frame.shape[0]:
                y2 = frame.shape[0]
            else:
                y2 = center[1]+20

            if center[0]-150 < 0:
                x1 = 0
            else:
                x1 = center[0]-150

            if center[0]+150 > frame.shape[1]:
                x2 = frame.shape[1]
            else:
                x2 = center[0]+150

            ## Crop the frame for faster processing
            frame2 = frame[y1:y2, x1:x2]

            ## Get the bounds for the scanned words
            self.bounds = getBounds(frame2)

            ## Find the word closest to the laser
            word = getWord(self.bounds, center)

            ## Add the word to a list containing previously scanned words
            ## Count the occurances of the words, and print out the most
            ## occured word
            if word != "":
                ## Only keep the last 10 occurances of words
                if len(self.words) < 20:
                    self.words.append(word)
                else:
                    self.words.pop(0)
                    self.words.append(word)

                ## Count the last 10 word occurances
                word_counter = {}
                for w in self.words:
                    if w in word_counter:
                        word_counter[w] += 1
                    else:
                        word_counter[w] = 1

                ## Sort the words
                word = sorted(word_counter, key=word_counter.get, reverse=True)[0]
                if self.current_word != word:
                    self.current_word = word
                    playSound(word, "zh-tw")
                    
                for word in self.bounds:
                    word.top_left = (word.top_left[0]+x1, word.top_left[1]+y1)
                    word.bottom_right = (word.bottom_right[0]+x1, word.bottom_right[1]+y1)
예제 #6
0
def answerHandler(inputjson, username):

    l.log_start()  # logging
    obj = json.loads(inputjson)

    # When the mode is phone and player inputs exit phone
    if str(obj['mode']) == 'phone' and classifyMessage(
            str(obj['message'].lower()),
        {"exit": ["exit", "leave", "shut down", "close"]}) == "exit":
        answer = ('You stop looking at the bad quality of your phone.',
                  getRoomName(getRoomId(str(obj['room']))), 'game')

    # When the mode is phone
    elif str(obj['mode']) == 'phone':
        answer = [
            handleAnswer(str(obj['message'].lower()), username,
                         int(obj['level']), getRoomId(str(obj['room']))),
            getRoomName(getRoomId(str(obj['room']))), 'phone'
        ]

    # When the mode is gps and player inputs exit gps
    elif str(obj['mode']) == 'gps' and classifyMessage(
            str(obj['message'].lower()),
        {"exit": ["exit", "leave", "shut down", "close"]}) == "exit":
        answer = ('Your gps device is now turned off',
                  getRoomName(getRoomId(str(obj['room']))), 'game')

    # When the mode is gps
    elif str(obj['mode']) == 'gps':
        cur_room_id = getRoomId(str(obj['room']))
        gpsTriple = handleGPS(str(obj['message'].lower()), username,
                              int(obj['level']), getRoomId(str(obj['room'])))
        if cur_room_id == gpsTriple[1]:
            answer = [gpsTriple[0], getRoomName(gpsTriple[1]), gpsTriple[2]]
        else:
            answer = [
                gpsTriple[0] + "<br>" +
                get_gpt2_intro(getRoomIntroduction(gpsTriple[1]), username),
                getRoomName(gpsTriple[1]), gpsTriple[2]
            ]

    # When the mode is riddle
    elif str(obj['mode']) == 'riddle':
        answer = checkAnswer(str(obj['message'].lower()),
                             getRoomId(str(obj['room'])), username)
        answer[1] = getRoomName(answer[1])

    # When mode is game
    else:
        #l.log_time('remove_tables')
        #database.remove_unused_tables()
        answer = findAnswer(username, str(obj['message'].lower()),
                            getRoomId(str(obj['room'])))

    if writeMessagetoTrainingData(str(obj['message'])):
        print("added message to training data")
    else:
        print("added nothing to training data")

    #text to spreech if it is turned on in the setting @author Max Petendra
    if json.loads(database.get_settings_by_username(username))['readMessages']:
        audio.playSound(formatHTMLText(answer[0])[0:200])

    # json wird wieder zusammen gepackt
    l.log_time('end')  # logging
    l.log_end()  # logging

    #Check if a differnt sender is given
    if len(answer) <= 3: newSender = "bot"
    else: newSender = answer[3]

    database.update_user_room(username, getRoomId(answer[1]))

    #regular return statment
    return json.dumps({
        "level": 1,
        "sender": newSender,
        "room": answer[1],
        "items": [],
        "mode": answer[2],
        "message": answer[0]
    })