#WioFunctions.py #List functions # #listfromfile() #wioMore() #anyButton() #minicom -o -D /dev/ttyACM0 #********************* end of list offunctions def listfromfile(filename): # parm1 in is the serial data file containing 0 or more reccords # parm1 out is the records in a Python list. # by D@CC on 2023CMar22 # converts a serial file into a list of records # each eor must be "\r\n" print("program:",progName) #minicom -o -D /dev/ttyACM0 #CTRL-A Z for minicom menu #>>>Enter to start REPL f=open(filename,"r") data=f.read() print(data) data2list=data.replace('\r',' ').split("\n") f.close() return data2list # def end #/listfromfile.py #*********************** end of function definition #function wioMore.py def wioMore(listName,beginRecNumber,lcdRows,lcdCols,hdrRow1,hdrRow2,prefix,isShow): # by D@CC on 2023CMar22 # Purpose: to display full set of rows of list on the Wio Terminal LCD # parm1 in: list to be displayed # parm2 in: first record number to display 0,1,2 etc # parm3 in: # rows on LCD # parm4 in: # columns on LCD # parm5 in: text for top row (header1) # parm6 in: text for second row (header2) # parm7 in: prefix for third and other rows # parm8 in: (for debugging) True will show more info in print lines # # parm out: False if empty screen ( data rows) were generated # # Wio Terminal LCD has lcdRows=24, lcdCols=59 # # disply hdrRow1 & hdrRow2 as top 2 rows on the LCD # display list "listName" on Wio Terminal LCD # beginning with beginRecNumber (= record number) ie initially is 0 # In WioIXkb, all list indices begin with 0 ie 0,1,2,3 . . . #Do=wioClearLCD(lcdRows,lcdCols) #beginRecNumber # returns True if something was displayed # returns False if display of data lines will be empty # if isShow : print("***entering wioMore()") if isShow : print("***about to print 2 headers") print(hdrRow1+str(beginRecNumber)) print(hdrRow2) if isShow : print("***after printing 2 headers") if isShow : print("lcdRows:",lcdRows) lenList=len(listName) if isShow : print("lenList:",lenList) unlistedRecs=lenList-beginRecNumber if isShow : print("unlistedRecs:",unlistedRecs) if isShow : print("beginRecNumber:",beginRecNumber) cntRowsToDisplay = min(lcdRows,unlistedRecs,lenList) if isShow : print("cntRowsToDisplay:",cntRowsToDisplay) if cntRowsToDisplay < 1 : if isShow : print("LCD will be empty.") isResult=False else: if isShow : print("LCD will print something.") isResult=True #if end if isShow : print("cntRowsToDisplay:",cntRowsToDisplay) forRange=lcdRows-2 for i in range(forRange): listRow=beginRecNumber+i if listRow >= lenList : print(i,prefix) else : if listRow<=lenList-1 : print(i,prefix+str(listRow)+" "+listName[listRow]) else : print(i,prefix+str(listRow)+"|"+str(forRange)) #if end #if end #for end return isResult # def end #*********************** end of function definition #/wioMore.py #anyButton.py Function # by D@CC on 2023CMar23 # Minicom >>>minicom -o -D /dev/ttyACM0 import time import board from digitalio import DigitalInOut, Direction def anyButton(button,device="Wio Terminal",isShow=False): # parm1 device must be "Wio Terminal" # parm2 button class must be defined in the main and passed # parm3 isShow = True, (False will print out debug info) # returns # parm2 name of switch is returned when it is depressed # this function hangs until a switch is pressed # button definitions MUST be in the main program #button = DigitalInOut(board.SWITCH_PRESS) #button.direction = Direction.INPUT #import board #digitalio import DigitalInOut, Direction # by D@CC on 2023CMar23 # successful function (only for 'SWITCH_PRESS') #Note button must be defined in the main program and passed # Clicking the button too fast will cause a reboot. Doh! isInUse0=True # just for the print statements when isShow=True if isShow :print("0.upon entry to anyButton, isInUse0:",isInUse0) # this routine monitors 8 buttons on the Wio Terminal # it returns the name of the button that is pressed (or "none") # the list of 8 buttons are named here : use REPL dir(board) to see them all # isShow is a debugging aid, if True, superfluous prints occur bList=['SWITCH_PRESS', 'SWITCH_DOWN', 'SWITCH_LEFT', 'SWITCH_RIGHT', 'SWITCH_UP','BUTTON_1', 'BUTTON_2', 'BUTTON_3'] # Note that 'SWITCH_PRESS' is bList[0] as of 2023CMar23 # the other buttons will be added in the future # The names in the board function library can be seen using the statement dir(board) # #isInUse0=False result="None" if not device == "Wio Terminal" : print("device must be 'Wio Terminal'") return result else : lenList=len(bList) lenList=1 #initially on the center uJoyStick button will be monitored for i in range(lenList) : if i==0: # set up the next button #if isShow :print("1.before defining button test, isInUse0:",isInUse0) #if isInUse0 == False : #isInUse0= True #if end isPressed=False #is Pressed is False until a button is pressed while isPressed==False: isUp = button.value # isUp = True when button not pressed # isUp = False when button is pressed if isUp== False : #meaning the button was pressed. if isShow :print("2.in anyButton, a button was pressed") buttonName=bList[0] # bList[0] is 'SWITCH_PRESS' if isShow :print("3.",buttonName," was pressed.") isPressed=True # takes us out of the while loop #break #out of the while loop #if end #while end if isShow :print("4.after button test, isInUse0:",isInUse0) #if end time.sleep(1) # don't stay in a tight loop if isShow :print("5.in anyButton, after sleep") #for end #if end return buttonName #def end #*********************** end of all function definitions #/WioFunctions.py #*********************** end of function definitions #/WioFunctions.py progName="WioIXkb01o11.py" # by D@CC on 2023CMar24 #0. connect Wio Terminal to Pi-400 #1. delete main.py from Desktop #2. copy WioFunctions.py+WioIXkb01o11.py into main.py #3. Delete main.py from ARDUPY #4. copyThenPaste main.py into ARDUPY volume #5. start RPi Terminal #6. Minicom >>>minicom -o -D /dev/ttyACM0 #7. CTRL-A Z #8. hit Enter in Terminal to get >>> which is REPL #9, hit CTRL-D to restart the Wio Terminal import os import time import board from digitalio import DigitalInOut, Direction # button definitions MUST be in the main program button = DigitalInOut(board.SWITCH_PRESS) button.direction = Direction.INPUT isShowWork = False if isShowWork : print("isShowWork:",isShowWork) print();print() print("program:",progName) #time.sleep(3) #3 seconds # get list of current folder #dirList=["$line 0","$line 1","$line 2","$line 3"] dirList=os.listdir() if isShowWork : print("dirList:",dirList) lenList=len(dirList) #time.sleep(3) #3 seconds #for i in range(dirList): # print(dirList[i]) #end for beginWithRecNumb=0 hdr1="$$pgdn dir |begRec#" hdr2="-------------------------------------"+progName #hdr="----------------------------------------------------" if isShowWork : print("calling wioMore()") isDisplaying=wioMore(dirList,beginWithRecNumb,18,55,hdr1,hdr2,">",isShowWork) if isShowWork : print("isDisplaying:",isDisplaying) time.sleep(1) #1 seconds #print() while True: inButton=anyButton(button) if isShowWork : print("inButton:",inButton) if inButton=="SWITCH_PRESS" : beginWithRecNumb =beginWithRecNumb+16 if isShowWork : print("again beginWithRecNumb:",beginWithRecNumb) if isShowWork : print("calling wioMore() again.") isDisplaying=wioMore(dirList,beginWithRecNumb,18,55,hdr1,hdr2,">",isShowWork) if isShowWork : print("isDisplaying:",isDisplaying) #if end #while end if isShowWork : print("end of ",progName) #print() # saved in Desktop on Fla89S032G #/WioIXkb01o11.py # end of WioFunctions.py+WioIXkb01o11.py