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" "basalt"
], ],
"uuid": "70ec170a-8e1b-11ea-bc55-0242ac130003", "uuid": "70ec170a-8e1b-11ea-bc55-0242ac130003",
"versionLabel": "0.1", "versionLabel": "0.2",
"watchapp": { "watchapp": {
"watchface": false "watchface": false
} }

View File

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

View File

@ -48,12 +48,21 @@ char *tokens[] = {
"7","8","9", "0", "7","8","9", "0",
"a", "b", "c", "d", "e", "a", "b", "c", "d", "e",
"= ", "< ", "> ", "= ", "< ", "> ",
"spent ", "window",
"\"", "\"",
"cat", "map", "fn", "def", "if", "\n", "cat", "map", "fn", "def", "if", "\n",
"...",
END_PHRASE 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_load(Window *window);
void code_window_unload(Window *window); void code_window_unload(Window *window);