blank.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. var cardInfo = {
  2. id: -1,
  3. active: false,
  4. responseTopic: '/blankCard_' + getEpochMillis(),
  5. bgColor: -1,
  6. nightlight: [
  7. 0x4eb96f,
  8. 0xc44569,
  9. 0xf5cd79,
  10. 0x546de5
  11. ],
  12. params: {
  13. }
  14. }
  15. // definitions for the program
  16. var elementId = {
  17. background: 0,
  18. buttons: 1,
  19. };
  20. var cardImg = {
  21. background: "blank_bg",
  22. buttons: "blank_buttons",
  23. };
  24. // card functions
  25. function createCard () {
  26. //var cardObj = generateNewCardObj(cardInfo.bgColor, cardInfo.responseTopic);
  27. // init the card
  28. //initCard(JSON.stringify(cardObj));
  29. }
  30. // base functions
  31. function setup() {
  32. connect('localhost', 1883, null, function () {
  33. subscribe('/cardResponse', function () {
  34. createCard();
  35. });
  36. subscribe('/button');
  37. });
  38. }
  39. function loop() {
  40. //do nothing
  41. }
  42. function onInput(e) {
  43. if (typeof e.source !== 'undefined' && typeof e.payload !== 'undefined' ) {
  44. print('input! input source: ' + e.source);
  45. if ( e.source === 'button' &&
  46. e.payload.action === 'press' &&
  47. cardInfo.active === true
  48. )
  49. {
  50. switch(e.payload.id) {
  51. case 0:
  52. case '0':
  53. break;
  54. case 1:
  55. case '1':
  56. break;
  57. case 2:
  58. case '2':
  59. break;
  60. case 3:
  61. case '3':
  62. break;
  63. default:
  64. break;
  65. }
  66. }
  67. }
  68. }
  69. function onMessage(e) {
  70. if (typeof e.topic !== 'undefined' && typeof e.payload !== 'undefined' ) {
  71. print('message! topic: ' + e.topic + ', value: ' + e.payload);
  72. switch (e.topic) {
  73. case '/cardResponse':
  74. cardInfo = handleCardResponseMessage(cardInfo, e.payload);
  75. break;
  76. default:
  77. break;
  78. }
  79. }
  80. }