AdcObj.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #! /usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. import os
  4. import re
  5. import string
  6. import xml.dom.minidom
  7. from obj.ModuleObj import ModuleObj
  8. from utility.util import log
  9. from utility.util import LogLevel
  10. from utility.util import sorted_key
  11. class AdcObj(ModuleObj):
  12. def __init__(self):
  13. ModuleObj.__init__(self, 'cust_adc.h', 'cust_adc.dtsi')
  14. self.__idx_map = {}
  15. def get_cfgInfo(self):
  16. pass
  17. def parse(self, node):
  18. self.get_cfgInfo()
  19. self.read(node)
  20. def read(self, node):
  21. nodes = node.childNodes
  22. try:
  23. for node in nodes:
  24. if node.nodeType == xml.dom.Node.ELEMENT_NODE:
  25. if node.nodeName == 'count':
  26. count = node.childNodes[0].nodeValue
  27. continue
  28. subNode = node.getElementsByTagName('varName')
  29. if len(subNode):
  30. ModuleObj.set_data(self, node.nodeName, subNode[0].childNodes[0].nodeValue)
  31. except:
  32. msg = 'read adc content fail!'
  33. log(LogLevel.error, msg)
  34. return False
  35. return True
  36. def gen_files(self):
  37. ModuleObj.gen_files(self)
  38. def fill_hFile(self):
  39. gen_str = ''
  40. sorted_list = sorted(ModuleObj.get_data(self).keys())
  41. for key in sorted_list:
  42. value = ModuleObj.get_data(self)[key]
  43. gen_str += '''#define AUXADC_%s_CHANNEL\t\t\t%s\n''' %(value.upper(), key[3:])
  44. return gen_str
  45. def fill_dtsiFile(self):
  46. gen_str = '''&auxadc {\n'''
  47. gen_str += '''\tadc_channel@ {\n'''
  48. gen_str += '''\t\tcompatible = "mediatek,adc_channel";\n'''
  49. # sort by the key, or the sequence is dissorted
  50. #sorted_list = sorted(ModuleObj.get_data(self).keys())
  51. for key in sorted_key(ModuleObj.get_data(self).keys()):
  52. value = ModuleObj.get_data(self)[key]
  53. if value == "TEMPERATURE":
  54. gen_str += '''\t\tmediatek,%s0 = <%d>;\n''' %(value.lower(), string.atoi(key[3:]))
  55. else:
  56. gen_str += '''\t\tmediatek,%s = <%d>;\n''' %(value.lower(), string.atoi(key[3:]))
  57. gen_str += '''\t\tstatus = \"okay\";\n'''
  58. gen_str += '''\t};\n'''
  59. gen_str += '''};\n'''
  60. return gen_str