upgrade.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. var cardInfo = {
  2. id: -1,
  3. responseTopic: '/upgradeCard' + getEpochMillis(),
  4. bgColor: 13,
  5. }
  6. // definitions for the program
  7. var elementId = {
  8. upgradeImage: 0
  9. };
  10. var upgradeImg = {
  11. splash: "upgrade"
  12. };
  13. function handleButtonInput (e) {
  14. if (typeof e.id !== 'undefined' &&
  15. typeof e.action !== 'undefined' &&
  16. typeof e.duration !== 'undefined' &&
  17. typeof e.multitouch !== 'undefined')
  18. {
  19. if (e.id === 14 && e.multitouch && e.duration >= 10000) {
  20. print('UPGRADE COMMAND DETECTED!');
  21. runUpgradeProgram()
  22. }
  23. }
  24. }
  25. function runUpgradeProgram () {
  26. system('sh /usr/bin/usbUpgrade.sh');
  27. }
  28. function setup() {
  29. connect('localhost', 1883, null, function () {
  30. subscribe('/button');
  31. print('Setup callback complete');
  32. });
  33. }
  34. function loop() {
  35. // do nothing
  36. }
  37. function onInput(e) {
  38. if (typeof e.source !== 'undefined' && typeof e.payload !== 'undefined' ) {
  39. print('input! input source: ' + e.source + ', value: ' + JSON.stringify(e.payload));
  40. if ( e.source === 'button') {
  41. handleButtonInput(e.payload);
  42. }
  43. }
  44. }
  45. function onMessage(e) {
  46. // do nothing
  47. // if (typeof e.topic !== 'undefined' && typeof e.payload !== 'undefined' ) {
  48. // print('message! topic: ' + e.topic + ', value: ' + e.payload);
  49. // switch (e.topic) {
  50. // case '/cardResponse':
  51. // cardInfo = handleCardResponseMessage(cardInfo, e.payload);
  52. // break;
  53. // default:
  54. // break;
  55. // }
  56. // }
  57. }