Skip to content

Commit 8561619

Browse files
Laurence BankLaurence Bank
authored andcommitted
Improved usability
1 parent eeb6586 commit 8561619

File tree

1 file changed

+38
-23
lines changed

1 file changed

+38
-23
lines changed

examples/Arduino/gray_matrix_editor/gray_matrix_editor.ino

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,29 @@ FASTEPD epaper;
1616
uint8_t ucTemp[64];
1717
uint8_t u8_last[16 * 48]; // to allow UNDO of a single change
1818
// Starting gray matrix. Copy your current one here before compiling/running the program
19+
// This should normally be "const" data so that it gets written to FLASH, but for this
20+
// program to be able to edit the values, it needs to be declared so it loads in RAM
1921
uint8_t u8_graytable[] = {
20-
/* 0 */ 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0,
21-
/* 1 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 1, 1, 1, 0, 0, 0, 0,
22-
/* 2 */ 0, 0, 0, 0, 0, 1, 1, 1, 2, 1, 1, 1, 2, 1, 0, 0, 0, 0,
23-
/* 3 */ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 1, 0, 0, 0, 0, 0,
24-
/* 4 */ 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 1, 0, 0, 0, 0, 0, 0,
25-
/* 5 */ 0, 0, 0, 0, 0, 1, 0, 0, 1, 2, 0, 1, 0, 0, 0, 0, 0, 0,
26-
/* 6 */ 0, 0, 0, 0, 0, 1, 2, 0, 1, 2, 0, 1, 0, 0, 0, 0, 0, 0,
27-
/* 7 */ 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 0, 0, 0,
28-
/* 8 */ 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 1, 2, 1, 0, 0, 0, 0, 0,
29-
/* 9 */ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 0, 0, 0,
30-
/* 10 */ 0, 0, 0, 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0, 0, 1, 1, 1, 2, 0, 0, 0,
33+
/* 11 */ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 1, 2, 0, 0,
34+
/* 12 */ 0, 0, 0, 0, 0, 1, 1, 2, 1, 2, 0, 0, 0, 0, 0, 0, 0,
35+
/* 13 */ 0, 0, 0, 0, 1, 1, 2, 2, 2, 2, 1, 2, 0, 0, 0, 0, 0,
36+
/* 14 */ 0, 0, 0, 1, 1, 2, 2, 1, 2, 2, 0, 0, 0, 0, 0, 0, 0,
37+
/* 15 */ 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
3638
};
37-
3839
static int passes; // Calculated at startup based on the matrix size
3940
// List of supported commands
40-
const char *szCMDs[] = {"HELP", "LIST", "SHOW", "COPY", "SWAP", "EDIT", "UNDO", 0};
41+
const char *szCMDs[] = {"HELP", "LIST", "SHOW", "COPY", "SWAP", "EDIT", "UNDO", "CODE", 0};
4142
enum {
4243
CMD_HELP = 0,
4344
CMD_LIST,
@@ -46,6 +47,7 @@ enum {
4647
CMD_SWAP,
4748
CMD_EDIT,
4849
CMD_UNDO,
50+
CMD_CODE,
4951
CMD_COUNT
5052
};
5153

@@ -144,17 +146,18 @@ void showHelp()
144146
Serial.println("Interactive FastEPD gray matrix editor command list");
145147
Serial.println("(case insensitive, decimal numbers assumed, space or comma delimited)");
146148
Serial.println("HELP - This command list");
147-
Serial.println("LIST - show the current gray matrix values");
149+
Serial.println("LIST n - show a row of gray matrix values to copy/edit");
148150
Serial.println("SHOW - Display the gray matrix on the EPD panel");
149151
Serial.println("COPY n m - copy row n to row m");
150152
Serial.println("SWAP n m - swap the contents of row n with row m");
151153
Serial.println("EDIT n 0 1 2 2 1 0 0... write new values for row n");
152154
Serial.println("UNDO - undo the last change (only 1 step is reversible)");
155+
Serial.println("CODE - generate the code for the current gray matrix");
153156
} /* showHelp() */
154157

155158
// List the current values of the gray matrix in a form that can be easily copied
156159
// back into your code
157-
void ListMatrix(void)
160+
void ListCode(void)
158161
{
159162
int i, j;
160163
uint8_t *s;
@@ -174,7 +177,7 @@ void ListMatrix(void)
174177
Serial.print("\n");
175178
} // for i
176179
Serial.print("};\n");
177-
} /* ListMatrix() */
180+
} /* ListCode() */
178181

179182
// Display the grayscale test image on the panel to see how your current gray matrix performs
180183
void ShowMatrix(void)
@@ -209,12 +212,24 @@ uint8_t *s, *d;
209212
case CMD_HELP:
210213
showHelp();
211214
break;
212-
case CMD_LIST:
213-
ListMatrix();
215+
case CMD_CODE:
216+
ListCode();
214217
break;
215218
case CMD_SHOW:
216219
ShowMatrix();
217220
break;
221+
case CMD_LIST:
222+
if (pData[1] < 0 || pData[1] > 15) {
223+
Serial.println("LIST: Row must be in the range 0 to 15");
224+
return;
225+
}
226+
Serial.printf("EDIT %d ", pData[1]);
227+
s = &u8_graytable[passes * pData[1]];
228+
for (i=0; i<passes; i++) {
229+
Serial.printf("%d ", s[i]);
230+
}
231+
Serial.print("\n");
232+
break;
218233
case CMD_COPY:
219234
if (pData[1] < 0 || pData[1] > 15 || pData[2] < 0 || pData[2] > 15) {
220235
Serial.println("COPY: Source/Dest rows must be in the range 0 to 15");

0 commit comments

Comments
 (0)