Skip to content

Commit 25f1642

Browse files
authored
Merge pull request #10 from m5stack/develop
Add CardputerADV support
2 parents add8b6f + 8ab9f43 commit 25f1642

22 files changed

+1709
-287
lines changed

.clang-format

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
BasedOnStyle: Google
2+
AccessModifierOffset: -4
3+
AlignAfterOpenBracket: Align
4+
AlignConsecutiveMacros: true
5+
AlignConsecutiveAssignments: true
6+
AlignConsecutiveDeclarations: false
7+
AlignEscapedNewlines: Left
8+
AlignOperands: true
9+
AlignTrailingComments: true
10+
AllowAllArgumentsOnNextLine: true
11+
AllowAllConstructorInitializersOnNextLine: true
12+
AllowAllParametersOfDeclarationOnNextLine: true
13+
AllowShortBlocksOnASingleLine: Never
14+
AllowShortCaseLabelsOnASingleLine: false
15+
AllowShortFunctionsOnASingleLine: false
16+
AllowShortLambdasOnASingleLine: All
17+
AllowShortIfStatementsOnASingleLine: WithoutElse
18+
AllowShortLoopsOnASingleLine: true
19+
AlwaysBreakAfterDefinitionReturnType: None
20+
AlwaysBreakAfterReturnType: None
21+
AlwaysBreakBeforeMultilineStrings: true
22+
AlwaysBreakTemplateDeclarations: Yes
23+
BinPackArguments: true
24+
BinPackParameters: true
25+
BraceWrapping:
26+
AfterCaseLabel: false
27+
AfterClass: false
28+
AfterControlStatement: false
29+
AfterEnum: false
30+
AfterFunction: true
31+
AfterNamespace: false
32+
AfterObjCDeclaration: false
33+
AfterStruct: false
34+
AfterUnion: false
35+
AfterExternBlock: false
36+
BeforeCatch: false
37+
BeforeElse: false
38+
IndentBraces: false
39+
SplitEmptyFunction: true
40+
SplitEmptyRecord: true
41+
SplitEmptyNamespace: true
42+
BreakBeforeBinaryOperators: None
43+
BreakBeforeBraces: Custom
44+
BreakBeforeInheritanceComma: false
45+
BreakInheritanceList: BeforeColon
46+
BreakBeforeTernaryOperators: true
47+
BreakConstructorInitializersBeforeComma: false
48+
BreakConstructorInitializers: BeforeColon
49+
BreakAfterJavaFieldAnnotations: false
50+
BreakStringLiterals: true
51+
ColumnLimit: 120
52+
CommentPragmas: '^ IWYU pragma:'
53+
CompactNamespaces: false
54+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
55+
ConstructorInitializerIndentWidth: 4
56+
ContinuationIndentWidth: 4
57+
Cpp11BracedListStyle: true
58+
DeriveLineEnding: true
59+
DerivePointerAlignment: true
60+
DisableFormat: false
61+
ExperimentalAutoDetectBinPacking: false
62+
FixNamespaceComments: true
63+
ForEachMacros:
64+
- foreach
65+
- Q_FOREACH
66+
- BOOST_FOREACH
67+
IncludeBlocks: Regroup
68+
IncludeCategories:
69+
- Regex: '^<ext/.*\.h>'
70+
Priority: 2
71+
SortPriority: 0
72+
- Regex: '^<.*\.h>'
73+
Priority: 1
74+
SortPriority: 0
75+
- Regex: '^<.*'
76+
Priority: 2
77+
SortPriority: 0
78+
- Regex: '.*'
79+
Priority: 3
80+
SortPriority: 0
81+
IncludeIsMainRegex: '([-_](test|unittest))?$'
82+
IncludeIsMainSourceRegex: ''
83+
IndentCaseLabels: true
84+
IndentGotoLabels: true
85+
IndentPPDirectives: None
86+
IndentWidth: 4
87+
IndentWrappedFunctionNames: false
88+
JavaScriptQuotes: Leave
89+
JavaScriptWrapImports: true
90+
KeepEmptyLinesAtTheStartOfBlocks: false
91+
MacroBlockBegin: ''
92+
MacroBlockEnd: ''
93+
MaxEmptyLinesToKeep: 1
94+
NamespaceIndentation: None
95+
ObjCBinPackProtocolList: Never
96+
ObjCBlockIndentWidth: 2
97+
ObjCSpaceAfterProperty: false
98+
ObjCSpaceBeforeProtocolList: true
99+
PenaltyBreakAssignment: 2
100+
PenaltyBreakBeforeFirstCallParameter: 1
101+
PenaltyBreakComment: 300
102+
PenaltyBreakFirstLessLess: 120
103+
PenaltyBreakString: 1000
104+
PenaltyBreakTemplateDeclaration: 10
105+
PenaltyExcessCharacter: 1000000
106+
PenaltyReturnTypeOnItsOwnLine: 200
107+
PointerAlignment: Left
108+
RawStringFormats:
109+
- Language: Cpp
110+
Delimiters:
111+
- cc
112+
- CC
113+
- cpp
114+
- Cpp
115+
- CPP
116+
- 'c++'
117+
- 'C++'
118+
CanonicalDelimiter: ''
119+
BasedOnStyle: google
120+
- Language: TextProto
121+
Delimiters:
122+
- pb
123+
- PB
124+
- proto
125+
- PROTO
126+
EnclosingFunctions:
127+
- EqualsProto
128+
- EquivToProto
129+
- PARSE_PARTIAL_TEXT_PROTO
130+
- PARSE_TEST_PROTO
131+
- PARSE_TEXT_PROTO
132+
- ParseTextOrDie
133+
- ParseTextProtoOrDie
134+
CanonicalDelimiter: ''
135+
BasedOnStyle: google
136+
ReflowComments: true
137+
SortIncludes: false
138+
SortUsingDeclarations: true
139+
SpaceAfterCStyleCast: false
140+
SpaceAfterLogicalNot: false
141+
SpaceAfterTemplateKeyword: true
142+
SpaceBeforeAssignmentOperators: true
143+
SpaceBeforeCpp11BracedList: false
144+
SpaceBeforeCtorInitializerColon: true
145+
SpaceBeforeInheritanceColon: true
146+
SpaceBeforeParens: ControlStatements
147+
SpaceBeforeRangeBasedForLoopColon: true
148+
SpaceInEmptyBlock: false
149+
SpaceInEmptyParentheses: false
150+
SpacesBeforeTrailingComments: 2
151+
SpacesInAngles: false
152+
SpacesInConditionalStatement: false
153+
SpacesInContainerLiterals: true
154+
SpacesInCStyleCastParentheses: false
155+
SpacesInParentheses: false
156+
SpacesInSquareBrackets: false
157+
SpaceBeforeSquareBrackets: false
158+
Standard: Auto
159+
StatementMacros:
160+
- Q_UNUSED
161+
- QT_REQUIRE_VERSION
162+
TabWidth: 4
163+
UseCRLF: false
164+
UseTab: Never

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# M5Cardputer
33

