From 88a98da975b6ef980f966070c4867af414be310a Mon Sep 17 00:00:00 2001 From: Lionel Ringenbach Date: Fri, 28 Mar 2025 10:10:32 +0100 Subject: [PATCH] Flowtime watch face implementation --- movement/lib/flowtime/README.md | 37 +++ movement/lib/flowtime/flowtime.c | 74 +++++ movement/lib/flowtime/flowtime.h | 32 +++ movement/make/Makefile | 3 + movement/movement_faces.h | 1 + .../watch_faces/clock/flowtime_clock_face.c | 253 ++++++++++++++++++ .../watch_faces/clock/flowtime_clock_face.h | 52 ++++ 7 files changed, 452 insertions(+) create mode 100644 movement/lib/flowtime/README.md create mode 100644 movement/lib/flowtime/flowtime.c create mode 100644 movement/lib/flowtime/flowtime.h create mode 100644 movement/watch_faces/clock/flowtime_clock_face.c create mode 100644 movement/watch_faces/clock/flowtime_clock_face.h diff --git a/movement/lib/flowtime/README.md b/movement/lib/flowtime/README.md new file mode 100644 index 000000000..97797efde --- /dev/null +++ b/movement/lib/flowtime/README.md @@ -0,0 +1,37 @@ +# flowtime for sensor-watch + +## What is flowtime? + +flowtime is an art project and thought experiment that challenges and reimagines our traditional understanding of time. It explores the relationship between our perception of time and our ability to enter [flow states](1), periods of deep focus and engagement with the present moment. In essence, flowtime is a manifestation of timelessness. + +The concept emerged from a simple observation: whenever I became aware of time, whether by mechanically looking at my watch or involuntarily catching a glimpse of a screen, I momentarily and unconsciously time travel and lose touch with the present. This sparked a question: what if there were a way to decide consciously whether to know the time or remain immersed in the flow? This was the birth of flowtime. + +Although it preserves the familiar structure of 24 hours per day 60 minutes per hour, the order of its hours and minutes is unpredictable and unique each day. Yet it remains universal, meaning the flowtime is the same for everyone, just like conventional time. This uncertainty encourages us to loosen our attachment to time, creating an opportunity to return into the flow of the present moment. + +What started as a conceptual exploration has since materialized into a tangible, interactive technology that melds philosophical inquiry with practical application. It is now available in the form of a JavaScript library, a command line tool, a classic Casio watch, and on the [flowtime project website](7). + +Concept and development by [Lionel Ringenbach (a.k.a. Ucodia)](6), started in September 2017. + +## How does it work? + +To compute the flowtime, the current date and time is used as input. The day and hour periods are derived by concatenating their numerical values. For example, `July 21 2018 09:28:42` has identifiers `20180721` for the day period and `2018072109` for the hour period. These identifiers then seed a [pseudorandom number generator (PRNG)](2) to produce a deterministic sequence of hours and minutes. This method ensures universality while remaining unpredictable to human beings. + +The [xorshift32 algorithm](3) generates the random numbers, and the [Fisher-Yates algorithm](4) shuffles them, resulting in deterministically random sequences. + +## Useful references + +- [Flow state](1) on Wikipedia +- [Pseudorandom number generator](2) on Wikipedia +- [Xorshift](3) on Wikipedia +- [Fisher-Yates shuffle](4) on Wikipedia +- [Sensor Watch](5) official website +- [Lionel Ringenbach (a.k.a. Ucodia)](6) official website +- [flowtime](7) project official website + +[1]: https://en.wikipedia.org/wiki/Flow_(psychology) +[2]: https://en.wikipedia.org/wiki/Pseudorandom_number_generator +[3]: https://en.wikipedia.org/wiki/Xorshift +[4]: https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle +[5]: https://www.sensorwatch.net/ +[6]: https://ucodia.space +[7]: https://ucodia.space/flowtime \ No newline at end of file diff --git a/movement/lib/flowtime/flowtime.c b/movement/lib/flowtime/flowtime.c new file mode 100644 index 000000000..791605ff6 --- /dev/null +++ b/movement/lib/flowtime/flowtime.c @@ -0,0 +1,74 @@ +/* + * MIT License + * + * Copyright © 2023-2025 Lionel Ringenbach + * + * 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. + */ + +#include "flowtime.h" +#include "watch.h" +#include +#include + +static uint32_t *random_sequence(uint32_t n, uint32_t seed) { + uint32_t *result = malloc(n * sizeof(uint32_t)); + if (!result) + return NULL; + uint32_t state = seed; + for (uint32_t i = 0; i < n; i++) { + state ^= state << 13; + state ^= state >> 17; + state ^= state << 5; + int j = (uint32_t)(((double)state / 4294967296) * (i + 1)); + result[i] = result[j]; + result[j] = i; + } + return result; +} + +watch_date_time date_to_flowtime(watch_date_time *date) { + static uint32_t cached_hours_seed = 0; + static uint32_t cached_minutes_seed = 0; + static uint32_t *cached_hours_sequence = NULL; + static uint32_t *cached_minutes_sequence = NULL; + + uint32_t hoursSeed = (date->unit.year + WATCH_RTC_REFERENCE_YEAR) * 10000 + + date->unit.month * 100 + + date->unit.day; + uint32_t minutesSeed = hoursSeed * 100 + date->unit.hour; + + if (hoursSeed != cached_hours_seed) { + free(cached_hours_sequence); + cached_hours_sequence = random_sequence(24, hoursSeed); + cached_hours_seed = hoursSeed; + } + + if (minutesSeed != cached_minutes_seed) { + free(cached_minutes_sequence); + cached_minutes_sequence = random_sequence(60, minutesSeed); + cached_minutes_seed = minutesSeed; + } + + watch_date_time flowtime = *date; + flowtime.unit.hour = cached_hours_sequence[date->unit.hour]; + flowtime.unit.minute = cached_minutes_sequence[date->unit.minute]; + + return flowtime; +} diff --git a/movement/lib/flowtime/flowtime.h b/movement/lib/flowtime/flowtime.h new file mode 100644 index 000000000..1cd801453 --- /dev/null +++ b/movement/lib/flowtime/flowtime.h @@ -0,0 +1,32 @@ +/* + * MIT License + * + * Copyright © 2023-2025 Lionel Ringenbach + * + * 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 __FLOWTIME_H_ +#define __FLOWTIME_H_ + +#include "watch.h" + +watch_date_time date_to_flowtime(watch_date_time *date); + +#endif // __FLOWTIME_H_ diff --git a/movement/make/Makefile b/movement/make/Makefile index 2116ebaba..a69b0dd6c 100644 --- a/movement/make/Makefile +++ b/movement/make/Makefile @@ -25,6 +25,7 @@ INCLUDES += \ -I../lib/astrolib/ \ -I../lib/morsecalc/ \ -I../lib/smallchesslib/ \ + -I../lib/flowtime/ \ # If you add any other source files you wish to compile, add them after ../app.c # Note that you will need to add a backslash at the end of any line you wish to continue, i.e. @@ -46,6 +47,7 @@ SRCS += \ ../lib/morsecalc/calc_fns.c \ ../lib/morsecalc/calc_strtof.c \ ../lib/morsecalc/morsecalc_display.c \ + ../lib/flowtime/flowtime.c \ ../../littlefs/lfs.c \ ../../littlefs/lfs_util.c \ ../movement.c \ @@ -149,6 +151,7 @@ SRCS += \ ../watch_faces/sensor/accel_interrupt_count_face.c \ ../watch_faces/complication/metronome_face.c \ ../watch_faces/complication/smallchess_face.c \ + ../watch_faces/clock/flowtime_clock_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. diff --git a/movement/movement_faces.h b/movement/movement_faces.h index 630f264aa..a555a3dca 100644 --- a/movement/movement_faces.h +++ b/movement/movement_faces.h @@ -123,6 +123,7 @@ #include "accel_interrupt_count_face.h" #include "metronome_face.h" #include "smallchess_face.h" +#include "flowtime_clock_face.h" // New includes go above this line. #endif // MOVEMENT_FACES_H_ diff --git a/movement/watch_faces/clock/flowtime_clock_face.c b/movement/watch_faces/clock/flowtime_clock_face.c new file mode 100644 index 000000000..2bece2fb2 --- /dev/null +++ b/movement/watch_faces/clock/flowtime_clock_face.c @@ -0,0 +1,253 @@ +/* + * MIT License + * + * Copyright © 2023-2025 Lionel Ringenbach + * Copyright © 2021-2023 Joey Castillo + * Copyright © 2022 David Keck + * Copyright © 2022 TheOnePerson + * Copyright © 2023 Jeremy O'Brien + * Copyright © 2023 Mikhail Svarichevsky <3@14.by> + * Copyright © 2023 Wesley Aptekar-Cassels + * Copyright © 2024 Matheus Afonso Martins Moreira + * + * 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. + */ + +#include +#include "flowtime_clock_face.h" +#include "watch.h" +#include "watch_utility.h" +#include "watch_private_display.h" +#include "flowtime.h" + +typedef struct { + struct { + watch_date_time previous; + } date_time; + uint8_t watch_face_index; + bool reality_check_enabled; +} clock_state_t; + +static bool clock_is_in_24h_mode(movement_settings_t *settings) { +#ifdef CLOCK_FACE_24H_ONLY + return true; +#else + return settings->bit.clock_mode_24h; +#endif +} + +static bool clock_should_set_leading_zero(movement_settings_t *settings) { + return clock_is_in_24h_mode(settings) && settings->bit.clock_24h_leading_zero; +} + +static void clock_indicate(WatchIndicatorSegment indicator, bool on) { + if (on) { + watch_set_indicator(indicator); + } else { + watch_clear_indicator(indicator); + } +} + +static void clock_indicate_alarm(movement_settings_t *settings) { + clock_indicate(WATCH_INDICATOR_SIGNAL, settings->bit.alarm_enabled); +} + +static void clock_indicate_24h(movement_settings_t *settings) { + clock_indicate(WATCH_INDICATOR_24H, clock_is_in_24h_mode(settings)); +} + +static bool clock_is_pm(watch_date_time date_time) { + return date_time.unit.hour >= 12; +} + +static void clock_indicate_pm(movement_settings_t *settings, watch_date_time date_time) { + if (settings->bit.clock_mode_24h) { return; } + clock_indicate(WATCH_INDICATOR_PM, clock_is_pm(date_time)); +} + +static watch_date_time clock_24h_to_12h(watch_date_time date_time) { + date_time.unit.hour %= 12; + + if (date_time.unit.hour == 0) { + date_time.unit.hour = 12; + } + + return date_time; +} + +static void clock_display_all(watch_date_time date_time, bool leading_zero) { + char buf[10 + 1]; + + snprintf( + buf, + sizeof(buf), + leading_zero? "%s%02d%02d%02d%02d" : "%s%2d%2d%02d%02d", + watch_utility_get_weekday(date_time), + date_time.unit.day, + date_time.unit.hour, + date_time.unit.minute, + date_time.unit.second + ); + + watch_display_string(buf, 0); +} + +static bool clock_display_some(watch_date_time current, watch_date_time previous) { + if ((current.reg >> 6) == (previous.reg >> 6)) { + // everything before seconds is the same, don't waste cycles setting those segments. + + watch_display_character_lp_seconds('0' + current.unit.second / 10, 8); + watch_display_character_lp_seconds('0' + current.unit.second % 10, 9); + + return true; + + } else if ((current.reg >> 12) == (previous.reg >> 12)) { + // everything before minutes is the same. + + char buf[4 + 1]; + + snprintf( + buf, + sizeof(buf), + "%02d%02d", + current.unit.minute, + current.unit.second + ); + + watch_display_string(buf, 6); + + return true; + + } else { + // other stuff changed; let's do it all. + return false; + } +} + +static void clock_display_clock(movement_settings_t *settings, clock_state_t *clock, watch_date_time current) { + if (!clock_display_some(current, clock->date_time.previous)) { + if (!clock_is_in_24h_mode(settings)) { + // if we are in 12 hour mode, do some cleanup. + clock_indicate_pm(settings, current); + current = clock_24h_to_12h(current); + } + clock_display_all(current, clock_should_set_leading_zero(settings)); + } +} + +static void clock_display_low_energy(watch_date_time date_time) { + char buf[10 + 1]; + + snprintf( + buf, + sizeof(buf), + "%s%2d%2d%02d ", + watch_utility_get_weekday(date_time), + date_time.unit.day, + date_time.unit.hour, + date_time.unit.minute + ); + + watch_display_string(buf, 0); +} + +static void clock_start_tick_tock_animation(void) { + if (!watch_tick_animation_is_running()) { + watch_start_tick_animation(500); + } +} + +static void clock_stop_tick_tock_animation(void) { + if (watch_tick_animation_is_running()) { + watch_stop_tick_animation(); + } +} + +void flowtime_clock_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(clock_state_t)); + clock_state_t *state = (clock_state_t *) *context_ptr; + state->reality_check_enabled = false; + state->watch_face_index = watch_face_index; + } +} + +void flowtime_clock_face_activate(movement_settings_t *settings, void *context) { + clock_state_t *clock = (clock_state_t *) context; + + clock_stop_tick_tock_animation(); + + clock_indicate_alarm(settings); + clock_indicate_24h(settings); + + watch_set_colon(); + + // this ensures that none of the timestamp fields will match, so we can re-render them all. + clock->date_time.previous.reg = 0xFFFFFFFF; +} + +bool flowtime_clock_face_loop(movement_event_t event, movement_settings_t *settings, void *context) { + clock_state_t *state = (clock_state_t *) context; + watch_date_time current; + watch_date_time display; + + switch (event.event_type) { + case EVENT_LOW_ENERGY_UPDATE: + clock_start_tick_tock_animation(); + current = watch_rtc_get_date_time(); + display = date_to_flowtime(¤t); + clock_display_low_energy(display); + break; + case EVENT_TICK: + case EVENT_ACTIVATE: + current = watch_rtc_get_date_time(); + display = state->reality_check_enabled ? current : date_to_flowtime(¤t); + clock_display_clock(settings, state, display); + state->date_time.previous = display; + break; + case EVENT_ALARM_BUTTON_DOWN: + state->reality_check_enabled = true; + watch_set_led_red(); + current = watch_rtc_get_date_time(); + clock_display_clock(settings, state, current); + state->date_time.previous = current; + break; + case EVENT_ALARM_LONG_UP: + case EVENT_ALARM_BUTTON_UP: + state->reality_check_enabled = false; + watch_set_led_off(); + current = watch_rtc_get_date_time(); + display = date_to_flowtime(¤t); + clock_display_clock(settings, state, display); + state->date_time.previous = display; + break; + default: + return movement_default_loop_handler(event, settings); + } + + return true; +} + +void flowtime_clock_face_resign(movement_settings_t *settings, void *context) { + (void) settings; + (void) context; +} diff --git a/movement/watch_faces/clock/flowtime_clock_face.h b/movement/watch_faces/clock/flowtime_clock_face.h new file mode 100644 index 000000000..29bb3eccc --- /dev/null +++ b/movement/watch_faces/clock/flowtime_clock_face.h @@ -0,0 +1,52 @@ +/* + * MIT License + * + * Copyright © 2023-2025 Lionel Ringenbach + * + * 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 FLOWTIME_CLOCK_FACE_H_ +#define FLOWTIME_CLOCK_FACE_H_ + +/* + * FLOWTIME CLOCK FACE + * + * Displays the current flowtime. + * + * Holding ALARM button will show the real time. + * + */ + +#include "movement.h" + +void flowtime_clock_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr); +void flowtime_clock_face_activate(movement_settings_t *settings, void *context); +bool flowtime_clock_face_loop(movement_event_t event, movement_settings_t *settings, void *context); +void flowtime_clock_face_resign(movement_settings_t *settings, void *context); + +#define flowtime_clock_face ((const watch_face_t) { \ + flowtime_clock_face_setup, \ + flowtime_clock_face_activate, \ + flowtime_clock_face_loop, \ + flowtime_clock_face_resign, \ + NULL, \ +}) + +#endif // FLOWTIME_CLOCK_FACE_H_