summaryrefslogtreecommitdiffstats
path: root/movement/watch_faces/demos/character_set_face.c
blob: eabb133f0ba1a6ce4a7004592ca3a598b8c68cc9 (plain)
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
#include <stdlib.h>
#include <string.h>
#include "character_set_face.h"
#include "watch.h"

void character_set_face_setup(movement_settings_t *settings, void ** context_ptr) {
    (void) settings;
    if (*context_ptr == NULL) *context_ptr = malloc(sizeof(char));
}

void character_set_face_activate(movement_settings_t *settings, void *context) {
    (void) settings;
    char *c = (char *)context;
    *c = '@';
    movement_request_tick_frequency(0);
}

bool character_set_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
    (void) settings;
    char *c = (char *)context;
    char buf[11];
    switch (event.event_type) {
        case EVENT_MODE_BUTTON_UP:
            movement_move_to_next_face();
            break;
        case EVENT_LIGHT_BUTTON_DOWN:
            movement_illuminate_led();
            break;
        case EVENT_ALARM_BUTTON_UP:
            *c = (*c) + 1;
            if (*c & 0x80) *c = ' ';
            // fall through
        case EVENT_ACTIVATE:
            sprintf(buf, "%c%c%c%c%c%c%c%c%c%c", *c, *c, *c, *c, *c, *c, *c, *c, *c, *c);
            watch_display_string(buf, 0);
            break;
        case EVENT_TIMEOUT:
            movement_move_to_face(0);
            break;
        default:
            break;
    }

    return true;
}

void character_set_face_resign(movement_settings_t *settings, void *context) {
    (void) settings;
    (void) context;
    movement_request_tick_frequency(1);
}