Merge branch 'main' of github.com:joeycastillo/second-movement
This commit is contained in:
4
.github/workflows/build.yml
vendored
4
.github/workflows/build.yml
vendored
@@ -41,9 +41,9 @@ jobs:
|
|||||||
run: emmake make
|
run: emmake make
|
||||||
working-directory: '.'
|
working-directory: '.'
|
||||||
- name: Archive simulator build
|
- name: Archive simulator build
|
||||||
working-directory: 'movement/make/build-sim'
|
working-directory: './build-sim'
|
||||||
run: |
|
run: |
|
||||||
tar -czf movement.tar.gz index.html firmware.wasm firmware.js
|
tar -czf movement.tar.gz firmware.html firmware.wasm firmware.js
|
||||||
- name: Upload simulator build
|
- name: Upload simulator build
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
|
|||||||
4
.gitmodules
vendored
4
.gitmodules
vendored
@@ -6,7 +6,7 @@
|
|||||||
url = https://github.com/littlefs-project/littlefs.git
|
url = https://github.com/littlefs-project/littlefs.git
|
||||||
[submodule "gossamer"]
|
[submodule "gossamer"]
|
||||||
path = gossamer
|
path = gossamer
|
||||||
url = git@github.com:joeycastillo/gossamer.git
|
url = https://github.com/joeycastillo/gossamer.git
|
||||||
[submodule "utz"]
|
[submodule "utz"]
|
||||||
path = utz
|
path = utz
|
||||||
url = git@github.com:joeycastillo/utz.git
|
url = https://github.com/joeycastillo/utz.git
|
||||||
|
|||||||
@@ -64,13 +64,11 @@ static void _day_one_face_increment(day_one_state_t *state) {
|
|||||||
state->birth_month = (state->birth_month % 12) + 1;
|
state->birth_month = (state->birth_month % 12) + 1;
|
||||||
break;
|
break;
|
||||||
case PAGE_DAY:
|
case PAGE_DAY:
|
||||||
state->birth_day = state->birth_day + 1;
|
state->birth_day = (state->birth_day % watch_utility_days_in_month(state->birth_month, state->birth_year)) + 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (state->birth_day == 0 || state->birth_day > days_in_month(state->birth_month, state->birth_year))
|
|
||||||
state->birth_day = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void day_one_face_setup(uint8_t watch_face_index, void ** context_ptr) {
|
void day_one_face_setup(uint8_t watch_face_index, void ** context_ptr) {
|
||||||
|
|||||||
@@ -269,15 +269,7 @@ static void _increment_date(deadline_state_t *state, watch_date_time_t date_time
|
|||||||
date_time.unit.month = (date_time.unit.month % 12) + 1;
|
date_time.unit.month = (date_time.unit.month % 12) + 1;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
date_time.unit.day = date_time.unit.day + 1;
|
date_time.unit.day = (date_time.unit.day % watch_utility_days_in_month(date_time.unit.month, date_time.unit.year + WATCH_RTC_REFERENCE_YEAR)) + 1;
|
||||||
|
|
||||||
/* Check for leap years */
|
|
||||||
int8_t days = days_in_month[date_time.unit.month - 1];
|
|
||||||
if (date_time.unit.month == 2 && _is_leap(date_time.unit.year))
|
|
||||||
days++;
|
|
||||||
|
|
||||||
if (date_time.unit.day > days)
|
|
||||||
date_time.unit.day = 1;
|
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
date_time.unit.hour = (date_time.unit.hour + 1) % 24;
|
date_time.unit.hour = (date_time.unit.hour + 1) % 24;
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ static void _handle_alarm_button(time_left_state_t *state) {
|
|||||||
state->birth_date.bit.month = (state->birth_date.bit.month % 12) + 1;
|
state->birth_date.bit.month = (state->birth_date.bit.month % 12) + 1;
|
||||||
break;
|
break;
|
||||||
case TIME_LEFT_FACE_SETTINGS_STATE + 2: // birth day
|
case TIME_LEFT_FACE_SETTINGS_STATE + 2: // birth day
|
||||||
state->birth_date.bit.day++;
|
state->birth_date.bit.day = (state->birth_date.bit.day % watch_utility_days_in_month(state->birth_date.bit.month, state->birth_date.bit.year)) + 1;
|
||||||
break;
|
break;
|
||||||
case TIME_LEFT_FACE_SETTINGS_STATE + 3: // target year
|
case TIME_LEFT_FACE_SETTINGS_STATE + 3: // target year
|
||||||
state->target_date.bit.year++;
|
state->target_date.bit.year++;
|
||||||
@@ -178,13 +178,9 @@ static void _handle_alarm_button(time_left_state_t *state) {
|
|||||||
state->target_date.bit.month = (state->target_date.bit.month % 12) + 1;
|
state->target_date.bit.month = (state->target_date.bit.month % 12) + 1;
|
||||||
break;
|
break;
|
||||||
case TIME_LEFT_FACE_SETTINGS_STATE + 5: // target day
|
case TIME_LEFT_FACE_SETTINGS_STATE + 5: // target day
|
||||||
state->target_date.bit.day++;
|
state->target_date.bit.day = (state->target_date.bit.day % watch_utility_days_in_month(state->target_date.bit.month, state->birth_date.bit.year)) + 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (state->birth_date.bit.day > days_in_month(state->birth_date.bit.month, state->birth_date.bit.year))
|
|
||||||
state->birth_date.bit.day = 1;
|
|
||||||
if (state->target_date.bit.day > days_in_month(state->target_date.bit.month, state->birth_date.bit.year))
|
|
||||||
state->target_date.bit.day = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _initiate_setting(time_left_state_t *state) {
|
static void _initiate_setting(time_left_state_t *state) {
|
||||||
|
|||||||
@@ -163,15 +163,13 @@ bool set_time_hackwatch_face_loop(movement_event_t event, void *context) {
|
|||||||
date_time_settings.unit.month = (date_time_settings.unit.month % 12) + 1;
|
date_time_settings.unit.month = (date_time_settings.unit.month % 12) + 1;
|
||||||
break;
|
break;
|
||||||
case 5: // day
|
case 5: // day
|
||||||
date_time_settings.unit.day = date_time_settings.unit.day + 1;
|
date_time_settings.unit.day = (date_time_settings.unit.day % watch_utility_days_in_month(date_time_settings.unit.month, date_time_settings.unit.year + WATCH_RTC_REFERENCE_YEAR)) + 1;
|
||||||
break;
|
break;
|
||||||
case 6: // time zone
|
case 6: // time zone
|
||||||
movement_set_timezone_index(movement_get_timezone_index() + 1);
|
movement_set_timezone_index(movement_get_timezone_index() + 1);
|
||||||
if (movement_get_timezone_index() >= NUM_ZONE_NAMES) movement_set_timezone_index(0);
|
if (movement_get_timezone_index() >= NUM_ZONE_NAMES) movement_set_timezone_index(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (date_time_settings.unit.day > days_in_month(date_time_settings.unit.month, date_time_settings.unit.year + WATCH_RTC_REFERENCE_YEAR))
|
|
||||||
date_time_settings.unit.day = 1;
|
|
||||||
if (current_page != 2) // Do not set time when we are at seconds, it was already set previously
|
if (current_page != 2) // Do not set time when we are at seconds, it was already set previously
|
||||||
watch_rtc_set_date_time(date_time_settings);
|
watch_rtc_set_date_time(date_time_settings);
|
||||||
//TODO: Do not update whole RTC, just what we are changing
|
//TODO: Do not update whole RTC, just what we are changing
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ static void _handle_alarm_button(watch_date_time_t date_time, uint8_t current_pa
|
|||||||
date_time.unit.month = (date_time.unit.month % 12) + 1;
|
date_time.unit.month = (date_time.unit.month % 12) + 1;
|
||||||
break;
|
break;
|
||||||
case 3: { // day
|
case 3: { // day
|
||||||
date_time.unit.day = date_time.unit.day + 1;
|
date_time.unit.day = (date_time.unit.day % watch_utility_days_in_month(date_time.unit.month, date_time.unit.year + WATCH_RTC_REFERENCE_YEAR)) + 1;
|
||||||
break;
|
break;
|
||||||
case 4: // hour
|
case 4: // hour
|
||||||
date_time.unit.hour = (date_time.unit.hour + 1) % 24;
|
date_time.unit.hour = (date_time.unit.hour + 1) % 24;
|
||||||
@@ -64,8 +64,6 @@ static void _handle_alarm_button(watch_date_time_t date_time, uint8_t current_pa
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (date_time.unit.day > days_in_month(date_time.unit.month, date_time.unit.year + WATCH_RTC_REFERENCE_YEAR))
|
|
||||||
date_time.unit.day = 1;
|
|
||||||
movement_set_local_date_time(date_time);
|
movement_set_local_date_time(date_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -320,3 +320,11 @@ uint32_t watch_utility_offset_timestamp(uint32_t now, int8_t hours, int8_t minut
|
|||||||
new += seconds;
|
new += seconds;
|
||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t watch_utility_days_in_month(uint8_t month, uint16_t year) {
|
||||||
|
static const uint8_t days_in_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||||
|
uint8_t days = days_in_month[month - 1];
|
||||||
|
if (month == 2 && is_leap(year))
|
||||||
|
days += 1;
|
||||||
|
return days;
|
||||||
|
}
|
||||||
|
|||||||
@@ -172,6 +172,6 @@ uint32_t watch_utility_offset_timestamp(uint32_t now, int8_t hours, int8_t minut
|
|||||||
* @param month The month of the date (1-12)
|
* @param month The month of the date (1-12)
|
||||||
* @param year The year of the date (ex. 2022)
|
* @param year The year of the date (ex. 2022)
|
||||||
*/
|
*/
|
||||||
uint8_t days_in_month(uint8_t month, uint16_t year);
|
uint8_t watch_utility_days_in_month(uint8_t month, uint16_t year);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -45,6 +45,12 @@ bool _watch_rtc_is_enabled(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _watch_rtc_init(void) {
|
void _watch_rtc_init(void) {
|
||||||
|
// Shifts the timezone so our local time is converted to UTC and set
|
||||||
|
int32_t time_zone_offset = EM_ASM_INT({
|
||||||
|
return -new Date().getTimezoneOffset() * 60;
|
||||||
|
});
|
||||||
|
watch_date_time_t date_time = watch_rtc_get_date_time();
|
||||||
|
watch_rtc_set_date_time(watch_utility_date_time_convert_zone(date_time, time_zone_offset, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void watch_rtc_set_date_time(watch_date_time_t date_time) {
|
void watch_rtc_set_date_time(watch_date_time_t date_time) {
|
||||||
@@ -62,9 +68,6 @@ void watch_rtc_set_date_time(watch_date_time_t date_time) {
|
|||||||
|
|
||||||
watch_date_time_t watch_rtc_get_date_time(void) {
|
watch_date_time_t watch_rtc_get_date_time(void) {
|
||||||
watch_date_time_t retval;
|
watch_date_time_t retval;
|
||||||
int32_t time_zone_offset = EM_ASM_INT({
|
|
||||||
return -new Date().getTimezoneOffset() * 60;
|
|
||||||
});
|
|
||||||
retval.reg = EM_ASM_INT({
|
retval.reg = EM_ASM_INT({
|
||||||
const date = new Date(Date.now() + $0);
|
const date = new Date(Date.now() + $0);
|
||||||
return date.getSeconds() |
|
return date.getSeconds() |
|
||||||
@@ -74,7 +77,6 @@ watch_date_time_t watch_rtc_get_date_time(void) {
|
|||||||
((date.getMonth() + 1) << 22) |
|
((date.getMonth() + 1) << 22) |
|
||||||
((date.getFullYear() - 2020) << 26);
|
((date.getFullYear() - 2020) << 26);
|
||||||
}, time_offset);
|
}, time_offset);
|
||||||
retval = watch_utility_date_time_convert_zone(retval, time_zone_offset, 0);
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user