MCPcopy Create free account
hub / github.com/SmingHub/Sming / testDisplay

Function testDisplay

samples/Display_TM1637/app/application.cpp:25–150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23SimpleTimer stateTimer;
24
25bool testDisplay()
26{
27 static uint8_t state;
28 static uint8_t subState;
29
30#define STATE(fmt, ...) debug_i("#%u.%u " fmt, state, subState, ##__VA_ARGS__);
31
32 switch(state) {
33 case 0: {
34 // All segments on
35 STATE("All segments on");
36 display.setBrightness(7);
37 display.setSegments(SEG_ALL_ON);
38 break;
39 }
40 case 1: {
41 // Selectively set different digits
42 uint8_t pos = 3 - subState;
43 STATE("setSegments(data, 1, %u)", pos);
44 const uint8_t seg = 0b01001001;
45 display.setSegments(&seg, 1, pos);
46 if(subState++ < 3) {
47 return false;
48 }
49 break;
50 }
51 case 2: {
52 uint8_t data[]{
53 display.encodeDigit(1),
54 display.encodeDigit(2),
55 display.encodeDigit(3),
56 };
57 uint8_t length = (subState == 2) ? 3 : 2;
58 uint8_t pos = (subState == 0) ? 2 : 1;
59 STATE("setSegments([0x%02x, 0x%02x, 0x%02x], %u, %u)", data[0], data[1], data[2], length, pos);
60 display.setSegments(data, length, pos);
61 if(subState++ < 3) {
62 return false;
63 }
64 break;
65 }
66 case 3:
67 case 4: {
68 // Show decimal numbers with/without leading zeros
69 static unsigned k;
70 if(subState == 0) {
71 k = 0;
72 ++subState;
73 }
74 bool showLeadingZeroes = (state == 4);
75 STATE("showNumberDec(%u, %u)", k, showLeadingZeroes);
76 display.showNumberDec(k, showLeadingZeroes);
77 k += k * 4 + 7;
78 if(k < 10000) {
79 return false;
80 }
81 break;
82 }

Callers 1

initFunction · 0.85

Calls 1

setBrightnessMethod · 0.45

Tested by

no test coverage detected