zoukankan      html  css  js  c++  java
  • 重构 maixpy 的 board_info + config.json 从而自适应硬件版型。

    主要是备份代码。

    class board_info:
      def set(key, value=None):
        return setattr(__class__, key, value)
      def all():
        return dir(__class__)
      def get():
        return getattr(__class__, key)
      def load(__map__={}):
        for k, v in __map__.items():
          __class__.set(k, v)
    
    board_info.load()
    
    if __name__ == "__main__":
      def check_config_json(data):
        try:
          with open('/flash/config.json', 'rb') as f:
            tmp = json.loads(f.read())
            if tmp["type"] != data["type"]:
              raise Exception('config.json no exist')
        except Exception as e:
          with open('/flash/config.json', "w") as f:
            f.write(cfg)
          import machine
          machine.reset()
    
      print(board_info.all())
      board_info.set('test', 123)
      print(board_info.test)
      print(board_info.all())
    
      import json
      test = {
        "type":"test",
        "board_info":{
          'PIN10': 10,
          'BOOT_KEY': 16,
          'WIFI_TX' : 6,
          'WIFI_RX' : 7,
          'WIFI_EN' : 8,
        }
      }
      cfg = json.dumps(test)
      check_config_json(test)
      from Maix import config
      tmp = config.get_value('board_info', None)
      if tmp != None:
        board_info.load(tmp)
      print(board_info.all())
      print(board_info.PIN10)
      print(board_info.BOOT_KEY)
      print(board_info.WIFI_TX)
      print(board_info.WIFI_RX)
      print(board_info.WIFI_EN)
    

  • 相关阅读:
    MYSQL导入,导出命令。
    MySQL修改,表结构大幅修改
    Ajax
    js和jQuery的日常
    freemarker 分页取值
    Timer定时任务
    汉字相似度比较
    读取Properties键值对
    Python+requests+unittest+excel实现接口自动化测试框架
    Android App 压力测试方法(Monkey)
  • 原文地址:https://www.cnblogs.com/juwan/p/13802915.html
Copyright © 2011-2022 走看看