Fix saving on Pebble. Break funcs into '...' menu

Bump to 0.2
This commit is contained in:
= 2020-05-21 17:57:24 +01:00
parent 3dee4eb8dc
commit 199eef7681
3 changed files with 49 additions and 12 deletions

View File

@ -25,7 +25,7 @@
"basalt"
],
"uuid": "70ec170a-8e1b-11ea-bc55-0242ac130003",
"versionLabel": "0.1",
"versionLabel": "0.2",
"watchapp": {
"watchface": false
}

View File

@ -3,11 +3,17 @@
#include "calc.h"
static inline int8_t tokenCount() {
if(!using_func_tokens)
return sizeof(tokens) / sizeof(tokens[0]);
return sizeof(func_tokens) / sizeof(func_tokens[0]);
}
static inline char* getToken(int8_t n) {
if(!using_func_tokens)
return tokens[n % tokenCount()];
return func_tokens[n % tokenCount()];
}
// Currently selected button, starts on '('
@ -48,15 +54,25 @@ static void up_down_handler(ClickRecognizerRef recognizer, void *context){
updateText();
}
// Backspace if possible, otherwise close the app
static void back_handler(ClickRecognizerRef recognizer, void *context) {
if(mytext[0] == '\0') {
window_stack_remove(window_stack_get_top_window(), true);
} else {
static void backspace()
{
int8_t i = 0;
while(mytext[++i] != '\0') { ; }
mytext[i-1] = '\0';
updateText();
}
// Backspace if possible, otherwise close the app
static void back_handler(ClickRecognizerRef recognizer, void *context) {
if(!using_func_tokens) {
if(mytext[0] == '\0') {
window_stack_remove(window_stack_get_top_window(), true);
} else {
backspace();
}
} else {
using_func_tokens = 0;
updateText();
}
}
@ -74,19 +90,29 @@ static void calculate(){
stringObj(temp, &obj);
snprintf(resulttext, RESULT_LENGTH, "R:%s", temp);
selected_token = 0;
text_layer_set_text(s_result_text_layer, resulttext);
}
// Button press handler
static void select_handler(ClickRecognizerRef recognizer, void *context){
if(selected_token == sizeof(tokens) / sizeof(tokens[0]) - 1)
if(!using_func_tokens && selected_token == tokenCount() - 1) {
calculate();
else
} else if(!using_func_tokens && selected_token == tokenCount() - 2) {
using_func_tokens = 1;
selected_token = 0;
updateText();
} else {
enter();
}
}
static void long_select_handler(ClickRecognizerRef recognizer, void *context){
int8_t i = 0;
while(temptext[++i] != '\0') { ; }
for(unsigned j = 0; j < strlen(getToken(selected_token)); j++) {
temptext[i-(1 + j)] = '\0';
}
persist_write_string(current_code, temptext);
window_stack_pop(true);
}
@ -240,6 +266,7 @@ void custom_unload(Window *window)
Object add_window(Object obj1, Object obj2, struct Environment *env)
{
printf("ADD_WINDOW\n");
if(obj1.type == TYPE_STRING) {
strcpy(header, obj1.string);
}
@ -261,6 +288,7 @@ static struct Environment pebbleEnv() {
struct Environment e = defaultEnv();
// Needs two args
addFunc("window", &add_window, &e);
parseEval("(def w (fn (a) (window a 1)))", &e);
return e;
}

View File

@ -48,12 +48,21 @@ char *tokens[] = {
"7","8","9", "0",
"a", "b", "c", "d", "e",
"= ", "< ", "> ",
"spent ", "window",
"\"",
"cat", "map", "fn", "def", "if", "\n",
"...",
END_PHRASE
};
char *func_tokens[] = {
"spent ", "window ",
"max ", "min ",
"sq ", "cube ", "exp "
};
int using_func_tokens = 0;
void code_window_load(Window *window);
void code_window_unload(Window *window);