This is an RPN calculator for the M5 Cardputer. It’s currently a work in progress.
Clone the repo, open it in the Arduino IDE (you can follow this: https://docs.m5stack.com/en/arduino/m5cardputer/program), build it, and deploy it.
Alternatively, you can download the .bin from the Releases page, then flash it or put it on the SD card if you have a launcher.
afterOperation()
This is intended to be the place where I explain the architecture of the project for newcomers (and my future self once come back to this project in 5 months and forget everything)
Here’s how most of it works:
sprintf
inside getModeString()
onKeyPress(char c)
,onCtrlKeyPress(char c)
, etc.)keys.h
and runs the respective actionkeys.h
there are #define
s for every action on the calculator, and the key press functions should usually only use keys from these #define
s, not hard-coded keys (common exceptions include 0-9 for numbers and A-F in HEX mode)t
) open up menus where other keys (ex. s
) can do different actions than normal (ex. sin(x)
)keys.h
and look like CALC_KEY_CHORD_[THING]
onKeyPress()
function, inside the else
not the if (chord!=0)
keys.h
and look like CALC_KEY_[THING]_[ACTION]
if (chord!=0)
section in onKeyPress()
X
,Y
,Z
, and T
NUMBER_TYPE
, which can be changed if needed. I did this for future proofing, like if long double
s are needed instead of regular double
sclearAll()
, shiftDown()
, and shiftUp()
functions can be used to modify the stackafterOperation()
(the name could use some work) at the end to shift things down, which erases Y and doesn’t affect X (because it’s the new result)HistoryItem
// In keys.h
// ...
// Chord starters
#define CALC_KEY_CHORD_LOG 'l'
// ...
// Chord sub-keys
#define CALC_KEY_LOG_10 'l'
#define CALC_KEY_LOG_2 '2'
#define CALC_KEY_LOG_X 'x'
#define CALC_KEY_LOG_NATURAL 'e'
// ...
X -> Y^X
// In cardcalc.ino
void onKeyPress(char key) {
// ...
if (chord != 0) {
// ...
} else {
// ...
switch (key) {
// ...
case CALC_KEY_POWER:
X = pow(Y, X);
afterOperation();
break;
// ...
}
// ...
}
// ...
}