Sin descripción

eboled.js 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*jslint node:true, vars:true, bitwise:true, unparam:true */
  2. /*jshint unused:true */
  3. /*
  4. * Author: Jon Trulson <jtrulson@ics.com>
  5. * Copyright (c) 2015 Intel Corporation.
  6. *
  7. * Author: Tyler Gibson <tgibson@microsoft.com>
  8. * Copyright (c) 2015 Microsoft Corporation.
  9. *
  10. * Permission is hereby granted, free of charge, to any person obtaining
  11. * a copy of this software and associated documentation files (the
  12. * "Software"), to deal in the Software without restriction, including
  13. * without limitation the rights to use, copy, modify, merge, publish,
  14. * distribute, sublicense, and/or sell copies of the Software, and to
  15. * permit persons to whom the Software is furnished to do so, subject to
  16. * the following conditions:
  17. *
  18. * The above copyright notice and this permission notice shall be
  19. * included in all copies or substantial portions of the Software.
  20. *
  21. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. */
  29. var lcdObj = require('jsupm_i2clcd');
  30. var oled = new lcdObj.EBOLED();
  31. var sample = 0;
  32. var samples = 13;
  33. function exit()
  34. {
  35. oled = null;
  36. lcdObj.cleanUp();
  37. lcdObj = null;
  38. process.exit(0);
  39. }
  40. setInterval( function()
  41. {
  42. if(sample>samples)
  43. {
  44. exit();
  45. }
  46. oled.clearScreenBuffer();
  47. runSample(sample++);
  48. oled.refresh();
  49. }, 1500);
  50. function runSample(sample)
  51. {
  52. switch(sample) {
  53. case 0:
  54. // x/y coords are 0 based, using 1 here for padding.
  55. oled.setCursor(1,1);
  56. // nowrap = 0, wrapping = 1
  57. oled.setTextWrap(1);
  58. oled.write("HELLO WORLD! Mixed with #123 and y's, g's and q's.");
  59. break;
  60. case 1:
  61. oled.setCursor(12, 1);
  62. //multiply text size, only integers
  63. oled.setTextSize(3);
  64. oled.write("BOO!");
  65. oled.setTextSize(1);
  66. break;
  67. case 2:
  68. oled.drawRectangleFilled(0,0,48,9);
  69. oled.setCursor(1,1);
  70. // 0=Black, 1=White, 2=Xor (Toggle)
  71. oled.setTextColor(2);
  72. oled.write("Cutout");
  73. break;
  74. case 3:
  75. var total = Math.random()*100;
  76. for(var stars=0; stars<total; stars++ )
  77. oled.drawPixel(Math.floor(Math.random()*63), Math.floor(Math.random()*47), 1);
  78. break;
  79. case 4:
  80. for(var burst=0; burst<12; burst++)
  81. oled.drawLine(31, 24, Math.floor(Math.random()*63), Math.floor(Math.random()*47), 1);
  82. break;
  83. case 5:
  84. var lastPeak = 24;
  85. for(var peak=0; peak < 64; peak++)
  86. {
  87. var thisPeak = Math.abs(lastPeak + Math.floor(Math.random()*(-6) + Math.random()*6));
  88. oled.drawLine(peak, thisPeak, peak, 47, 1);
  89. lastPeak = thisPeak;
  90. }
  91. break;
  92. case 6:
  93. for(var y=0; y<47; y++)
  94. {
  95. oled.drawLineHorizontal(0,y+1,63,2);
  96. oled.refresh();
  97. oled.drawLineHorizontal(0,y,63,2);
  98. }
  99. break;
  100. case 7:
  101. var eqbarHeights = [ Math.floor(Math.random()*32),
  102. Math.floor(Math.random()*32),
  103. Math.floor(Math.random()*32),
  104. Math.floor(Math.random()*32),
  105. Math.floor(Math.random()*32),
  106. Math.floor(Math.random()*32),
  107. Math.floor(Math.random()*32) ];
  108. var begin = Date.now();
  109. while(Date.now()-begin < 2000)
  110. {
  111. oled.clearScreenBuffer();
  112. for(var eqbar=0; eqbar<7; eqbar++)
  113. {
  114. oled.drawRectangleFilled(eqbar*9, 49 - eqbarHeights[eqbar], 8, eqbarHeights[eqbar], 1);
  115. eqbarHeights[eqbar] = eqbarHeights[eqbar] + Math.random()*(-2) + Math.random()*2;
  116. if(eqbarHeights[eqbar]<0)
  117. eqbarHeights[eqbar] = 1;
  118. }
  119. oled.refresh();
  120. }
  121. oled.clear();
  122. break;
  123. case 8:
  124. oled.drawRoundedRectangle(8, 8, 48, 16, 4, 1);
  125. oled.setCursor(12, 16);
  126. oled.write("Cancel");
  127. break;
  128. case 9:
  129. oled.drawTriangle(2, 2, 52, 7, 17, 37, 1);
  130. break;
  131. case 10:
  132. oled.drawTriangleFilled(2, 2, 52, 7, 17, 37, 1);
  133. break;
  134. case 11:
  135. oled.drawCircle(32, 24, 14, 1);
  136. break;
  137. case 12:
  138. oled.drawCircleFilled(32, 24, 14, 1);
  139. break;
  140. case 13:
  141. oled.fillScreen(1);
  142. break;
  143. }
  144. }