src/eric7/MicroPython/Devices/MicrobitDevices.py

branch
eric7
changeset 11189
289c7150ec4b
parent 11186
c2d18aefef6b
child 11222
42441412dc29
equal deleted inserted replaced
11188:413f6ff459ab 11189:289c7150ec4b
73 """ 73 """
74 super().setConnected(connected) 74 super().setConnected(connected)
75 75
76 if self._deviceData: 76 if self._deviceData:
77 self._deviceData["local_mip"] = False 77 self._deviceData["local_mip"] = False
78
79 if self.hasCircuitPython():
80 self._submitMode = "paste"
81 78
82 def setButtons(self): 79 def setButtons(self):
83 """ 80 """
84 Public method to enable the supported action buttons. 81 Public method to enable the supported action buttons.
85 """ 82 """
1021 for determining information about the board. 1018 for determining information about the board.
1022 1019
1023 @return list of command strings to be executed 1020 @return list of command strings to be executed
1024 @rtype list of str 1021 @rtype list of str
1025 """ 1022 """
1026 # These are a subset of the generic ones. 1023 if self.hasCircuitPython():
1027 return [ # needs to be splitted for boards with low memory 1024 return super()._boardInformationCommands()
1028 """def get_board_info(): 1025 else:
1026 # These are a subset of the generic ones.
1027 return [ # needs to be splitted for boards with low memory
1028 """def get_board_info():
1029 res = {} 1029 res = {}
1030 1030
1031 try: 1031 try:
1032 import os 1032 import os
1033 uname = os.uname() 1033 uname = os.uname()
1047 return res 1047 return res
1048 1048
1049 print(get_board_info()) 1049 print(get_board_info())
1050 del get_board_info 1050 del get_board_info
1051 """, 1051 """,
1052 """def get_board_info(): 1052 """def get_board_info():
1053 res = {} 1053 res = {}
1054 1054
1055 import sys 1055 import sys
1056 res['py_platform'] = sys.platform 1056 res['py_platform'] = sys.platform
1057 res['py_version'] = sys.version 1057 res['py_version'] = sys.version
1082 return res 1082 return res
1083 1083
1084 print(get_board_info()) 1084 print(get_board_info())
1085 del get_board_info 1085 del get_board_info
1086 """, 1086 """,
1087 """def get_board_info(): 1087 """def get_board_info():
1088 res = {} 1088 res = {}
1089 1089
1090 try: 1090 try:
1091 import ulab 1091 import ulab
1092 res['ulab'] = ulab.__version__ 1092 res['ulab'] = ulab.__version__
1096 return res 1096 return res
1097 1097
1098 print(get_board_info()) 1098 print(get_board_info())
1099 del get_board_info 1099 del get_board_info
1100 """, 1100 """,
1101 # micro:bit specific variants due to missing float support 1101 # micro:bit specific variants due to missing float support
1102 """def get_board_info(): 1102 """def get_board_info():
1103 res = {} 1103 res = {}
1104 1104
1105 import gc 1105 import gc
1106 gc.enable() 1106 gc.enable()
1107 gc.collect() 1107 gc.collect()
1116 return res 1116 return res
1117 1117
1118 print(get_board_info()) 1118 print(get_board_info())
1119 del get_board_info 1119 del get_board_info
1120 """, 1120 """,
1121 """def get_board_info(): 1121 """def get_board_info():
1122 res = {} 1122 res = {}
1123 1123
1124 try: 1124 try:
1125 import os 1125 import os
1126 stat_ = os.statvfs('/flash') 1126 stat_ = os.statvfs('/flash')
1133 return res 1133 return res
1134 1134
1135 print(get_board_info()) 1135 print(get_board_info())
1136 del get_board_info 1136 del get_board_info
1137 """, 1137 """,
1138 """def get_board_info(): 1138 """def get_board_info():
1139 res = {} 1139 res = {}
1140 1140
1141 import machine as mc 1141 import machine as mc
1142 import microbit as mb 1142 import microbit as mb
1143 try: 1143 try:
1163 return res 1163 return res
1164 1164
1165 print(get_board_info()) 1165 print(get_board_info())
1166 del get_board_info 1166 del get_board_info
1167 """, 1167 """,
1168 ] 1168 ]
1169 1169
1170 def getBoardInformation(self): 1170 def getBoardInformation(self):
1171 """ 1171 """
1172 Public method to get some information data of the connected board. 1172 Public method to get some information data of the connected board.
1173 1173
1174 @return dictionary containing the determined data 1174 @return dictionary containing the determined data
1175 @rtype dict 1175 @rtype dict
1176 """ 1176 """
1177 res = super().getBoardInformation() 1177 res = super().getBoardInformation()
1178 1178
1179 # post-process the results to determine the right float entries 1179 if not self.hasCircuitPython():
1180 1180 # post-process the results to determine the right float entries
1181 # 1. memory 1181
1182 res["mem_total_kb"] = res["mem_total"] / 1024.0 1182 # 1. memory
1183 res["mem_used_kb"] = res["mem_used"] / 1024.0 1183 res["mem_total_kb"] = res["mem_total"] / 1024.0
1184 res["mem_used_pc"] = res["mem_used"] / res["mem_total"] * 100.0 1184 res["mem_used_kb"] = res["mem_used"] / 1024.0
1185 res["mem_free_kb"] = res["mem_free"] / 1024.0 1185 res["mem_used_pc"] = res["mem_used"] / res["mem_total"] * 100.0
1186 res["mem_free_pc"] = res["mem_free"] / res["mem_total"] * 100.0 1186 res["mem_free_kb"] = res["mem_free"] / 1024.0
1187 1187 res["mem_free_pc"] = res["mem_free"] / res["mem_total"] * 100.0
1188 # 2. flash 1188
1189 if res["flash_info_available"]: 1189 # 2. flash
1190 res["flash_total_kb"] = res["flash_total"] / 1024.0 1190 if res["flash_info_available"]:
1191 res["flash_free_kb"] = res["flash_free"] / 1024.0 1191 res["flash_total_kb"] = res["flash_total"] / 1024.0
1192 res["flash_used_kb"] = res["flash_total_kb"] - res["flash_free_kb"] 1192 res["flash_free_kb"] = res["flash_free"] / 1024.0
1193 res["flash_free_pc"] = res["flash_free_kb"] / res["flash_total_kb"] * 100.0 1193 res["flash_used_kb"] = res["flash_total_kb"] - res["flash_free_kb"]
1194 res["flash_used_pc"] = res["flash_used_kb"] / res["flash_total_kb"] * 100.0 1194 res["flash_free_pc"] = (
1195 1195 res["flash_free_kb"] / res["flash_total_kb"] * 100.0
1196 # 3. machine 1196 )
1197 res["mc_frequency_mhz"] = ( 1197 res["flash_used_pc"] = (
1198 res["mc_frequency"] / 1000000.0 if res["mc_frequency"] is not None else None 1198 res["flash_used_kb"] / res["flash_total_kb"] * 100.0
1199 ) 1199 )
1200 with contextlib.suppress(KeyError): 1200
1201 if res["mc_temp_c"] is not None: 1201 # 3. machine
1202 res["mc_temp_c"] = res["mc_temp_c"] / 100 # due to integer support only 1202 res["mc_frequency_mhz"] = (
1203 res["mc_frequency"] / 1000000.0
1204 if res["mc_frequency"] is not None
1205 else None
1206 )
1207 with contextlib.suppress(KeyError):
1208 if res["mc_temp_c"] is not None:
1209 res["mc_temp_c"] = (
1210 res["mc_temp_c"] / 100
1211 ) # due to integer support only
1203 1212
1204 return res 1213 return res
1205 1214
1206 def isMicrobit(self): 1215 def isMicrobit(self):
1207 """ 1216 """

eric ide

mercurial