#boot_activeMenu_v00_i.py #by D@CC #on 2024AJan05 #Purpose: to server as a boot program for a Raspberry Pi def IX_grepStr(nameListIn,rowIn,badNameErrMsg): #By D@CC #on 2024AJan03 #appearing in nameList #Purpose: to grep 2nd word into a variable in the calling module #parm1 is the nameList #parm2 is the row read from the file #Returns i,name, value where i is the list item # # and name is name of variable to define # and value is the value to be assigned #Eg: nameListIn={"a","b"} # i,value=IX_grepStr(nameListIn,row) # if i>-1 : # if i==0 : a=value # print("a:",a) # if i==1 : a = value # print("b:",b) # else: # print("ERROR: unrecognised grep name") # #if end #varList is {a,b} #rowA is string to grep rowA=rowIn nameList=nameListIn rowA=rowA.strip() #print("rowIn stripped:",row) cnt=rowA.count(" ") if cnt>1 : print("ERROR too many spaces in: ",rowA) cnt=-1 #if end col=rowA.find(" ")+1 #print("col:",col) nameA=badNameErrMsg value="" if col>0: #split at a space w1,w2=rowA.split(" ") if w1 in nameList : idx = nameList.index(w1) nameA=w1 value=w2 else: #if name not found idx =-1 if w1=="uBoot" : #print("at 51") return -1,"","" else: print("WARNING name NOT found:",w1) return -1,"","" #if end #returning bad name & value #if end else: print("WARNING wrong # of spaces found in:",rowA) idx=-1 # no " " in rowA #if end #print("returning idx,name,value:",idx,name,value) return idx,nameA,value #def end IX_grepStr() #/IX_grepStr() def newLine(mLine,menuText): #By D@CC #on 2024AJan05 #Purpose: Write out a line of text # about this menu line #print(mLine,menuText) pass #def end def anyTapWto(iSwitch,timeOutSecs): #By D@CC #on 2024AJan05 #Purpose: watch for any tap by the user time.sleep(timeOutSecs) wasTapped=False return wasTapped #def end def runMenuItem(j): #By D@CC #on 2024AJan05 #Purpose: run menu item # j return #def end def ringBell(GPIO,timeSecs): #By D@CC #on 2024AJan05 #Purpose: ring the bell for a # of seconds #Parm1: GPIO # eg 26 for the Cytron Maker pHAT #Parm2: (a short beep is .1 seconds) # (a long beep is .2 seconds) import time global bell #print("@103 GPIO:", GPIO) #input("@104 in ringBell") gBell=GPIO if GPIO==-2: # works very poorly #os.system("speaker-test -t sine -f 1000 -l 1 & sleep .2 && kill -9 $!") #Source: https://linux.die.net/man/1/speaker-test dT=" .3 " belTXT="speaker-test -t sine -f 1000 -l 1 & sleep"+dT+"&& kill -9 $!" os.system(belTXT) #if end if GPIO==-1: #print("@115 try an ascii BEL character") print('/a') #doesn't work with Python 3 on 2024AJan04 #if end if GPIO==0 or GPIO==26: # set up as global bell = LED(26) in main #gBell=26 #buzzer on Cytron Maker pHAT # if its buzzer is too loud, cover it with an erasure uTime=time.time() bell.on() waitT=timeSecs #(a short beep is .1 seconds) # #(a long beep is .2 seconds) offT=.1 #time between beeps deltaT=0 while deltaT0: newLine(mLine,menuLine[mLine]) #highlight new menuLine #if end if mLine==1: pass #if end if mLine==2: pass #if end if mLine==3: pass #if end if mLine==4: #4 print the message print(iMsg) #if end #print("@283") if mLine==5: #run the application #myCmd="sh "+"IX_assets/IX_log.sh "+">result.txt" #myCmd="sh "+shBoot+" > result.txt" import os if outputCLI=="/home/pi/Desktop/IX_output.txt": # route the output to the stnd IX output file # but first delete previous output myCmd="rm /home/pi/Desktop/IX_output.txt" #print("myCmd:",myCmd) os.system(myCmd) #now run sh but save the output #Future: also allow a program Name, not just a "sh" myCmd="sh "+boot_i print("@310 running");print(" >$"+myCmd) myCmd=myCmd+" > /home/pi/Desktop/IX_output.txt" os.system(myCmd) else: #do NOT save the output myCmd="sh "+boot_i #print("@317 running");print(" >$"+myCmd) #print("@318 myCmd:",myCmd) os.system(myCmd) #if end #display the result if saved #if outputCLI=="/home/pi/Desktop/IX_output.txt" or outputCLI=="": if outputCLI=="/home/pi/Desktop/IX_output.txt": print("@327 displaying saved outputCLI:") for row in open("/home/pi/Desktop/IX_output.txt"): print(" >"+row, end='') #for end #if end #if end if mLine==6: #6 Loop Back to top displayTime=3 print("HELP MESSAGE DISPLAYING FOR",displayTime,"seconds") print("Hit ^C to exit") try: time.sleep(displayTime) except: isLooping=False #stop the while loop finally: #hit ^C to exit # following statement works fine with Python3 but os.system("clear") #causes "TERM environment variable not set" with Thonny #bell was set as global in this module bell.off() #turn bell OFF if accidentally left ON #os.system("cls") #causes "cls: not found" #for j in range(100): print() #clears any screen with Thonny #end try pass #print("@353") #if end #for end #while end print("end of:",progName) #/boot_activeMenu_v00_i.py