4-
## Basic library for M5Stack M5Cardputer Board
4+
## Basic library for M5Stack M5Cardputer and M5Cardputer-ADV Board
55

66

77
License

examples/UI/REPL/REPL.ino

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
#include "ReplView.h"
7+
#include <M5Cardputer.h>
8+
9+
LGFX_Sprite *canvas;
10+
ReplView repl_view;
11+
long the_number = 2333;
12+
bool is_player_win = false;
13+
14+
bool string_to_number(const char *str, long *out)
15+
{
16+
if (str == NULL || *str == '\0') {
17+
return false;
18+
}
19+
20+
char *end;
21+
long value = strtol(str, &end, 10);
22+
23+
if (*end != '\0') {
24+
return false;
25+
}
26+
27+
if (value < -999 || value > 999) {
28+
return false;
29+
}
30+
31+
*out = value;
32+
return true;
33+
}
34+
35+
void handle_command(const std::string &command)
36+
{
37+
/* If player win, show the message */
38+
if (is_player_win) {
39+
repl_view.showMessage(command, TFT_CYAN);
40+
return;
41+
}
42+
43+
/* Convert input to number */
44+
long number = 0;
45+
if (!string_to_number(command.c_str(), &number)) {
46+
repl_view.showMessage("Invaild input :(", TFT_RED);
47+
return;
48+
}
49+
50+
/* Compare */
51+
if (number == the_number) {
52+
repl_view.showMessage("Correct! :)", TFT_GREENYELLOW);
53+
is_player_win = true;
54+
} else if (number > the_number) {
55+
repl_view.showMessage("Too high!", TFT_CYAN);
56+
} else {
57+
repl_view.showMessage("Too low!", TFT_CYAN);
58+
}
59+
}
60+
61+
void setup()
62+
{
63+
M5Cardputer.begin();
64+
65+
/* Create a full screen canvas for view */
66+
canvas = new LGFX_Sprite(&M5Cardputer.Display);
67+
canvas->createSprite(M5Cardputer.Display.width(), M5Cardputer.Display.height());
68+
69+
/* Init REPL view, setup callbacks */
70+
repl_view.onCommand = handle_command;
71+
repl_view.onRenderTips = []() {
72+
canvas->setTextColor(TFT_CYAN);
73+
canvas->println("Guess the number");
74+
canvas->println("The number is between\n-999 and 999 :D");
75+
};
76+
repl_view.init(canvas);
77+
78+
/* Get a random number */
79+
the_number = random(-999, 999);
80+
}
81+
82+
void loop()
83+
{
84+
/* Keep updating */
85+
M5Cardputer.update();
86+
repl_view.update();
87+
}

0 commit comments

Comments
 (0)