1212import urequests as requests
1313import _thread as thread
1414import json
15+ import random
16+ import string
1517
1618os .chdir ('drivers' )
1719
1820index = open ('drivers.conf' , 'r' )
19- j = json .load (index )
21+ conf = json .load (index )
22+
23+ LOADEDDRIVERS = []
24+ basedrivers = ['display' , 'direction' , 'storage' , 'keyboard' ]
25+
26+ # Load base drivers
27+ try :
28+ execfile (conf ['display' ])
29+ LOADEDDRIVERS .append ('display' )
30+ except :
31+ print ('Could not initialize a driver for display.' )
32+
33+ try :
34+ execfile (conf ['direction' ])
35+ LOADEDDRIVERS .append ('direction' )
36+ except :
37+ print ('Could not initialize a driver for directional control.' )
38+
39+ try :
40+ execfile (conf ['storage' ])
41+ LOADEDDRIVERS .append ('storage' )
42+ except :
43+ print ('Could not initialize a driver for external storage.' )
44+
45+ try :
46+ execfile (conf ['keyboard' ])
47+ LOADEDDRIVERS .append ('keyboard' )
48+ except :
49+ print ('Could not initialize driver for keyboard input' )
2050
21- execfile (j ['display' ])
22- execfile (j ['direction' ])
23- execfile (j ['SDreader' ])
24- execfile (j ['keyboard' ])
51+ # Load optional drivers
52+ for i in conf :
53+ if not i in basedrivers :
54+ if conf [i ][0 ] == True :
55+ execfile (conf [i ][1 ])
56+ LOADEDDRIVERS .append (i )
2557
2658print ('Drivers initialized' )
2759
@@ -36,12 +68,12 @@ def log(text):
3668 if LOGGING :
3769 logfile = open ('/sd/.logs/' + LOGFILENAME + '.log' , 'a' )
3870 logfile .write ('\n ' )
39- logfile .write (str (time .localtime ()[3 ])+ ':' + str (time .localtime ()[4 ])+ ': ' + str (time .localtime ()[5 ])+ ': ' + str (text ))
71+ logfile .write (str (time .localtime ()[3 ])+ ':' + str (time .localtime ()[4 ])+ '. ' + str (time .localtime ()[5 ])+ ': ' + str (text ))
4072 logfile .close ()
4173 else :
4274 print (str (time .localtime ()[3 ])+ ':' + str (time .localtime ()[4 ])+ ':' + str (time .localtime ()[5 ])+ ': ' + str (text ))
4375
44- if btn . value () != 0 :
76+ if not pressed () :
4577 try :
4678 logs = os .listdir ('/sd/.logs' )
4779 logs .reverse ()
0 commit comments