-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.cpp
36 lines (33 loc) · 1010 Bytes
/
common.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "common.h"
void drawNumber(Arduboy2 *gr, uint8_t x, uint8_t y, uint32_t number, uint8_t color, uint8_t padding) {
int8_t digit, maxPad, length = 1;
uint32_t tempNum = number;
while(tempNum /= 10) {
length++;
}
maxPad = max(length, padding);
tempNum = number;
while(maxPad > 0) {
maxPad--;
digit = tempNum % 10;
tempNum /= 10;
if(! digit && (maxPad + length - padding < 0)) continue;
gr->drawBitmap(x + (maxPad * 4), y, digitsBmp[digit], 3, 5, color);
}
}
int8_t buttonPressed(Arduboy2 *gr) {
return gr->justPressed(A_BUTTON) ||
gr->justPressed(B_BUTTON) ||
gr->justPressed(UP_BUTTON) ||
gr->justPressed(DOWN_BUTTON) ||
gr->justPressed(LEFT_BUTTON) ||
gr->justPressed(RIGHT_BUTTON);
}
int8_t buttonReleased(Arduboy2 *gr) {
return gr->justReleased(A_BUTTON) ||
gr->justReleased(B_BUTTON) ||
gr->justReleased(UP_BUTTON) ||
gr->justReleased(DOWN_BUTTON) ||
gr->justReleased(LEFT_BUTTON) ||
gr->justReleased(RIGHT_BUTTON);
}