Numworks Epsilon  1.4.1
Graphing Calculator Operating System
display.cpp
Go to the documentation of this file.
1 #include "command.h"
2 #include <ion.h>
4 
5 namespace Ion {
6 namespace Device {
7 namespace Bench {
8 namespace Command {
9 
10 // Input must be of the form "0xAABBCC" or "ON" or "OFF"
11 void Display(const char * input) {
12 
13  if (strcmp(input, sON) == 0) {
15  reply(sOK);
16  return;
17  }
18  if (strcmp(input, sOFF) == 0) {
20  reply(sOK);
21  return;
22  }
23  if (input == nullptr || input[0] != '0' || input[1] != 'x' || !isHex(input[2]) ||!isHex(input[3]) || !isHex(input[4]) || !isHex(input[5]) || !isHex(input[6]) || !isHex(input[7]) || input[8] != NULL) {
25  return;
26  }
27 
28  /* We fill the screen with a color and return OK if we read that color back everywhere. */
29 
31 
32  constexpr int stampHeight = 10;
33  constexpr int stampWidth = 10;
34  static_assert(Ion::Display::Width % stampWidth == 0, "Stamps must tesselate the display");
35  static_assert(Ion::Display::Height % stampHeight == 0, "Stamps must tesselate the display");
36  static_assert(stampHeight % 2 == 0 || stampWidth % 2 == 0, "Even number of XOR needed.");
37 
38  KDColor stamp[stampWidth*stampHeight];
39  for (int i=0;i<stampWidth*stampHeight; i++) {
40  stamp[i] = c;
41  }
42 
43  for (int i=0; i<Ion::Display::Width/stampWidth; i++) {
44  for (int j=0; j<Ion::Display::Height/stampHeight; j++) {
45  Ion::Display::pushRect(KDRect(i*stampWidth, j*stampHeight, stampWidth, stampHeight), stamp);
46  }
47  }
48 
49  for (int i=0; i<Ion::Display::Width/stampWidth; i++) {
50  for (int j=0; j<Ion::Display::Height/stampHeight; j++) {
51  for (int i=0;i<stampWidth*stampHeight; i++) {
52  stamp[i] = KDColorBlack;
53  }
54  Ion::Display::pullRect(KDRect(i*stampWidth, j*stampHeight, stampWidth, stampHeight), stamp);
55  for (int i=0;i<stampWidth*stampHeight; i++) {
56  if (stamp[i] != c) {
57  reply(sKO);
58  return;
59  }
60  }
61  }
62  }
63 
64  reply(sOK);
65 }
66 
67 }
68 }
69 }
70 }
const char *const sOK
Definition: command.cpp:9
constexpr int Width
Definition: display.h:26
void Display(const char *input)
Definition: display.cpp:11
void pullRect(KDRect r, KDColor *pixels)
Definition: display.cpp:26
const char *const sSyntaxError
Definition: command.cpp:11
void pushRect(KDRect r, const KDColor *pixels)
Definition: display.cpp:14
const char *const sON
Definition: command.cpp:12
const char *const sOFF
Definition: command.cpp:13
c(generic_all_nodes)
#define NULL
Definition: stddef.h:4
const char *const sKO
Definition: command.cpp:10
uint32_t hexNumber(const char *s, int maxLength)
Definition: command.cpp:33
constexpr KDColor KDColorBlack
Definition: color.h:41
Definition: rect.h:26
Definition: color.h:6
void reply(const char *s)
Definition: command.cpp:15
int strcmp(const char *s1, const char *s2)
Definition: strcmp.c:3
Definition: backlight.h:6
constexpr int Height
Definition: display.h:27
static constexpr KDColor RGB24(uint32_t rgb)
Definition: color.h:13