Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit 7f7911b

Browse files
cuiyanxgrgustaf
authored andcommitted
[tests] Add manual tests for Grove LCD APIs (#464)
1 parent cdd23ac commit 7f7911b

File tree

3 files changed

+283
-0
lines changed

3 files changed

+283
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Copyright (c) 2016, Intel Corporation.
2+
3+
console.log("test cursor position");
4+
5+
var grove_lcd = require("grove_lcd");
6+
7+
var glcd = grove_lcd.init();
8+
9+
var displays = [
10+
grove_lcd.GLCD_DS_DISPLAY_ON,
11+
grove_lcd.GLCD_DS_DISPLAY_OFF,
12+
grove_lcd.GLCD_DS_CURSOR_ON,
13+
grove_lcd.GLCD_DS_CURSOR_OFF,
14+
grove_lcd.GLCD_DS_BLINK_ON,
15+
grove_lcd.GLCD_DS_BLINK_OFF
16+
];
17+
18+
var cursorFlag = true;
19+
var cursorCol = -1;
20+
var cursorRow = 0;
21+
var cursorCount = 0;
22+
23+
glcd.setCursorPos(0, 0);
24+
glcd.setDisplayState(displays[0] | displays[2]);
25+
glcd.print("cursor position");
26+
27+
var cycleTimer = setInterval(function () {
28+
if (cursorCount === 0) {
29+
glcd.setCursorPos(6, 1);
30+
glcd.print("BLINK");
31+
glcd.setDisplayState(displays[0] | displays[2] | displays[4]);
32+
33+
console.log("set cursor as 'on' and blink");
34+
}
35+
36+
if (cursorCount === 64) {
37+
glcd.clear();
38+
glcd.setCursorPos(6, 1);
39+
glcd.print("_END_");
40+
glcd.setDisplayState(displays[0] | displays[3]);
41+
42+
console.log("Testing completed");
43+
44+
clearInterval(cycleTimer);
45+
}
46+
47+
if (cursorFlag) {
48+
cursorCol++;
49+
} else {
50+
cursorCol--;
51+
}
52+
53+
if (cursorCount <= 31) {
54+
if (cursorCol === 16) {
55+
cursorFlag = false;
56+
cursorCol = 15;
57+
cursorRow = 1;
58+
}
59+
}
60+
61+
if (cursorCount === 32) {
62+
cursorFlag = true;
63+
glcd.setCursorPos(5, 1);
64+
glcd.print("NOBLINK");
65+
cursorCol = 0;
66+
cursorRow = 1;
67+
glcd.setDisplayState(displays[0] | displays[2]);
68+
69+
console.log("set cursor as 'on' and no blink");
70+
}
71+
72+
if (32 <= cursorCount && cursorCount <= 63) {
73+
if (cursorCol === 16) {
74+
cursorFlag = false;
75+
cursorCol = 15;
76+
cursorRow = 0;
77+
}
78+
}
79+
80+
if (cursorCount <= 63) {
81+
glcd.setCursorPos(cursorCol, cursorRow);
82+
83+
console.log("setCursorPos(col, row): expected result "
84+
+ cursorCol + ", " + cursorRow);
85+
}
86+
87+
cursorCount++;
88+
}, 1000);

tests/test-grovelcd-ds-manual.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright (c) 2016, Intel Corporation.
2+
3+
console.log("test GroveLCD display");
4+
5+
var grove_lcd = require("grove_lcd");
6+
7+
var glcd = grove_lcd.init();
8+
9+
var funs = [
10+
grove_lcd.GLCD_FS_ROWS_1,
11+
grove_lcd.GLCD_FS_ROWS_2,
12+
grove_lcd.GLCD_FS_8BIT_MODE,
13+
grove_lcd.GLCD_FS_DOT_SIZE_BIG,
14+
grove_lcd.GLCD_FS_DOT_SIZE_LITTLE
15+
];
16+
17+
var index = [
18+
[0, 2, "ROW1, 8BIT"],
19+
[1, 2, "ROW2, 8BIT"],
20+
[2, 3, "8BIT, BIG"],
21+
[2, 4, "8BIT, LIT"],
22+
[0, 3, "ROW1, BIG"],
23+
[0, 4, "ROW1, LIT"],
24+
[1, 3, "ROW2, BIG"],
25+
[1, 4, "ROW2, LIT"],
26+
[0, 2, 3, "ROW1, 8BIT, BIG"],
27+
[0, 2, 4, "ROW1, 8BIT, LIT"],
28+
[1, 2, 3, "ROW2, 8BIT, BIG"],
29+
[1, 2, 4, "ROW2, 8BIT, LIT"]
30+
];
31+
32+
glcd.setColor(50, 50, 50);
33+
34+
var count = 0;
35+
var funcConfig;
36+
37+
var timer = setInterval(function () {
38+
if (count === index.length) {
39+
glcd.clear();
40+
glcd.setCursorPos(6, 1);
41+
glcd.print("_END_");
42+
43+
console.log("Testing completed");
44+
45+
clearInterval(timer);
46+
}
47+
48+
if (index[count].length === 3) {
49+
funcConfig = funs[index[count][0]]
50+
| funs[index[count][1]];
51+
glcd.setFunction(funcConfig);
52+
53+
glcd.clear();
54+
glcd.setCursorPos(0, 0);
55+
glcd.print(index[count][2]);
56+
57+
console.log("setFunction(row, mode, dot): expected result "
58+
+ index[count][2]);
59+
}
60+
61+
if (index[count].length === 4) {
62+
funcConfig = funs[index[count][0]]
63+
| funs[index[count][1]]
64+
| funs[index[count][2]];
65+
glcd.setFunction(funcConfig);
66+
67+
glcd.clear();
68+
glcd.setCursorPos(0, 0);
69+
glcd.print(index[count][3]);
70+
71+
console.log("setFunction(row, mode, dot): expected result "
72+
+ index[count][3]);
73+
}
74+
75+
count++;
76+
}, 5000);

tests/test-grovelcd-rgb-manual.js

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// Copyright (c) 2016, Intel Corporation.
2+
3+
console.log("test RGB color");
4+
5+
var grove_lcd = require("grove_lcd");
6+
7+
var glcd = grove_lcd.init();
8+
9+
var colorNum = [
10+
[255, 0, 0],
11+
[0, 255, 0],
12+
[0, 0, 255],
13+
[255, 255, 0],
14+
[255, 0, 255],
15+
[0, 255, 255],
16+
[255, 255, 255]
17+
];
18+
19+
var colorName = [
20+
" red ",
21+
"green ",
22+
" blue ",
23+
"yellow",
24+
"purple",
25+
" cyan ",
26+
"white "
27+
];
28+
29+
var displayConfig = grove_lcd.GLCD_DS_DISPLAY_ON
30+
| grove_lcd.GLCD_DS_CURSOR_OFF;
31+
glcd.setDisplayState(displayConfig);
32+
33+
glcd.setCursorPos(1, 0);
34+
glcd.print("Color Gradient");
35+
36+
var flag = true;
37+
var redFlag = colorNum[0][0];
38+
var greenFlag = colorNum[0][1];
39+
var blueFlag = colorNum[0][2];
40+
var redNum = 0;
41+
var greenNum = 0;
42+
var blueNum = 0;
43+
var colorCount = 0;
44+
var count = 0;
45+
46+
var colorGradient = setInterval(function () {
47+
glcd.setCursorPos(5, 1);
48+
glcd.print(colorName[colorCount]);
49+
50+
if (count === 102) {
51+
colorCount++;
52+
count = 0;
53+
54+
if (colorCount === 7) {
55+
glcd.clear();
56+
glcd.setCursorPos(6, 1);
57+
glcd.print("_END_");
58+
59+
console.log("Testing completed");
60+
61+
clearInterval(colorGradient);
62+
}
63+
64+
redFlag = colorNum[colorCount][0];
65+
greenFlag = colorNum[colorCount][1];
66+
blueFlag = colorNum[colorCount][2];
67+
}
68+
69+
if (count === 0) {
70+
console.log("setColor(R, G, B): expected result "
71+
+ redFlag + ", " + greenFlag + ", " + blueFlag);
72+
console.log("color gradient: " + colorName[colorCount]);
73+
}
74+
75+
if (redNum === 255 || greenNum === 255 || blueNum === 255) {
76+
flag = false;
77+
}
78+
79+
if (flag) {
80+
if (redFlag > 0) {
81+
redNum += 5;
82+
}
83+
84+
if (greenFlag > 0) {
85+
greenNum += 5;
86+
}
87+
88+
if (blueFlag > 0) {
89+
blueNum += 5;
90+
}
91+
} else {
92+
if (redFlag > 0) {
93+
redNum -= 5;
94+
95+
if (redNum === 0) {
96+
flag = true;
97+
}
98+
}
99+
100+
if (greenFlag > 0) {
101+
greenNum -= 5;
102+
103+
if (greenNum === 0) {
104+
flag = true;
105+
}
106+
}
107+
108+
if (blueFlag > 0) {
109+
blueNum -= 5;
110+
111+
if (blueNum === 0) {
112+
flag = true;
113+
}
114+
}
115+
}
116+
117+
glcd.setColor(redNum, greenNum, blueNum);
118+
count++;
119+
}, 100);

0 commit comments

Comments
 (0)