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.

59 lines
1.8 KiB

  1. #!/usr/bin/env python
  2. import time
  3. Import("env")
  4. # ------------------------------------------------------------------------------
  5. # Utils
  6. # ------------------------------------------------------------------------------
  7. class Color(object):
  8. BLACK = '\x1b[1;30m'
  9. RED = '\x1b[1;31m'
  10. GREEN = '\x1b[1;32m'
  11. YELLOW = '\x1b[1;33m'
  12. BLUE = '\x1b[1;34m'
  13. MAGENTA = '\x1b[1;35m'
  14. CYAN = '\x1b[1;36m'
  15. WHITE = '\x1b[1;37m'
  16. LIGHT_GREY = '\x1b[0;30m'
  17. LIGHT_RED = '\x1b[0;31m'
  18. LIGHT_GREEN = '\x1b[0;32m'
  19. LIGHT_YELLOW = '\x1b[0;33m'
  20. LIGHT_BLUE = '\x1b[0;34m'
  21. LIGHT_MAGENTA = '\x1b[0;35m'
  22. LIGHT_CYAN = '\x1b[0;36m'
  23. LIGHT_WHITE = '\x1b[0;37m'
  24. def clr(color, text):
  25. return color + str(text) + '\x1b[0m'
  26. # ------------------------------------------------------------------------------
  27. # Callbacks
  28. # ------------------------------------------------------------------------------
  29. def check_size(source, target, env):
  30. time.sleep(2)
  31. size = target[0].get_size()
  32. print clr(Color.LIGHT_BLUE, "Binary size: %s bytes" % size)
  33. #if size > 512000:
  34. # print clr(Color.LIGHT_RED, "File too large for OTA!")
  35. # Exit(1)
  36. def add_build_flags(source, target, env):
  37. build_h = "espurna/config/build.h"
  38. build_flags = env['BUILD_FLAGS'][0]
  39. lines = open(build_h).readlines()
  40. with open(build_h, "w") as fh:
  41. for line in lines:
  42. if "APP_BUILD_FLAGS" in line:
  43. fh.write("#define APP_BUILD_FLAGS \"%s\"" % build_flags)
  44. else:
  45. fh.write(line)
  46. # ------------------------------------------------------------------------------
  47. # Hooks
  48. # ------------------------------------------------------------------------------
  49. env.AddPreAction("$BUILD_DIR/src/espurna.ino.o", add_build_flags)
  50. env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", check_size)