Esempio n. 1
0
def get_ack():
    lcd.lcd_clear()
    lcd.lcd_string('waiting for ack', 0)
    data = ser_port.readline()
    if len(data) > 0 and data == b'Done\n':
        lcd.lcd_clear()
        lcd.lcd_string('ack recieved', 0)
        return
Esempio n. 2
0
def main():
    d = identify.Identify()
    lcd.lcd_init()

    if d == -1:
        lcd.lcd_print("No Face Found")
        time.sleep(1)
        return 1

    if d == -2:
        lcd.lcd_print("No Internet Connection")
        return 1

    name = d['name']
    gender = d['gender']
    age = findAge(d['age'])
    smile = isSmiling(d['smile'])
    glasses = d['glasses']
    confidence = d['confidence']
    emotion = findMaxEmotion(d['emotion'])

    lcd.lcd_string("Uploading Data...")
    
    with open("index.xml", 'r+') as f:
        line = f.readline()
        index = int(line)

    fb = firebase.FirebaseApplication(URL)
    imageName = str(index)+".jpg"

    result = fb.put('/',index,{'name':name, 'gender':gender ,'age':age, 'smile':smile, 'glasses':glasses, 'confidence':confidence, 'emotion':emotion})

    status = 1

    try:
        status = subprocess.check_call(["./storage.sh",imageName])
    except:
        pass
    
    while status!=0:
        try:
            status = subprocess.check_call(["./storage.sh",imageName])
        except:
            pass

    index += 1
    with open("index.xml", 'w+') as f:
        f.write(str(index))

    lcd.lcd_string(name)
    if smile == "Yes":
        smile = "Smiling"
    else:
        smile = "Not Smiling"
    printString = "Age Range:" + str(age) + " " + str(gender) + " " + str(smile) + " " + str(glasses) + " Emotion:" + str(emotion)
    lcd.lcd_print(printString,2)
    lcd.lcd_clear()
    return 0
Esempio n. 3
0
def main():
    init_lcd()

    while True:
        read_value = read_socket_value()
        pm10, pm25 = read_value.decode("utf-8").split('|')
        lcd_clear()
        lcd_display_string("PM10  : %s" % pm10.rjust(4), 1)
        lcd_display_string("PM2.5 : %s" % pm25.rjust(4), 2)
        sleep(update_interval)
Esempio n. 4
0
def main():
    initialize()
    global turn
    time.sleep(4)
    while True:
        ser_port.write(b'0')
        get_ack()
        ser_port.write(b'pick')
        choose_start()
        if turn:
            time.sleep(4)
        lcd.lcd_clear()
        lcd.lcd_string('Checking board ..', 0)
        global result
        result = 0
        #play
        while True:
            if algo.isWin(pre_state):
                if algo.whoWins(pre) == 'X':
                    result = 2
                else:
                    result = 1
                break
            if algo.isFull(pre_state):
                result = 0
                break
            while turn:
                if button.check():
                    lcd.lcd_clear()
                    lcd.lcd_string('My turn ..', 0)
                    turn = 0
                    break
            play_turn()

        lcd.lcd_clear()
        if result == 0:
            lcd.lcd_string('Draw', 0)
        elif result == 1:
            lcd.lcd_string('I win, you noob', 0)
        else:
            lcd.lcd_string('gg', 0)
        time.sleep(8)
        lcd.lcd_clear()
        lcd.lcd_string('again ?', 0)
        while True:
            if button.check():
                break
Esempio n. 5
0
def choose_start():
    lcd.lcd_clear()
    lcd.lcd_string('press the button', 1)
    for i in range(7):
        lcd.lcd_string('to starts %s' % str(i), 2)
        time.sleep(0.5)
        if button.check():  #change with button input
            turn = 1
            lcd.lcd_clear()
            lcd.lcd_string('You start (X)', 0)
            return
        time.sleep(0.5)
    lcd.lcd_clear()
    lcd.lcd_string('I start (O)', 0)
Esempio n. 6
0
def setup_serial_port():
    global ser_port
    for i in range(5):
        time.sleep(1)
        lcd.lcd_clear()
        lcd.lcd_string('trying port %s' % str(i), 0)
        time.sleep(2)
        try:
            ser_port = serial.Serial('/dev/ttyACM%s' % str(i), 9600)
            lcd.lcd_clear()
            lcd.lcd_string('port %s up' % str(i), 0)
            break
        except:
            lcd.lcd_clear()
            lcd.lcd_string('port %s empty' % str(i), 0)
Esempio n. 7
0
def play_turn():
    lcd.lcd_clear()
    lcd.lcd_string('looking ..', 0)
    os.system('raspistill -md 2 -o ./imgs/still.jpg')
    time.sleep(1)
    lcd.lcd_clear()
    lcd.lcd_string('thinking ..', 0)
    global pre_state
    state = img_proc.detect_board('./imgs/still.jpg')
    pre_state = state
    #TODO: check if current is valid from pre_state
    win, move = algo.nextMove(list(state), 'O')
    square = 9 - move
    lcd.lcd_clear()
    lcd.lcd_string('moving ..', 0)
    ser_port.write(str.encode(str(square)))
    get_ack()
    lcd.lcd_clear()
    lcd.lcd_string('droping ..', 0)
    ser_port.write(b'drop')
    time.sleep(2)
    lcd.lcd_clear()
    lcd.lcd_string('moving back ..', 0)
    ser_port.write(b'0')
    get_ack()
    lcd.lcd_clear()
    ser_port.write(b'pick')
    global turn
    lcd.lcd_clear()
    lcd.lcd_string('Your turn ..', 0)
    turn = 1
def lcd_close_board():
	file_print("Closing LCDs")
	lcd.lcd_clear()
	for index in range(0,7):
		lcd.lcd_led_set(index, 0)
Esempio n. 9
0
                    lcd_string("Rate N/A", LCD_LINE_4, 2)
                else:
                    btc_day = status.stats['btc_day']
                    eur_day = btc_day * eur_rate if (btc_day
                                                     and eur_rate) else 0
                    lcd_string(
                        "{} {}/d[{}E]".format(btc_day,
                                              displayed_cryptocurrency,
                                              round(eur_day, 2)), LCD_LINE_4,
                        2)
            elif line_state[4]['current_state'] == 3:
                lcd_string("1BTC = {}eur".format(int(btc_eur_rate)),
                           LCD_LINE_4, 2)
            elif line_state[4]['current_state'] == 4:
                lcd_string("1LTC = {}eur".format(int(ltc_eur_rate)),
                           LCD_LINE_4, 2)

            update_line_states()
        except Exception as e:
            logger.exception("Leaving... Error while refreshing LCD")
            break


if __name__ == '__main__':
    try:
        main()
    except KeyboardInterrupt:
        pass
    finally:
        lcd_clear()