mirror of
https://github.com/firewalkwithm3/Sensor-Watch.git
synced 2024-11-22 19:20:30 +08:00
Add simple_coin_flip_face.
This commit is contained in:
parent
67be6affd3
commit
73f689e65a
|
@ -118,6 +118,7 @@ SRCS += \
|
|||
../watch_faces/complication/flashlight_face.c \
|
||||
../watch_faces/clock/decimal_time_face.c \
|
||||
../watch_faces/clock/wyoscan_face.c \
|
||||
../watch_faces/complication/simple_coin_flip_face.c \
|
||||
# New watch faces go above this line.
|
||||
|
||||
# Leave this line at the bottom of the file; it has all the targets for making your project.
|
||||
|
|
|
@ -95,6 +95,7 @@
|
|||
#include "flashlight_face.h"
|
||||
#include "decimal_time_face.h"
|
||||
#include "wyoscan_face.h"
|
||||
#include "simple_coin_flip_face.h"
|
||||
// New includes go above this line.
|
||||
|
||||
#endif // MOVEMENT_FACES_H_
|
||||
|
|
139
movement/watch_faces/complication/simple_coin_flip_face.c
Normal file
139
movement/watch_faces/complication/simple_coin_flip_face.c
Normal file
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Wesley Aptekar-Cassels
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#if __EMSCRIPTEN__
|
||||
#include <time.h>
|
||||
#else
|
||||
#include "saml22j18a.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "simple_coin_flip_face.h"
|
||||
|
||||
#define SIMPLE_COIN_FLIP_REQUIRE_LONG_PRESS_FOR_REFLIP true
|
||||
|
||||
void simple_coin_flip_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
|
||||
(void) settings;
|
||||
(void) watch_face_index;
|
||||
if (*context_ptr == NULL) {
|
||||
*context_ptr = malloc(sizeof(simple_coin_flip_state_t));
|
||||
memset(*context_ptr, 0, sizeof(simple_coin_flip_state_t));
|
||||
}
|
||||
}
|
||||
|
||||
void simple_coin_flip_face_activate(movement_settings_t *settings, void *context) {
|
||||
(void) settings;
|
||||
(void) context;
|
||||
}
|
||||
|
||||
static uint32_t get_random(uint32_t max) {
|
||||
#if __EMSCRIPTEN__
|
||||
return rand() % max;
|
||||
#else
|
||||
return arc4random_uniform(max);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void animation_0() {
|
||||
watch_display_string(" ", 8);
|
||||
watch_set_pixel(0, 3);
|
||||
watch_set_pixel(0, 6);
|
||||
}
|
||||
|
||||
static void animation_1() {
|
||||
watch_display_string(" ", 8);
|
||||
watch_set_pixel(1, 3);
|
||||
watch_set_pixel(1, 5);
|
||||
}
|
||||
|
||||
static void animation_2() {
|
||||
watch_display_string(" ", 8);
|
||||
watch_set_pixel(2, 2);
|
||||
watch_set_pixel(2, 4);
|
||||
}
|
||||
|
||||
bool simple_coin_flip_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
|
||||
simple_coin_flip_state_t *state = (simple_coin_flip_state_t *)context;
|
||||
|
||||
switch (event.event_type) {
|
||||
case EVENT_ACTIVATE:
|
||||
watch_display_string("flip", 5);
|
||||
state->animation_frame = 0;
|
||||
break;
|
||||
case EVENT_TICK:
|
||||
switch (state->animation_frame) {
|
||||
case 0:
|
||||
case 7:
|
||||
return true;
|
||||
case 1:
|
||||
movement_request_tick_frequency(8);
|
||||
watch_display_string(" ", 4);
|
||||
// fallthrough
|
||||
case 5:
|
||||
animation_0();
|
||||
break;
|
||||
case 2:
|
||||
case 4:
|
||||
animation_1();
|
||||
break;
|
||||
case 3:
|
||||
animation_2();
|
||||
break;
|
||||
case 6:
|
||||
movement_request_tick_frequency(1);
|
||||
if (get_random(2)) {
|
||||
watch_display_string("Heads ", 4);
|
||||
} else {
|
||||
watch_display_string(" Tails", 4);
|
||||
}
|
||||
break;
|
||||
}
|
||||
state->animation_frame++;
|
||||
break;
|
||||
case EVENT_LIGHT_BUTTON_UP:
|
||||
case EVENT_ALARM_BUTTON_UP:
|
||||
if (!SIMPLE_COIN_FLIP_REQUIRE_LONG_PRESS_FOR_REFLIP || state->animation_frame == 0) {
|
||||
state->animation_frame = 1;
|
||||
}
|
||||
break;
|
||||
case EVENT_ALARM_LONG_PRESS:
|
||||
case EVENT_LIGHT_LONG_PRESS:
|
||||
state->animation_frame = 1;
|
||||
break;
|
||||
case EVENT_TIMEOUT:
|
||||
movement_move_to_face(0);
|
||||
break;
|
||||
default:
|
||||
return movement_default_loop_handler(event, settings);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void simple_coin_flip_face_resign(movement_settings_t *settings, void *context) {
|
||||
(void) settings;
|
||||
(void) context;
|
||||
}
|
||||
|
62
movement/watch_faces/complication/simple_coin_flip_face.h
Normal file
62
movement/watch_faces/complication/simple_coin_flip_face.h
Normal file
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2023 Wesley Aptekar-Cassels
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef SIMPLE_COIN_FLIP_FACE_H_
|
||||
#define SIMPLE_COIN_FLIP_FACE_H_
|
||||
|
||||
#include "movement.h"
|
||||
|
||||
/*
|
||||
* A extremely simple coin flip face.
|
||||
*
|
||||
* Press ALARM or LIGHT to flip a coin, after a short animation it will display
|
||||
* "Heads" or "Tails". Long-press to flip again (you can change a #define to
|
||||
* allow a short-press to reflip as well, if you'd like).
|
||||
*
|
||||
* This is for people who want a simpler UI than probability_face or
|
||||
* randonaut_face. While those have more features, this one is more immediately
|
||||
* obvious - useful, for instance, if you are using a coin flip to agree on
|
||||
* something with someone, and want the operation to be clear to someone who
|
||||
* has not had anything explained to them.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
uint8_t animation_frame;
|
||||
} simple_coin_flip_state_t;
|
||||
|
||||
void simple_coin_flip_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
|
||||
void simple_coin_flip_face_activate(movement_settings_t *settings, void *context);
|
||||
bool simple_coin_flip_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
|
||||
void simple_coin_flip_face_resign(movement_settings_t *settings, void *context);
|
||||
|
||||
#define simple_coin_flip_face ((const watch_face_t){ \
|
||||
simple_coin_flip_face_setup, \
|
||||
simple_coin_flip_face_activate, \
|
||||
simple_coin_flip_face_loop, \
|
||||
simple_coin_flip_face_resign, \
|
||||
NULL, \
|
||||
})
|
||||
|
||||
#endif // SIMPLE_COIN_FLIP_FACE_H_
|
||||
|
Loading…
Reference in a new issue