-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathblockClockUtils.cpp
70 lines (55 loc) · 1.46 KB
/
blockClockUtils.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "blockClockUtils.h"
#include "userBoardDefines.h"
#ifdef M5STACK
#include <M5StickCPlus.h>
#endif
#ifdef GENERIC_ESP32
#include <Arduino.h>
#endif
#include <esp_system.h>
ScreenState currentScreenState = BLOCKHEIGHT;
CurrencyState currentCurrencyState = BRL;
void changeScreenState() {
currentScreenState =
static_cast<ScreenState>((currentScreenState + 1) % NUM_SCREEN_STATES);
}
void changeCurrencyState() {
currentCurrencyState = static_cast<CurrencyState>((currentCurrencyState + 1) %
NUM_CURRENCIES_STATES);
}
String currencyStateToString(CurrencyState currency) {
static const String currencies[] = {"BRL", "USD"};
return currencies[currency];
}
String currencyStateToSymbol(CurrencyState currency) {
static const String currencies[] = {"R$", "US$"};
return currencies[currency];
}
String intWithThousandSeparator(int number) {
String numberStr = String(number);
int length = numberStr.length();
int pos = length % 3;
String result = "";
for (int i = 0; i < length; i++) {
if (i > 0 && i % 3 == pos) {
result += ".";
}
result += numberStr.charAt(i);
}
return result;
}
String truncateString(String input) {
if (input.length() > 10) {
input.remove(7);
input.concat("...");
}
return input;
}
String replaceCommaWithDot(String str) {
for (int i = 0; i < str.length(); i++) {
if (str[i] == ',') {
str[i] = '.';
}
}
return str;
}