Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.2 KiB

  1. #!/usr/bin/env python
  2. from subprocess import call
  3. from platformio import util
  4. import os
  5. import time
  6. Import("env")
  7. # ------------------------------------------------------------------------------
  8. # Utils
  9. # ------------------------------------------------------------------------------
  10. class Color(object):
  11. BLACK = '\x1b[1;30m'
  12. RED = '\x1b[1;31m'
  13. GREEN = '\x1b[1;32m'
  14. YELLOW = '\x1b[1;33m'
  15. BLUE = '\x1b[1;34m'
  16. MAGENTA = '\x1b[1;35m'
  17. CYAN = '\x1b[1;36m'
  18. WHITE = '\x1b[1;37m'
  19. LIGHT_GREY = '\x1b[0;30m'
  20. LIGHT_RED = '\x1b[0;31m'
  21. LIGHT_GREEN = '\x1b[0;32m'
  22. LIGHT_YELLOW = '\x1b[0;33m'
  23. LIGHT_BLUE = '\x1b[0;34m'
  24. LIGHT_MAGENTA = '\x1b[0;35m'
  25. LIGHT_CYAN = '\x1b[0;36m'
  26. LIGHT_WHITE = '\x1b[0;37m'
  27. def clr(color, text):
  28. return color + str(text) + '\x1b[0m'
  29. # ------------------------------------------------------------------------------
  30. # Callbacks
  31. # ------------------------------------------------------------------------------
  32. def remove_float_support():
  33. flags = " ".join(env['LINKFLAGS'])
  34. flags = flags.replace("-u _printf_float", "")
  35. flags = flags.replace("-u _scanf_float", "")
  36. newflags = flags.split()
  37. env.Replace(
  38. LINKFLAGS = newflags
  39. )
  40. def cpp_check(source, target, env):
  41. print("Started cppcheck...\n")
  42. call(["cppcheck", os.getcwd()+"/espurna", "--force", "--enable=all"])
  43. print("Finished cppcheck...\n")
  44. def check_size(source, target, env):
  45. time.sleep(2)
  46. size = target[0].get_size()
  47. print clr(Color.LIGHT_BLUE, "Binary size: %s bytes" % size)
  48. #if size > 512000:
  49. # print clr(Color.LIGHT_RED, "File too large for OTA!")
  50. # Exit(1)
  51. def build_webui(source, target, env):
  52. config = util.load_project_config()
  53. kv = dict(config.items("env:" + env.get('PIOENV')))
  54. if 'modules' in kv:
  55. os.environ['WEBUI_MODULES'] = kv["modules"]
  56. call(["gulp"])
  57. # ------------------------------------------------------------------------------
  58. # Hooks
  59. # ------------------------------------------------------------------------------
  60. remove_float_support()
  61. #env.AddPreAction("buildprog", cpp_check)
  62. env.AddPreAction("$BUILD_DIR/src/espurna.ino.cpp.o", build_webui)
  63. env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", check_size)