RawToGlobalCache.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/bash
  2. # Convert IRremoteESP8266's rawData output into Global Cache format.
  3. function isDigits()
  4. {
  5. [[ "$1" =~ ^[0-9]+$ ]]
  6. }
  7. function usage()
  8. {
  9. cat << EOF
  10. Usage: $0 Frequency_in_Hz
  11. Reads an IRremoteESP8266 rawData declaration from STDIN and converts it to
  12. GlobalCache format.
  13. e.g.
  14. uint16_t rawbuf[37] = {
  15. 7930, 3952, 494, 1482, 520, 1482, 494, 1508,
  16. 494, 520, 494, 1482, 494, 520, 494, 1482,
  17. 494, 1482, 494, 3978, 494, 520, 494, 520,
  18. 494, 520, 494, 520, 520, 520, 494, 520,
  19. 494, 520, 494, 520, 494};
  20. EOF
  21. exit 1
  22. }
  23. # We need a frequency argument.
  24. if [[ $# -ne 1 ]]; then
  25. usage
  26. fi
  27. HZ="$1"
  28. # HZ must be a positive number
  29. if ! isDigits "${HZ}"; then
  30. usage
  31. fi
  32. # HZ must not be zero.
  33. if [[ ${HZ} == 0 ]]; then
  34. usage
  35. fi
  36. PERIOD_OFFSET=0
  37. period=$((((1000000 + (${HZ} / 2)) / ${HZ}) + ${PERIOD_OFFSET}))
  38. result="${HZ},1,1"
  39. while read line; do
  40. # Quick and Dirty Removal of any array declaration syntax, and any commas.
  41. line="$(echo ${line} | sed 's/uint.*{//i' | sed 's/,//g' | sed 's/};.*//g')"
  42. for msecs in ${line}; do
  43. if isDigits "${msecs}"; then
  44. result="${result},$((${msecs} / ${period}))"
  45. fi
  46. done
  47. done
  48. echo "GlobalCache code = \"${result}\""