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.

96 lines
3.0 KiB

6 years ago
6 years ago
6 years ago
6 years ago
  1. #!/usr/bin/env python
  2. from __future__ import print_function
  3. import os
  4. import sys
  5. from subprocess import call
  6. import click
  7. from platformio import util
  8. Import("env")
  9. # ------------------------------------------------------------------------------
  10. # Utils
  11. # ------------------------------------------------------------------------------
  12. class Color(object):
  13. BLACK = '\x1b[1;30m'
  14. RED = '\x1b[1;31m'
  15. GREEN = '\x1b[1;32m'
  16. YELLOW = '\x1b[1;33m'
  17. BLUE = '\x1b[1;34m'
  18. MAGENTA = '\x1b[1;35m'
  19. CYAN = '\x1b[1;36m'
  20. WHITE = '\x1b[1;37m'
  21. LIGHT_GREY = '\x1b[0;30m'
  22. LIGHT_RED = '\x1b[0;31m'
  23. LIGHT_GREEN = '\x1b[0;32m'
  24. LIGHT_YELLOW = '\x1b[0;33m'
  25. LIGHT_BLUE = '\x1b[0;34m'
  26. LIGHT_MAGENTA = '\x1b[0;35m'
  27. LIGHT_CYAN = '\x1b[0;36m'
  28. LIGHT_WHITE = '\x1b[0;37m'
  29. def clr(color, text):
  30. return color + str(text) + '\x1b[0m'
  31. def print_warning(message, color=Color.LIGHT_YELLOW):
  32. print(clr(color, message), file=sys.stderr)
  33. def print_filler(fill, color=Color.WHITE, err=False):
  34. width, _ = click.get_terminal_size()
  35. if len(fill) > 1:
  36. fill = fill[0]
  37. out = sys.stderr if err else sys.stdout
  38. print(clr(color, fill * width), file=out)
  39. # ------------------------------------------------------------------------------
  40. # Callbacks
  41. # ------------------------------------------------------------------------------
  42. def remove_float_support():
  43. flags = " ".join(env['LINKFLAGS'])
  44. flags = flags.replace("-u _printf_float", "")
  45. flags = flags.replace("-u _scanf_float", "")
  46. newflags = flags.split()
  47. env.Replace(
  48. LINKFLAGS = newflags
  49. )
  50. def cpp_check(source, target, env):
  51. print("Started cppcheck...\n")
  52. call(["cppcheck", os.getcwd()+"/espurna", "--force", "--enable=all"])
  53. print("Finished cppcheck...\n")
  54. def check_size(source, target, env):
  55. (binary,) = target
  56. path = binary.get_abspath()
  57. size = os.stat(path).st_size
  58. print(clr(Color.LIGHT_BLUE, "Binary size: {} bytes".format(size)))
  59. # Warn 1MB variants about exceeding OTA size limit
  60. flash_size = int(env.BoardConfig().get("upload.maximum_size", 0))
  61. if (flash_size == 1048576) and (size >= 512000):
  62. print_filler("*", color=Color.LIGHT_YELLOW, err=True)
  63. print_warning("File is too large for OTA! Here you can find instructions on how to flash it:")
  64. print_warning("https://github.com/xoseperez/espurna/wiki/TwoStepUpdates", color=Color.LIGHT_CYAN)
  65. print_filler("*", color=Color.LIGHT_YELLOW, err=True)
  66. def build_webui(env):
  67. config = util.load_project_config()
  68. kv = dict(config.items("env:" + env.get('PIOENV')))
  69. modules = kv["modules"] if "modules" in kv else "all"
  70. env.Execute("WEBUI_MODULES=\"%s\" node node_modules/gulp/bin/gulp.js" % modules)
  71. # ------------------------------------------------------------------------------
  72. # Hooks
  73. # ------------------------------------------------------------------------------
  74. remove_float_support()
  75. build_webui(env)
  76. env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", check_size)