def show_choices(names, percentages, primary_keys, display_percentages=True, short_names=True): lcd.clear() print("Options:") options, pks = generate_options(names, percentages, primary_keys, display_percentages, short_names) last_idx = len(options) - 1 print(options) curr_start_idx = 0 key = '' while True: option = options[curr_start_idx] for i in range(0, len(option)): lcd.string(option[i], LINES[i]) time.sleep(0.2) while True: key = kpad.get_key() for i in range(1, len(option) + 1): if key == str(i): time.sleep(0.1) return pks[curr_start_idx][i - 1] if key == '*': lcd.clear() time.sleep(0.1) if curr_start_idx == last_idx: curr_start_idx = 0 elif curr_start_idx < last_idx: curr_start_idx = (curr_start_idx + 1) break if key == '#': lcd.clear() time.sleep(0.1) if curr_start_idx == 0: curr_start_idx = last_idx elif curr_start_idx >= 1: curr_start_idx = (curr_start_idx - 1) break if key == 'A': while True: cropIDAccepted, pk_manual = acceptManualCropID() if cropIDAccepted: return pk_manual else: return show_choices(names, percentages, primary_keys)
def acceptFarmID(): lcd.clear() farmID = "" key = "E" time.sleep(0.1) lcd.string("Enter Farm ID", LINE_1) lcd.string("*- continue", LINE_2) lcd.string("#- clear D- back", LINE_3) #loop until some farm id is entered and * key is pressed. Following loop will only break when valid farm ID is entered while True: while key != "*": lcd.string(farmID, LINE_4) key = kpad.get_key() if key == '*': if len(farmID) == 0: lcd.clear() lcd.string("Farm ID can't", LINE_1) lcd.string("be null", LINE_2) time.sleep(1) lcd.clear() lcd.string("Enter Farm ID", LINE_1) lcd.string("*- continue", LINE_2) lcd.string("#- clear D- back", LINE_3) else: break elif key == '#': #for backspacing if len(farmID) > 0: farmID = farmID[:-1] time.sleep(0.1) elif key == 'D': #return to previous menu return False, "" elif key.isdigit(): farmID += key time.sleep(0.1) key = "" if validateFarmID(): # verify farm id return True, farmID else: lcd.clear() lcd.string("Farm ID is", LINE_1) lcd.string(" Invalid!", LINE_2) lcd.string("Please Try Again", LINE_3) time.sleep(1)
def acceptManualCropID(): lcd.clear() cropID = "" key = "" time.sleep(0.1) lcd.string(" Enter Crop ID ", LINE_1) lcd.string(" *- continue ", LINE_2) lcd.string("#- clear,D- back", LINE_3) #loop until some crop id is entered and * key is pressed. Following loop will run until valid crop id entered while True: while key != "*": lcd.string(cropID, LINE_4) key = kpad.get_key() if key == '*': if len(cropID) == 0: lcd.clear() lcd.string("Crop ID cant", LINE_1) lcd.string("be null", LINE_2) time.sleep(1) lcd.clear() lcd.string(" Enter Crop ID ", LINE_1) lcd.string(" *- continue ", LINE_2) lcd.string("#- clear,D- back", LINE_3) else: break elif key == '#': #for backspacing if len(cropID) > 0: cropID = cropID[:-1] time.sleep(0.1) elif key == 'D': #return to previous menu return False, "" elif key.isdigit(): cropID += key time.sleep(0.2) key = "" if validateCropID(): # verify Crop id return True, cropID else: lcd.clear() lcd.string("Crop ID is", LINE_1) lcd.string(" Invalid!", LINE_2) lcd.string("Please Try Again", LINE_3) time.sleep(1)
def display_screen(): weight = 0 while True: key = "E" while key is not '*': weight = displayWeight() key = kpad.get_key() if key == 'D': tare() elif key == 'A': lcd.clear() lcd.string(" System", LINE_2) lcd.string(" Shutting down...", LINE_3) active = 0 os.system("sudo poweroff") lcd.clear() break elif key == 'B': lcd.clear() lcd.string(" Script", LINE_2) lcd.string(" Restarting", LINE_3) lcd.string(" Please wait...", LINE_4) active = 0 GPIO.cleanup() sys.stdout.flush() os.execv(sys.executable, ['python3'] + sys.argv) break elif key == 'C': lcd.clear() lcd.string(" System", LINE_2) lcd.string(" Restarting", LINE_3) lcd.string(" Please wait...", LINE_4) active = 0 os.system("sudo reboot") break if (weight < min_weight): continue else: return weight
def show_prediction(names, percentages, primary_keys): lcd.clear() time.sleep(0.1) s = ("Confidence: {:05.2f}".format(percentages[0] * 100)) + '%' lcd.string("A to enter manually", LINE_2) lcd.string(names[0], LINE_1) lcd.string(s, LINE_2) lcd.string("A -> enter manually", LINE_3) lcd.string("*->next, #->change", LINE_4) #lcd.string("# to change", LINE_4) key = "" while True: if key == '*': return primary_keys[0] if key == '#': return show_choices(names, percentages, primary_keys) if key == 'A': while True: cropIDAccepted, pk_manual = acceptManualCropID() if cropIDAccepted: return pk_manual else: return show_prediction(names, percentages, primary_keys) key = kpad.get_key()