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