13 Commits

Author SHA1 Message Date
hueso
fe5898e7ee Merge branch 'legacy_moonrise' into legacy
Some checks failed
Build / build (push) Has been cancelled
Build / build-simulator (push) Has been cancelled
2025-12-16 12:12:23 -03:00
hueso
5a3a99bb36 Merge branch 'legacy_español' into legacy 2025-12-16 12:12:15 -03:00
hueso
b98a2a0870 Moonrise face
Some checks failed
Build / build (push) Has been cancelled
Build / build-simulator (push) Has been cancelled
2025-12-16 12:09:15 -03:00
hueso
aeeb62eefd fix LED turning off on face changes
Some checks failed
Build / build (push) Has been cancelled
Build / build-simulator (push) Has been cancelled
2025-12-16 12:03:27 -03:00
hueso
f1e78b5b4b spanish translations
Some checks failed
Build / build (push) Has been cancelled
Build / build-simulator (push) Has been cancelled
2025-12-16 11:13:42 -03:00
hueso
0b58ac750e close_enough_face: swap bell/alarm to match stock firmware 2025-06-16 22:04:26 -03:00
hueso
45583b3120 ignore indicators for short beep alarms 2025-06-16 22:01:35 -03:00
hueso
8abf6f4f5b Fixed buffer overflows in sunrise_sunset_face
Some checks failed
Build / build (push) Has been cancelled
Build / build-simulator (push) Has been cancelled
GitHub Pages / gh-pages (push) Has been cancelled
2025-05-15 11:59:21 -03:00
Joey Castillo
8c39d42824 Merge branch 'main' of github.com:joeycastillo/Sensor-Watch
Some checks failed
Build / build (push) Has been cancelled
Build / build-simulator (push) Has been cancelled
2025-05-06 23:57:45 -04:00
Joey Castillo
56f2c93783 sensor watch pro test procedure 2025-05-06 23:56:19 -04:00
Wesley Ellis
14e64caac9 Merge pull request #512 from tahnok/schematic-readme
Add schematic info to README
2025-04-03 08:58:30 -04:00
Wesley Ellis
cc6a0c363e Add links to schematics and gerbers for different models 2025-04-01 09:55:41 -04:00
Wesley Ellis
845caa30fb Add link to schematics and gerbers to README 2025-04-01 09:55:41 -04:00
16 changed files with 678 additions and 237 deletions

View File

@@ -74,6 +74,17 @@ python3 -m http.server -d build-sim
Finally, visit [watch.html](http://localhost:8000/watch.html) to see your work. Finally, visit [watch.html](http://localhost:8000/watch.html) to see your work.
Hardware Schematics and PCBs
----------------------------
| Name | Color | Schematic | Gerbers |
| ---- | ----- | --------- | ------- |
| Sensorwatch Lite | RED | [PCB/Main Boards/OSO-SWAT-B1](PCB/Main%20Boards/OSO-SWAT-B1) | [OSO-SWAT-B1-03](PCB/Main%20Boards/OSO-SWAT-B1/OSO-SWAT-B1-03.zip) |
| Sensorwatch | GREEN | [OSO-SWAT-A1-05](PCB/Main%20Boards/OSO-SWAT-A1/OSO-SWAT-A1-05.sch) (Eagle format) | ? |
| Sensorwatch Pro | TBD | TBD | TBD |
License License
------- -------
Different components of the project are licensed differently, see [LICENSE.md](https://github.com/joeycastillo/Sensor-Watch/blob/main/LICENSE.md). Different components of the project are licensed differently, see [LICENSE.md](https://github.com/joeycastillo/Sensor-Watch/blob/main/LICENSE.md).

View File

@@ -0,0 +1,420 @@
#include <stdio.h>
#include <string.h>
#include "watch.h"
#include "spiflash.h"
bool has_ticked = false;
extern struct io_descriptor *uart_io;
// array of lcd pins from pins.h
const uint8_t lcd_pins[] = {
SLCD26, // SEG23
SLCD25, // SEG22
SLCD24, // SEG21
SLCD23, // SEG20
SLCD22, // SEG19
SLCD21, // SEG18
SLCD20, // SEG17
SLCD19, // SEG16
SLCD18, // SEG15
SLCD17, // SEG14
SLCD16, // SEG13
SLCD15, // SEG12
SLCD14, // SEG11
SLCD13, // SEG10
SLCD12, // SEG9
SLCD11, // SEG8
SLCD10, // SEG7
SLCD9, // SEG6
SLCD8, // SEG5
SLCD7, // SEG4
SLCD6, // SEG3
SLCD5, // SEG2
SLCD4, // SEG1
SLCD3, // SEG0
SLCD2, // COM2
SLCD1, // COM1
SLCD0, // COM0
};
void cb_tick(void);
void cb_tick(void) {
has_ticked = true;
watch_rtc_disable_periodic_callback(8);
}
void pass_if(bool passed);
void pass_if(bool passed) {
if (passed) {
watch_set_led_green();
delay_ms(100);
watch_set_led_off();
} else {
watch_set_led_red();
delay_ms(100);
watch_set_led_off();
}
}
void app_init(void) {
}
void app_wake_from_backup(void) {
}
static void enable_irda_uart() {
gpio_set_pin_direction(IR_ENABLE, GPIO_DIRECTION_OUT);
gpio_set_pin_level(IR_ENABLE, false);
SERCOM_USART_CTRLA_Type ctrla;
SERCOM_USART_CTRLB_Type ctrlb;
ctrla.reg = SERCOM_USART_CTRLA_DORD | SERCOM_USART_CTRLA_MODE(1);
ctrlb.reg = SERCOM_USART_CTRLB_CHSIZE(0) | SERCOM_USART_CTRLB_ENC;
MCLK->APBCMASK.reg |= MCLK_APBCMASK_SERCOM0;
GCLK->PCHCTRL[SERCOM0_GCLK_ID_CORE].reg = GCLK_PCHCTRL_GEN(0) | GCLK_PCHCTRL_CHEN;
while (0 == (GCLK->PCHCTRL[SERCOM0_GCLK_ID_CORE].reg & GCLK_PCHCTRL_CHEN));
usart_sync_init(&USART_0, SERCOM0, (void *)NULL);
SERCOM0->USART.CTRLA.reg &= ~SERCOM_USART_CTRLA_ENABLE;
gpio_set_pin_direction(IRSENSE, GPIO_DIRECTION_IN);
gpio_set_pin_function(IRSENSE, PINMUX_PA04D_SERCOM0_PAD0);
ctrla.reg |= SERCOM_USART_CTRLA_RXPO(0);
ctrlb.reg |= SERCOM_USART_CTRLB_RXEN;
SERCOM0->USART.CTRLA.reg = ctrla.reg;
SERCOM0->USART.CTRLB.reg = ctrlb.reg;
if (hri_usbdevice_get_CTRLA_ENABLE_bit(USB)) {
uint64_t br = 65536 - ((65536 * 16.0f * 600) / 8000000);
SERCOM0->USART.BAUD.reg = (uint16_t)br;
} else {
uint64_t br = 65536 - ((65536 * 16.0f * 600) / 4000000);
SERCOM0->USART.BAUD.reg = (uint16_t)br;
}
SERCOM0->USART.CTRLA.reg |= SERCOM_USART_CTRLA_ENABLE;
usart_sync_enable(&USART_0);
usart_sync_get_io_descriptor(&USART_0, &uart_io);
}
void app_setup(void) {
// Set up tick for RTC test
watch_rtc_register_periodic_callback(cb_tick, 8);
// Set up UART for communication with tester
enable_irda_uart();
// Set up LED pins
watch_enable_leds();
watch_enable_buzzer();
// Set up buttons with pull-down resistors
gpio_set_pin_direction(BTN_ALARM, GPIO_DIRECTION_IN);
gpio_set_pin_pull_mode(BTN_ALARM, GPIO_PULL_DOWN);
gpio_set_pin_direction(BTN_LIGHT, GPIO_DIRECTION_IN);
gpio_set_pin_pull_mode(BTN_LIGHT, GPIO_PULL_DOWN);
gpio_set_pin_direction(BTN_MODE, GPIO_DIRECTION_IN);
gpio_set_pin_pull_mode(BTN_MODE, GPIO_PULL_DOWN);
// Set up ADC for thermistor and light sensor tests
watch_enable_adc();
watch_enable_analog_input(TEMPSENSE);
// Pin A0 is the thermistor enable pin
gpio_set_pin_direction(TS_ENABLE, GPIO_DIRECTION_OUT);
}
void app_prepare_for_standby(void) {
}
void app_wake_from_standby(void) {
}
static bool test_i2c(void) {
watch_enable_i2c();
uint16_t device_id = watch_i2c_read8(0x48, 0x0F);
printf("%d\n", device_id);
return device_id == 0x75;
}
static bool test_spi(void) {
gpio_set_pin_level(A3, true);
gpio_set_pin_direction(A3, GPIO_DIRECTION_OUT);
watch_enable_spi();
delay_ms(10);
watch_set_pin_level(A3, false);
delay_ms(10);
uint8_t read_status_response[3] = {0};
bool ok = spi_flash_read_command(0x9F, read_status_response, 3);
watch_set_pin_level(A3, true);
printf("%d %d %d\n", read_status_response[0], read_status_response[1], read_status_response[2]);
return (read_status_response[0] == 0xC8 && read_status_response[1] == 0x40 && read_status_response[2] == 0x13);
}
bool app_loop(void) {
uint8_t buf[5] = {0};
watch_storage_read(10, 0, buf, 4);
printf("%s\n", (const char *)buf);
if (strcmp((const char *)buf, "BEEP") == 0) {
watch_set_led_yellow();
watch_buzzer_play_note(BUZZER_NOTE_C5, 150);
watch_buzzer_play_note(BUZZER_NOTE_REST, 25);
watch_buzzer_play_note(BUZZER_NOTE_E5, 150);
watch_buzzer_play_note(BUZZER_NOTE_REST, 25);
watch_buzzer_play_note(BUZZER_NOTE_G5, 150);
watch_buzzer_play_note(BUZZER_NOTE_REST, 25);
watch_buzzer_play_note(BUZZER_NOTE_C6, 150);
watch_storage_erase(10);
delay_ms(10);
watch_storage_write(10, 0, (const char *)"9PIN", 4);
watch_storage_sync();
watch_storage_read(10, 0, buf, 4);
delay_ms(10);
if(strcmp((const char *)buf, (const char *)"9PIN") == 0) {
watch_set_led_off();
while(1);
}
}
if (strcmp((const char *)buf, "9PIN") == 0) {
bool i2c_passed = test_i2c();
bool spi_passed = test_spi();
if (i2c_passed && spi_passed) {
watch_storage_erase(10);
delay_ms(10);
watch_storage_write(10, 0, (const char *)"PASS", 4);
watch_storage_sync();
watch_storage_read(10, 0, buf, 4);
delay_ms(10);
if(strcmp((const char *)buf, (const char *)"PASS") == 0) {
gpio_set_pin_direction(A0, GPIO_DIRECTION_OUT);
gpio_set_pin_level(A0, true);
}
} else if (i2c_passed) {
// SPI failed, RED indicator
watch_set_led_color_rgb(128, 0, 0);
} else if (spi_passed) {
// I2C failed, BLUE indicator
watch_set_led_color_rgb(0, 0, 128);
} else {
// both failed, PURPLE indicator
watch_set_led_color_rgb(64, 0, 128);
}
while(1);
}
if(strcmp((const char *)buf, (const char *)"PASS") == 0) {
watch_set_led_green();
while(1);
}
char char_received = watch_uart_getc();
if (char_received) {
switch (char_received) {
// - [X] RTC
case 'R':
pass_if(has_ticked);
break;
// - [X] LCD pin continuity
case 'O':
// Set all LCD pins high
for (int i = 0; i < 27; i++) {
gpio_set_pin_function(lcd_pins[i], GPIO_PIN_FUNCTION_OFF);
gpio_set_pin_direction(lcd_pins[i], GPIO_DIRECTION_OUT);
gpio_set_pin_level(lcd_pins[i], true);
}
// It is the tester's responsibility to check that the pins are high
break;
case 'P':
// Set all LCD pins low
for (int i = 0; i < 27; i++) {
gpio_set_pin_function(lcd_pins[i], GPIO_PIN_FUNCTION_OFF);
gpio_set_pin_direction(lcd_pins[i], GPIO_DIRECTION_OUT);
gpio_set_pin_level(lcd_pins[i], false);
}
// It is the tester's responsibility to check that the pins are low
break;
// - [X] LCD pin bridging
case 'Q':
{
bool passed = true;
// Pull all LCD pins up
for (int i = 0; i < 27; i++) {
gpio_set_pin_function(lcd_pins[i], GPIO_PIN_FUNCTION_OFF);
gpio_set_pin_direction(lcd_pins[i], GPIO_DIRECTION_IN);
gpio_set_pin_pull_mode(lcd_pins[i], GPIO_PULL_UP);
}
// SEG23 is adjacent to the green LED.
// setting the LED green drives GREEN low.
watch_set_led_green();
if (!gpio_get_pin_level(SLCD26)) {
// If SEG23 is low, then it must be bridged to the green pin
pass_if(false);
}
// SEG13 is adjacent to the blue LED.
// setting the LED blue drives BLUE low.
watch_set_led_color_rgb(0, 0, 255);
if (!gpio_get_pin_level(SLCD16)) {
// If SEG13 is low, then it must be bridged to the blue pin
pass_if(false);
}
// SEG12 is adjacent to the red LED.
// setting the LED red drives RED low.
watch_set_led_red();
if (!gpio_get_pin_level(SLCD15)) {
// If SEG12 is low, then it must be bridged to the red pin
pass_if(false);
}
watch_set_led_off();
// After this, all LCD pins are adjacent. Test if each pin is bridged to the previous one.
for (int i = 1; i < 27; i++) {
gpio_set_pin_direction(lcd_pins[i - 1], GPIO_DIRECTION_OUT);
gpio_set_pin_level(lcd_pins[i - 1], false);
if (!gpio_get_pin_level(lcd_pins[i])) {
passed = false;
break;
}
gpio_set_pin_direction(lcd_pins[i - 1], GPIO_DIRECTION_IN);
gpio_set_pin_pull_mode(lcd_pins[i - 1], GPIO_PULL_UP);
}
// Special cases:
// SLCD0 neighbors VCC
gpio_set_pin_direction(SLCD0, GPIO_DIRECTION_IN);
gpio_set_pin_pull_mode(SLCD0, GPIO_PULL_DOWN);
if (gpio_get_pin_level(SLCD0)) {
passed = false;
}
// SLCD18 neighbors VCC
gpio_set_pin_direction(SLCD18, GPIO_DIRECTION_IN);
gpio_set_pin_pull_mode(SLCD18, GPIO_PULL_DOWN);
if (gpio_get_pin_level(SLCD18)) {
passed = false;
}
// SLCD26 neighbors USB_N
gpio_set_pin_direction(GPIO(GPIO_PORTA, 24), GPIO_DIRECTION_OUT);
gpio_set_pin_level(GPIO(GPIO_PORTA, 24), true);
gpio_set_pin_direction(SLCD26, GPIO_DIRECTION_IN);
gpio_set_pin_pull_mode(SLCD26, GPIO_PULL_DOWN);
// if SLCD26 is high, then it is bridged to USB_N
if (gpio_get_pin_level(SLCD26)) {
passed = false;
}
// SLCD11 neighbors VLCD
watch_enable_display();
delay_ms(50);
gpio_set_pin_function(SLCD11, GPIO_PIN_FUNCTION_OFF);
gpio_set_pin_direction(SLCD11, GPIO_DIRECTION_IN);
gpio_set_pin_pull_mode(SLCD11, GPIO_PULL_DOWN);
if (gpio_get_pin_level(SLCD11)) {
passed = false;
}
for (int i = 0; i < 27; i++) {
gpio_set_pin_function(lcd_pins[i], GPIO_PIN_FUNCTION_OFF);
gpio_set_pin_direction(lcd_pins[i], GPIO_DIRECTION_IN);
gpio_set_pin_pull_mode(lcd_pins[i], GPIO_PULL_OFF);
}
pass_if(passed);
}
break;
// - [X] Thermistor high
case 'U':
// Set TS_ENABLE high and read the value of TEMPSENSE via the ADC.
// Pass if the value is near VCC.
gpio_set_pin_level(TS_ENABLE, true);
pass_if(watch_get_analog_pin_level(TEMPSENSE) > 65000);
break;
// - [X] Thermistor low
case 'T':
{
// Set TS_ENABLE low and read the value of TEMPSENSE via the ADC.
// Pass if the value is within the realm of reasonable temperatures.
// 15000 is a few minutes in the freezer, 45000 is holding it a few feet above a stovetop
gpio_set_pin_level(TS_ENABLE, false);
uint16_t value = watch_get_analog_pin_level(TEMPSENSE);
pass_if(value < 45000 && value > 15000);
}
break;
// - [X] VLCD low
case 'V':
watch_enable_display();
SLCD->CTRLA.bit.ENABLE = 0;
while(SLCD->SYNCBUSY.bit.ENABLE);
SLCD->CTRLC.bit.CTST = 0x0;
SLCD->CTRLA.bit.ENABLE = 1;
while(SLCD->SYNCBUSY.bit.ENABLE);
break;
// - [X] VLCD high
case 'W':
watch_enable_display();
SLCD->CTRLA.bit.ENABLE = 0;
while(SLCD->SYNCBUSY.bit.ENABLE);
SLCD->CTRLC.bit.CTST = 0xD;
SLCD->CTRLA.bit.ENABLE = 1;
while(SLCD->SYNCBUSY.bit.ENABLE);
break;
/// TODO: LED
case 'r':
watch_set_led_color_rgb(255, 0, 0);
delay_ms(100);
watch_set_led_color_rgb(0, 0, 0);
// It is the tester's responsibility to check the LED color.
break;
case 'g':
watch_set_led_color_rgb(0, 255, 0);
delay_ms(100);
watch_set_led_color_rgb(0, 0, 0);
// It is the tester's responsibility to check the LED color.
break;
case 'b':
watch_set_led_color_rgb(0, 0, 255);
delay_ms(100);
watch_set_led_color_rgb(0, 0, 0);
// It is the tester's responsibility to check the LED color.
break;
// - [X] Buttons
case 'B':
// Pass if all three buttons are low
pass_if(!gpio_get_pin_level(BTN_ALARM) && !gpio_get_pin_level(BTN_LIGHT) && !gpio_get_pin_level(BTN_MODE));
break;
case 'L':
// pass if BTN_LIGHT is high and the other two are low
pass_if(gpio_get_pin_level(BTN_LIGHT) && !gpio_get_pin_level(BTN_ALARM) && !gpio_get_pin_level(BTN_MODE));
break;
case 'A':
// pass if BTN_ALARM is high and the other two are low
pass_if(gpio_get_pin_level(BTN_ALARM) && !gpio_get_pin_level(BTN_LIGHT) && !gpio_get_pin_level(BTN_MODE));
break;
case 'M':
// pass if BTN_MODE is high and the other two are low
pass_if(gpio_get_pin_level(BTN_MODE) && !gpio_get_pin_level(BTN_ALARM) && !gpio_get_pin_level(BTN_LIGHT));
break;
// - [X] File system
case 'F':
watch_storage_erase(10);
delay_ms(10);
watch_storage_write(10, 0, (const char *)"BEEP", 4);
watch_storage_sync();
watch_storage_read(10, 0, buf, 4);
delay_ms(10);
// No need to do anything here; comparison with 'beep' happens at next loop invocation.
break;
}
}
return false;
}

View File

@@ -0,0 +1,10 @@
TOP = ../../..
include $(TOP)/make.mk
INCLUDES += \
-I../
SRCS += \
../app.c
include $(TOP)/rules.mk

View File

@@ -12,6 +12,14 @@
#define BTN_MODE GPIO(GPIO_PORTA, 31) #define BTN_MODE GPIO(GPIO_PORTA, 31)
#define WATCH_BTN_MODE_EIC_CHANNEL 11 #define WATCH_BTN_MODE_EIC_CHANNEL 11
// Temperature Sensor
#define TS_ENABLE GPIO(GPIO_PORTB, 23)
#define TEMPSENSE GPIO(GPIO_PORTA, 3)
// Light Sensor
#define IR_ENABLE GPIO(GPIO_PORTB, 22)
#define IRSENSE GPIO(GPIO_PORTA, 4)
// Buzzer // Buzzer
#define BUZZER GPIO(GPIO_PORTA, 27) #define BUZZER GPIO(GPIO_PORTA, 27)
#define WATCH_BUZZER_TCC_PINMUX PINMUX_PA27F_TCC0_WO5 #define WATCH_BUZZER_TCC_PINMUX PINMUX_PA27F_TCC0_WO5

View File

@@ -223,7 +223,7 @@ ifndef COLOR
$(error Set the COLOR variable to RED, BLUE, or GREEN depending on what board you have.) $(error Set the COLOR variable to RED, BLUE, or GREEN depending on what board you have.)
endif endif
COLOR_VALID := $(filter $(COLOR),RED BLUE GREEN) COLOR_VALID := $(filter $(COLOR),RED BLUE GREEN PRO)
ifeq ($(COLOR_VALID),) ifeq ($(COLOR_VALID),)
$(error COLOR must be RED, BLUE, or GREEN) $(error COLOR must be RED, BLUE, or GREEN)

View File

@@ -2,36 +2,35 @@
// //
// This software minimizes computational work by performing the full calculation // This software minimizes computational work by performing the full calculation
// of the lunar position three times, at the beginning, middle, and end of the // of the lunar position three times, at the beginning, middle, and end of the
// period of interest. Three point interpolation is used to predict the position // period of interest. Three point interpolation is used to predict the
// for each hour, and the arithmetic mean is used to predict the half-hour positions. // position for each hour, and the arithmetic mean is used to predict the
// half-hour positions.
// //
// The full computational burden is negligible on modern computers, but the // The full computational burden is negligible on modern computers, but the
// algorithm is effective and still useful for small embedded systems. // algorithm is effective and still useful for small embedded systems.
// //
// This software was originally adapted to javascript by Stephen R. Schmitt // This software was originally adapted to javascript by Stephen R. Schmitt
// from a BASIC program from the 'Astronomical Computing' column of Sky & Telescope, // from a BASIC program from the 'Astronomical Computing' column of Sky &
// April 1989, page 78. // Telescope, April 1989, page 78.
// //
// Subsequently adapted from Stephen R. Schmitt's javascript to c++ for the Arduino // Subsequently adapted from Stephen R. Schmitt's javascript to c++ for the
// by Cyrus Rahman. // Arduino by Cyrus Rahman.
// //
// Subsequently adapted from Cyrus Rahman's Arduino C++ to C for the Sensor Watch // Subsequently adapted from Cyrus Rahman's Arduino C++ to C for the Sensor
// by hueso, this work is subject to Stephen Schmitt's copyright: // Watch by hueso, this work is subject to Stephen Schmitt's copyright:
// //
// Copyright 2007 Stephen R. Schmitt // Copyright 2007 Stephen R. Schmitt
// Subsequent work Copyright 2020 Cyrus Rahman // Subsequent work Copyright 2020 Cyrus Rahman
// You may use or modify this source code in any way you find useful, provided // You may use or modify this source code in any way you find useful, provided
// that you agree that the author(s) have no warranty, obligations or liability. You // that you agree that the author(s) have no warranty, obligations or liability.
// must determine the suitability of this source code for your use. // You must determine the suitability of this source code for your use.
// //
// Redistributions of this source code must retain this copyright notice. // Redistributions of this source code must retain this copyright notice.
#include <math.h>
#include <stdbool.h>
#include <stdlib.h>
#include "moonrise.h" #include "moonrise.h"
#include <math.h>
#define K1 15*(M_PI/180)*1.0027379 #define K1 15 * (M_PI / 180) * 1.0027379
// Determine the nearest moon rise or set event previous, and the nearest // Determine the nearest moon rise or set event previous, and the nearest
// moon rise or set event subsequent, to the specified time in seconds since the // moon rise or set event subsequent, to the specified time in seconds since the
@@ -40,15 +39,15 @@
// //
// We look for events from MR_WINDOW/2 hours in the past to MR_WINDOW/2 hours // We look for events from MR_WINDOW/2 hours in the past to MR_WINDOW/2 hours
// in the future. // in the future.
MoonRise MoonRise_calculate(double latitude, double longitude, time_t t) { MoonRise MoonRise_calculate(double latitude, double longitude, uint32_t t) {
MoonRise self; MoonRise self = {};
skyCoordinates moonPosition[3]; skyCoordinates moonPosition[3];
double offsetDays; double offsetDays;
self.queryTime = t; self.queryTime = t;
offsetDays = julianDate(t) - 2451545L; // Days since Jan 1, 2000, 1200UTC. offsetDays = julianDate(t) - 2451545L; // Days since Jan 1, 2000, 1200UTC.
// Begin testing (MR_WINDOW / 2) hours before requested time. // Begin testing (MR_WINDOW / 2) hours before requested time.
offsetDays -= (double)MR_WINDOW / (2 * 24) ; // offsetDays -= (double)MR_WINDOW / (2 * 24) ;
// Calculate coordinates at start, middle, and end of search period. // Calculate coordinates at start, middle, and end of search period.
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
@@ -64,142 +63,150 @@ MoonRise MoonRise_calculate(double latitude, double longitude, time_t t) {
// Initialize interpolation array. // Initialize interpolation array.
skyCoordinates mpWindow[3]; skyCoordinates mpWindow[3];
mpWindow[0].RA = moonPosition[0].RA; mpWindow[0].RA = moonPosition[0].RA;
mpWindow[0].declination = moonPosition[0].declination; mpWindow[0].declination = moonPosition[0].declination;
mpWindow[0].distance = moonPosition[0].distance; mpWindow[0].distance = moonPosition[0].distance;
for (int k = 0; k < MR_WINDOW; k++) { // Check each interval of search period for (int k = 0; k < MR_WINDOW; k++) { // Check each interval of search period
float ph = (float)(k + 1)/MR_WINDOW; float ph = (float)(k + 1) / MR_WINDOW;
mpWindow[2].RA = interpolate(moonPosition[0].RA, mpWindow[2].RA = interpolate(moonPosition[0].RA, moonPosition[1].RA,
moonPosition[1].RA, moonPosition[2].RA, ph);
moonPosition[2].RA, ph); mpWindow[2].declination =
mpWindow[2].declination = interpolate(moonPosition[0].declination, interpolate(moonPosition[0].declination, moonPosition[1].declination,
moonPosition[1].declination, moonPosition[2].declination, ph);
moonPosition[2].declination, ph);
mpWindow[2].distance = moonPosition[2].distance; mpWindow[2].distance = moonPosition[2].distance;
// Look for moonrise/set events during this interval. // Look for moonrise/set events during this interval.
{ {
double ha[3], VHz[3]; double ha[3], VHz[3];
double lSideTime; double lSideTime;
// Get (local_sidereal_time - MR_WINDOW / 2) hours in radians. // Get (local_sidereal_time - MR_WINDOW / 2) hours in radians.
lSideTime = localSiderealTime(offsetDays, longitude) * 2* M_PI / 360; lSideTime = localSiderealTime(offsetDays, longitude) * 2 * M_PI / 360;
// Calculate Hour Angle. // Calculate Hour Angle.
ha[0] = lSideTime - mpWindow[0].RA + k*K1; ha[0] = lSideTime - mpWindow[0].RA + k * K1;
ha[2] = lSideTime - mpWindow[2].RA + k*K1 + K1; ha[2] = lSideTime - mpWindow[2].RA + k * K1 + K1;
// Hour Angle and declination at half hour. // Hour Angle and declination at half hour.
ha[1] = (ha[2] + ha[0])/2; ha[1] = (ha[2] + ha[0]) / 2;
mpWindow[1].declination = (mpWindow[2].declination + mpWindow[0].declination)/2; mpWindow[1].declination =
(mpWindow[2].declination + mpWindow[0].declination) / 2;
double s = sin(M_PI / 180 * latitude); double s = sin(M_PI / 180 * latitude);
double c = cos(M_PI / 180 * latitude); double c = cos(M_PI / 180 * latitude);
// refraction + semidiameter at horizon + distance correction // refraction + semidiameter at horizon + distance correction
double z = cos(M_PI / 180 * (90.567 - 41.685 / mpWindow[0].distance)); double z = cos(M_PI / 180 * (90.567 - 41.685 / mpWindow[0].distance));
VHz[0] = s * sin(mpWindow[0].declination) + c * cos(mpWindow[0].declination) * cos(ha[0]) - z; VHz[0] = s * sin(mpWindow[0].declination) +
VHz[2] = s * sin(mpWindow[2].declination) + c * cos(mpWindow[2].declination) * cos(ha[2]) - z; c * cos(mpWindow[0].declination) * cos(ha[0]) - z;
VHz[2] = s * sin(mpWindow[2].declination) +
c * cos(mpWindow[2].declination) * cos(ha[2]) - z;
if (signbit(VHz[0]) == signbit(VHz[2])) if (signbit(VHz[0]) == signbit(VHz[2]))
goto noevent; // No event this hour. goto noevent; // No event this hour.
VHz[1] = s * sin(mpWindow[1].declination) + c * cos(mpWindow[1].declination) * cos(ha[1]) - z; VHz[1] = s * sin(mpWindow[1].declination) +
c * cos(mpWindow[1].declination) * cos(ha[1]) - z;
double a, b, d, e, time; double a, b, d, e, time;
a = 2 * VHz[2] - 4 * VHz[1] + 2 * VHz[0]; a = 2 * VHz[2] - 4 * VHz[1] + 2 * VHz[0];
b = 4 * VHz[1] - 3 * VHz[0] - VHz[2]; b = 4 * VHz[1] - 3 * VHz[0] - VHz[2];
d = b * b - 4 * a * VHz[0]; d = b * b - 4 * a * VHz[0];
if (d < 0) if (d < 0)
goto noevent; // No event this hour. goto noevent; // No event this hour.
d = sqrt(d); d = sqrt(d);
e = (-b + d) / (2 * a); e = (-b + d) / (2 * a);
if ((e < 0) || (e > 1)) if ((e < 0) || (e > 1))
e = (-b - d) / (2 * a); e = (-b - d) / (2 * a);
time = k + e + 1 / 120; // Time since k=0 of event (in hours). time = k + e + 1 / 120; // Time since k=0 of event (in hours).
// The time we started searching + the time from the start of the search to the // The time we started searching + the time from the start of the search
// event is the time of the event. Add (time since k=0) - window/2 hours. // to the event is the time of the event.
time_t eventTime; uint32_t eventTime;
eventTime = self.queryTime + (time - MR_WINDOW / 2) *60 *60; eventTime = self.queryTime + (time) * 60 * 60;
double hz, nz, dz, az; double hz, nz, dz, az;
hz = ha[0] + e * (ha[2] - ha[0]); // Azimuth of the moon at the event. hz = ha[0] + e * (ha[2] - ha[0]); // Azimuth of the moon at the event.
nz = -cos(mpWindow[1].declination) * sin(hz); nz = -cos(mpWindow[1].declination) * sin(hz);
dz = c * sin(mpWindow[1].declination) - s * cos(mpWindow[1].declination) * cos(hz); dz = c * sin(mpWindow[1].declination) -
az = atan2(nz, dz) / (M_PI / 180); s * cos(mpWindow[1].declination) * cos(hz);
if (az < 0) az = atan2(nz, dz) / (M_PI / 180);
if (az < 0)
az += 360; az += 360;
// If there is no previously recorded event of this type, save this event. // If there is no previously recorded event of this type, save this event.
// //
// If this event is previous to queryTime, and is the nearest event to queryTime // If this event is previous to queryTime, and is the nearest event to
// of events of its type previous to queryType, save this event, replacing the // queryTime of events of its type previous to queryType, save this event,
// previously recorded event of its type. Events subsequent to queryTime are // replacing the previously recorded event of its type. Events subsequent
// treated similarly, although since events are tested in chronological order // to queryTime are treated similarly, although since events are tested in
// no replacements will occur as successive events will be further from // chronological order no replacements will occur as successive events
// queryTime. // will be further from queryTime.
// //
// If this event is subsequent to queryTime and there is an event of its type // If this event is subsequent to queryTime and there is an event of its
// previous to queryTime, then there is an event of the other type between the // type previous to queryTime, then there is an event of the other type
// two events of this event's type. If the event of the other type is // between the two events of this event's type. If the event of the other
// previous to queryTime, then it is the nearest event to queryTime that is // type is previous to queryTime, then it is the nearest event to
// previous to queryTime. In this case save the current event, replacing // queryTime that is previous to queryTime. In this case save the current
// the previously recorded event of its type. Otherwise discard the current // event, replacing the previously recorded event of its type. Otherwise
// event. // discard the current event.
// //
if ((VHz[0] < 0) && (VHz[2] > 0)) { if ((VHz[0] < 0) && (VHz[2] > 0)) {
if (!self.hasRise || if (!self.hasRise ||
((self.riseTime < self.queryTime) == (eventTime < self.queryTime) && ((self.riseTime < self.queryTime) == (eventTime < self.queryTime) &&
llabs(self.riseTime - self.queryTime) > llabs(eventTime - self.queryTime)) || (self.riseTime - self.queryTime) > (eventTime - self.queryTime)) ||
((self.riseTime < self.queryTime) != (eventTime < self.queryTime) && ((self.riseTime < self.queryTime) != (eventTime < self.queryTime) &&
(self.hasSet && (self.hasSet && (self.riseTime < self.queryTime) ==
(self.riseTime < self.queryTime) == (self.setTime < self.queryTime)))) { (self.setTime < self.queryTime)))) {
self.riseTime = eventTime; self.riseTime = eventTime;
self.riseAz = az; self.riseAz = az;
self.hasRise = true; self.hasRise = true;
}
} }
if ((VHz[0] > 0) && (VHz[2] < 0)) { }
if (!self.hasSet || if ((VHz[0] > 0) && (VHz[2] < 0)) {
if (!self.hasSet ||
((self.setTime < self.queryTime) == (eventTime < self.queryTime) && ((self.setTime < self.queryTime) == (eventTime < self.queryTime) &&
llabs(self.setTime - self.queryTime) > llabs(eventTime - self.queryTime)) || (self.setTime - self.queryTime) > (eventTime - self.queryTime)) ||
((self.setTime < self.queryTime) != (eventTime < self.queryTime) && ((self.setTime < self.queryTime) != (eventTime < self.queryTime) &&
(self.hasRise && (self.hasRise && (self.setTime < self.queryTime) ==
(self.setTime < self.queryTime) == (self.riseTime < self.queryTime)))) { (self.riseTime < self.queryTime)))) {
self.setTime = eventTime; self.setTime = eventTime;
self.setAz = az; self.setAz = az;
self.hasSet = true; self.hasSet = true;
}
} }
}
noevent: noevent:
// There are obscure cases in the polar regions that require extra logic. // There are obscure cases in the polar regions that require extra logic.
if (!self.hasRise && !self.hasSet) if (!self.hasRise && !self.hasSet)
self.isVisible = !signbit(VHz[2]); self.isVisible = !signbit(VHz[2]);
else if (self.hasRise && !self.hasSet) else if (self.hasRise && !self.hasSet)
self.isVisible = (self.queryTime > self.riseTime); self.isVisible = (self.queryTime > self.riseTime);
else if (!self.hasRise && self.hasSet) else if (!self.hasRise && self.hasSet)
self.isVisible = (self.queryTime < self.setTime); self.isVisible = (self.queryTime < self.setTime);
else else
self.isVisible = ((self.riseTime < self.setTime && self.riseTime < self.queryTime && self.setTime > self.queryTime) || self.isVisible =
(self.riseTime > self.setTime && (self.riseTime < self.queryTime || self.setTime > self.queryTime))); ((self.riseTime < self.setTime && self.riseTime < self.queryTime &&
self.setTime > self.queryTime) ||
(self.riseTime > self.setTime && (self.riseTime < self.queryTime ||
self.setTime > self.queryTime)));
}
} if (self.hasSet && self.hasRise)
break;
mpWindow[0] = mpWindow[2]; // Advance to next interval. mpWindow[0] = mpWindow[2]; // Advance to next interval.
} }
return self; return self;
} }
// Moon position using fundamental arguments
// Moon position using fundamental arguments
// (Van Flandern & Pulkkinen, 1979) // (Van Flandern & Pulkkinen, 1979)
skyCoordinates moon(double dayOffset) { skyCoordinates moon(double dayOffset) {
double l = 0.606434 + 0.03660110129 * dayOffset; double l = 0.606434 + 0.03660110129 * dayOffset;
@@ -275,7 +282,7 @@ double interpolate(double f0, double f1, double f2, double p) {
// Determine Julian date from Unix time. // Determine Julian date from Unix time.
// Provides marginally accurate results with Arduino 4-byte double. // Provides marginally accurate results with Arduino 4-byte double.
double julianDate(time_t t) { double julianDate(uint32_t t) {
return (t / 86400.0L + 2440587.5); return (t / 86400.0L + 2440587.5);
} }

View File

@@ -1,7 +1,8 @@
#ifndef MoonRise_h #ifndef MoonRise_h
#define MoonRise_h #define MoonRise_h
#include <time.h> #include <stdint.h>
#include <stdbool.h>
// Size of event search window in hours. // Size of event search window in hours.
// Events further away from the search time than MR_WINDOW/2 will not be // Events further away from the search time than MR_WINDOW/2 will not be
@@ -10,33 +11,33 @@
// windows will increase interpolation error. Useful values are probably from // windows will increase interpolation error. Useful values are probably from
// 12 - 48 but will depend upon your application. // 12 - 48 but will depend upon your application.
#define MR_WINDOW 72 // Even integer #define MR_WINDOW 48 // Even integer
typedef struct { typedef struct {
double RA; // Right ascension double RA; // Right ascension
double declination; // Declination double declination; // Declination
double distance; // Distance double distance; // Distance
} skyCoordinates; } skyCoordinates;
typedef struct { typedef struct {
time_t queryTime; uint32_t queryTime;
time_t riseTime; uint32_t riseTime;
time_t setTime; uint32_t setTime;
float riseAz; float riseAz;
float setAz; float setAz;
bool hasRise; bool hasRise;
bool hasSet; bool hasSet;
bool isVisible; bool isVisible;
} MoonRise; } MoonRise;
MoonRise MoonRise_calculate(double latitude, double longitude, time_t t); MoonRise MoonRise_calculate(double latitude, double longitude, uint32_t t);
// private: // private:
void testMoonRiseSet(MoonRise *self, int i, double offsetDays, double latitude, double longitude, void testMoonRiseSet(MoonRise *self, int i, double offsetDays, double latitude,
skyCoordinates *mp); double longitude, skyCoordinates *mp);
skyCoordinates moon(double dayOffset); skyCoordinates moon(double dayOffset);
double interpolate(double f0, double f1, double f2, double p); double interpolate(double f0, double f1, double f2, double p);
double julianDate(time_t t); double julianDate(uint32_t t);
double localSiderealTime(double offsetDays, double longitude); double localSiderealTime(double offsetDays, double longitude);
#endif #endif

View File

@@ -33,20 +33,20 @@ const char *words[12] = {
" ", " ",
" 5", " 5",
"10", "10",
"15", "CU",
"20", "20",
"25", "Me",
"30", "ME",
"35", "mE",
"40", "40",
"45", "45",
"50", "50",
"55", "55",
}; };
static const char *past_word = " P"; static const char *past_word = " y";
static const char *to_word = " 2"; static const char *to_word = " -";
static const char *oclock_word = "OC"; static const char *oclock_word = "EP";
// sets when in the five minute period we switch // sets when in the five minute period we switch
// from "X past HH" to "X to HH+1" // from "X past HH" to "X to HH+1"
@@ -55,9 +55,9 @@ static const int hour_switch_index = 8;
static void _update_alarm_indicator(bool settings_alarm_enabled, close_enough_clock_state_t *state) { static void _update_alarm_indicator(bool settings_alarm_enabled, close_enough_clock_state_t *state) {
state->alarm_enabled = settings_alarm_enabled; state->alarm_enabled = settings_alarm_enabled;
if (state->alarm_enabled) { if (state->alarm_enabled) {
watch_set_indicator(WATCH_INDICATOR_BELL); watch_set_indicator(WATCH_INDICATOR_SIGNAL);
} else { } else {
watch_clear_indicator(WATCH_INDICATOR_BELL); watch_clear_indicator(WATCH_INDICATOR_SIGNAL);
}; };
} }
@@ -185,7 +185,7 @@ bool close_enough_clock_face_loop(movement_event_t event, movement_settings_t *s
int words_length = sizeof(words) / sizeof(words[0]); int words_length = sizeof(words) / sizeof(words[0]);
strncpy( strncpy(
first_word, third_word,
five_minute_period >= hour_switch_index ? five_minute_period >= hour_switch_index ?
words[words_length - five_minute_period] : words[words_length - five_minute_period] :
words[five_minute_period], words[five_minute_period],
@@ -197,7 +197,7 @@ bool close_enough_clock_face_loop(movement_event_t event, movement_settings_t *s
to_word : past_word, to_word : past_word,
3 3
); );
sprintf(third_word, "%2d", close_enough_hour); sprintf(first_word, "%2d", close_enough_hour);
} }
sprintf( sprintf(

View File

@@ -148,7 +148,7 @@ static void _alarm_update_alarm_enabled(movement_settings_t *settings, alarm_sta
uint16_t now_minutes_of_day; uint16_t now_minutes_of_day;
uint16_t alarm_minutes_of_day; uint16_t alarm_minutes_of_day;
for (uint8_t i = 0; i < ALARM_ALARMS; i++) { for (uint8_t i = 0; i < ALARM_ALARMS; i++) {
if (state->alarm[i].enabled) { if (state->alarm[i].enabled && state->alarm[i].beeps != 0) {
// figure out if alarm is to go off in the next 24 h // figure out if alarm is to go off in the next 24 h
if (state->alarm[i].day == ALARM_DAY_EACH_DAY || state->alarm[i].day == ALARM_DAY_ONE_TIME) { if (state->alarm[i].day == ALARM_DAY_EACH_DAY || state->alarm[i].day == ALARM_DAY_ONE_TIME) {
active_alarms = true; active_alarms = true;
@@ -235,7 +235,6 @@ void alarm_face_resign(movement_settings_t *settings, void *context) {
alarm_state_t *state = (alarm_state_t *)context; alarm_state_t *state = (alarm_state_t *)context;
state->is_setting = false; state->is_setting = false;
_alarm_update_alarm_enabled(settings, state); _alarm_update_alarm_enabled(settings, state);
watch_set_led_off();
state->alarm_quick_ticks = false; state->alarm_quick_ticks = false;
_wait_ticks = -1; _wait_ticks = -1;
movement_request_tick_frequency(1); movement_request_tick_frequency(1);

View File

@@ -39,16 +39,19 @@
static const uint8_t _location_count = sizeof(longLatPresets) / sizeof(long_lat_presets_t); static const uint8_t _location_count = sizeof(longLatPresets) / sizeof(long_lat_presets_t);
static void _moonrise_set_expiration(moonrise_state_t *state, watch_date_time next_rise_set) {
uint32_t timestamp = watch_utility_date_time_to_unix_time(next_rise_set, 0);
state->rise_set_expires = watch_utility_date_time_from_unix_time(timestamp + 60, 0);
}
static void _moonrise_face_update(movement_settings_t *settings, moonrise_state_t *state) { static void _moonrise_face_update(movement_settings_t *settings, moonrise_state_t *state) {
char buf[14]; char buf[11];
bool show_next_match = false;
movement_location_t movement_location; movement_location_t movement_location;
watch_clear_colon();
watch_clear_indicator(WATCH_INDICATOR_PM);
watch_clear_indicator(WATCH_INDICATOR_24H);
// watch_display_string("__ _ ", 0);
if(state->rise_index == 0)
watch_display_string("M~ rise", 0);
else
watch_display_string("M_ set ", 0);
if (state->longLatToUse == 0 || _location_count <= 1) if (state->longLatToUse == 0 || _location_count <= 1)
movement_location = (movement_location_t) watch_get_backup_data(1); movement_location = (movement_location_t) watch_get_backup_data(1);
else{ else{
@@ -57,7 +60,8 @@ static void _moonrise_face_update(movement_settings_t *settings, moonrise_state_
} }
if (movement_location.reg == 0) { if (movement_location.reg == 0) {
watch_display_string("MR no Loc", 0); watch_clear_colon();
watch_display_string("Mz no Loc", 0);
return; return;
} }
@@ -73,83 +77,53 @@ static void _moonrise_face_update(movement_settings_t *settings, moonrise_state_
double lat = (double)lat_centi / 100.0; double lat = (double)lat_centi / 100.0;
double lon = (double)lon_centi / 100.0; double lon = (double)lon_centi / 100.0;
time_t t = watch_utility_date_time_to_unix_time(scratch_time, movement_timezone_offsets[settings->bit.time_zone] * 60); uint32_t t = watch_utility_date_time_to_unix_time(date_time, movement_timezone_offsets[settings->bit.time_zone] * 60);
MoonRise mr = MoonRise_calculate(lat, lon, t); MoonRise mr = MoonRise_calculate(lat, lon, t);
if(mr.isVisible) if(mr.isVisible)
watch_set_indicator(WATCH_INDICATOR_LAP); watch_set_indicator(WATCH_INDICATOR_LAP);
else else
watch_clear_indicator(WATCH_INDICATOR_LAP); watch_clear_indicator(WATCH_INDICATOR_LAP);
for(int i = 0; i < 2; i++) { if ( (state->rise_index == 0 && !mr.hasRise) ||
t = watch_utility_date_time_to_unix_time(scratch_time, movement_timezone_offsets[settings->bit.time_zone] * 60); (state->rise_index == 1 && !mr.hasSet) ) {
watch_clear_colon();
MoonRise mr = MoonRise_calculate(lat, lon, t); watch_clear_indicator(WATCH_INDICATOR_PM);
watch_clear_indicator(WATCH_INDICATOR_24H);
if (!mr.hasRise && !mr.hasSet) { snprintf(buf, sizeof(buf), "%s%2d none ", state->rise_index ? "M_" : "M~", scratch_time.unit.day);
watch_clear_colon(); watch_display_string(buf, 0);
watch_clear_indicator(WATCH_INDICATOR_PM); state->rise_set_expires = watch_utility_date_time_from_unix_time(
watch_clear_indicator(WATCH_INDICATOR_24H); watch_utility_offset_timestamp(t, MR_WINDOW, 0, 0),
sprintf(buf, "MR%2d none ", scratch_time.unit.day); movement_timezone_offsets[settings->bit.time_zone] * 60);
watch_display_string(buf, 0); return;
return; }
}
watch_set_colon(); watch_set_colon();
if (settings->bit.clock_mode_24h && !settings->bit.clock_24h_leading_zero) if (settings->bit.clock_mode_24h && !settings->bit.clock_24h_leading_zero)
watch_set_indicator(WATCH_INDICATOR_24H); watch_set_indicator(WATCH_INDICATOR_24H);
scratch_time = watch_utility_date_time_from_unix_time(mr.riseTime, movement_timezone_offsets[settings->bit.time_zone] * 60); if(state->rise_index == 0)
scratch_time = watch_utility_date_time_from_unix_time(mr.riseTime, movement_timezone_offsets[settings->bit.time_zone] * 60);
else
scratch_time = watch_utility_date_time_from_unix_time(mr.setTime, movement_timezone_offsets[settings->bit.time_zone] * 60);
if (date_time.reg < scratch_time.reg) _moonrise_set_expiration(state, scratch_time); state->rise_set_expires.reg = scratch_time.reg;
if (date_time.reg < scratch_time.reg || show_next_match) { bool set_leading_zero = false;
if (state->rise_index == 0 || show_next_match) { if (!settings->bit.clock_mode_24h)
bool set_leading_zero = false; if (watch_utility_convert_to_12_hour(&scratch_time))
if (!settings->bit.clock_mode_24h) { watch_set_indicator(WATCH_INDICATOR_PM);
if (watch_utility_convert_to_12_hour(&scratch_time)) watch_set_indicator(WATCH_INDICATOR_PM); else
else watch_clear_indicator(WATCH_INDICATOR_PM); watch_clear_indicator(WATCH_INDICATOR_PM);
} else if (settings->bit.clock_24h_leading_zero && scratch_time.unit.hour < 10) { else if (settings->bit.clock_24h_leading_zero && scratch_time.unit.hour < 10) {
set_leading_zero = true; set_leading_zero = true;
}
sprintf(buf, "M %2d%2d%02d%s", scratch_time.unit.day, scratch_time.unit.hour, scratch_time.unit.minute,longLatPresets[state->longLatToUse].name);
watch_display_string(buf, 0);
watch_set_pixel(0,11);
if (set_leading_zero)
watch_display_string("0", 4);
return;
} else {
show_next_match = true;
}
} }
snprintf(buf, sizeof(buf), "%s%2d%2d%02d%2s", state->rise_index ? "M_" : "M~", scratch_time.unit.day, scratch_time.unit.hour, scratch_time.unit.minute,longLatPresets[state->longLatToUse].name);
watch_display_string(buf, 0);
scratch_time = watch_utility_date_time_from_unix_time(mr.setTime, movement_timezone_offsets[settings->bit.time_zone] * 60); if (set_leading_zero)
watch_display_string("0", 4);
return;
if (date_time.reg < scratch_time.reg) _moonrise_set_expiration(state, scratch_time);
if (date_time.reg < scratch_time.reg || show_next_match) {
if (state->rise_index == 0 || show_next_match) {
bool set_leading_zero = false;
if (!settings->bit.clock_mode_24h) {
if (watch_utility_convert_to_12_hour(&scratch_time)) watch_set_indicator(WATCH_INDICATOR_PM);
else watch_clear_indicator(WATCH_INDICATOR_PM);
} else if (settings->bit.clock_24h_leading_zero && scratch_time.unit.hour < 10) {
set_leading_zero = true;
}
sprintf(buf, "M %2d%2d%02d%s", scratch_time.unit.day, scratch_time.unit.hour, scratch_time.unit.minute, longLatPresets[state->longLatToUse].name);
watch_display_string(buf, 0);
watch_set_pixel(2,11);
if (set_leading_zero)
watch_display_string("0", 4);
return;
} else {
show_next_match = true;
}
}
// it's after sunset. we need to display sunrise/sunset for tomorrow.
uint32_t timestamp = watch_utility_date_time_to_unix_time(date_time, 0);
timestamp += 86400;
scratch_time = watch_utility_date_time_from_unix_time(timestamp, 0);
}
} }
static int16_t _moonrise_face_latlon_from_struct(moonrise_lat_lon_settings_t val) { static int16_t _moonrise_face_latlon_from_struct(moonrise_lat_lon_settings_t val) {
@@ -201,10 +175,10 @@ static void _moonrise_face_update_settings_display(movement_event_t event, moonr
case 0: case 0:
return; return;
case 1: case 1:
sprintf(buf, "LA %c %04d", state->working_latitude.sign ? '-' : '+', abs(_moonrise_face_latlon_from_struct(state->working_latitude))); snprintf(buf, sizeof(buf), "LA %c %04d", state->working_latitude.sign ? '-' : '+', abs(_moonrise_face_latlon_from_struct(state->working_latitude)));
break; break;
case 2: case 2:
sprintf(buf, "LO %c%05d", state->working_longitude.sign ? '-' : '+', abs(_moonrise_face_latlon_from_struct(state->working_longitude))); snprintf(buf, sizeof(buf), "LO %c%05d", state->working_longitude.sign ? '-' : '+', abs(_moonrise_face_latlon_from_struct(state->working_longitude)));
break; break;
} }
if (event.subsecond % 2) { if (event.subsecond % 2) {

View File

@@ -330,6 +330,5 @@ bool simon_face_loop(movement_event_t event, movement_settings_t *settings,
void simon_face_resign(movement_settings_t *settings, void *context) { void simon_face_resign(movement_settings_t *settings, void *context) {
(void)settings; (void)settings;
(void)context; (void)context;
watch_set_led_off();
watch_set_buzzer_off(); watch_set_buzzer_off();
} }

View File

@@ -45,7 +45,7 @@ static void _sunrise_sunset_set_expiration(sunrise_sunset_state_t *state, watch_
} }
static void _sunrise_sunset_face_update(movement_settings_t *settings, sunrise_sunset_state_t *state) { static void _sunrise_sunset_face_update(movement_settings_t *settings, sunrise_sunset_state_t *state) {
char buf[14]; char buf[11];
double rise, set, minutes, seconds; double rise, set, minutes, seconds;
bool show_next_match = false; bool show_next_match = false;
movement_location_t movement_location; movement_location_t movement_location;
@@ -87,7 +87,7 @@ static void _sunrise_sunset_face_update(movement_settings_t *settings, sunrise_s
watch_clear_colon(); watch_clear_colon();
watch_clear_indicator(WATCH_INDICATOR_PM); watch_clear_indicator(WATCH_INDICATOR_PM);
watch_clear_indicator(WATCH_INDICATOR_24H); watch_clear_indicator(WATCH_INDICATOR_24H);
sprintf(buf, "%s%2d none ", (result == 1) ? "SE" : "rI", scratch_time.unit.day); snprintf(buf, sizeof(buf), "%s%2d none ", (result == 1) ? "SE" : "rI", scratch_time.unit.day);
watch_display_string(buf, 0); watch_display_string(buf, 0);
return; return;
} }
@@ -120,7 +120,7 @@ static void _sunrise_sunset_face_update(movement_settings_t *settings, sunrise_s
} else if (settings->bit.clock_24h_leading_zero && scratch_time.unit.hour < 10) { } else if (settings->bit.clock_24h_leading_zero && scratch_time.unit.hour < 10) {
set_leading_zero = true; set_leading_zero = true;
} }
sprintf(buf, "rI%2d%2d%02d%s", scratch_time.unit.day, scratch_time.unit.hour, scratch_time.unit.minute,longLatPresets[state->longLatToUse].name); snprintf(buf, sizeof(buf), "rI%2d%2d%02d%s", scratch_time.unit.day, scratch_time.unit.hour, scratch_time.unit.minute,longLatPresets[state->longLatToUse].name);
watch_display_string(buf, 0); watch_display_string(buf, 0);
if (set_leading_zero) if (set_leading_zero)
watch_display_string("0", 4); watch_display_string("0", 4);
@@ -152,7 +152,7 @@ static void _sunrise_sunset_face_update(movement_settings_t *settings, sunrise_s
} else if (settings->bit.clock_24h_leading_zero && scratch_time.unit.hour < 10) { } else if (settings->bit.clock_24h_leading_zero && scratch_time.unit.hour < 10) {
set_leading_zero = true; set_leading_zero = true;
} }
sprintf(buf, "SE%2d%2d%02d%s", scratch_time.unit.day, scratch_time.unit.hour, scratch_time.unit.minute, longLatPresets[state->longLatToUse].name); snprintf(buf, sizeof(buf), "SE%2d%2d%02d%s", scratch_time.unit.day, scratch_time.unit.hour, scratch_time.unit.minute, longLatPresets[state->longLatToUse].name);
watch_display_string(buf, 0); watch_display_string(buf, 0);
if (set_leading_zero) if (set_leading_zero)
watch_display_string("0", 4); watch_display_string("0", 4);
@@ -212,16 +212,16 @@ static void _sunrise_sunset_face_update_location_register(sunrise_sunset_state_t
} }
static void _sunrise_sunset_face_update_settings_display(movement_event_t event, sunrise_sunset_state_t *state) { static void _sunrise_sunset_face_update_settings_display(movement_event_t event, sunrise_sunset_state_t *state) {
char buf[12]; char buf[11];
switch (state->page) { switch (state->page) {
case 0: case 0:
return; return;
case 1: case 1:
sprintf(buf, "LA %c %04d", state->working_latitude.sign ? '-' : '+', abs(_sunrise_sunset_face_latlon_from_struct(state->working_latitude))); snprintf(buf, sizeof(buf), "LA %c %04d", state->working_latitude.sign ? '-' : '+', abs(_sunrise_sunset_face_latlon_from_struct(state->working_latitude)));
break; break;
case 2: case 2:
sprintf(buf, "LO %c%05d", state->working_longitude.sign ? '-' : '+', abs(_sunrise_sunset_face_latlon_from_struct(state->working_longitude))); snprintf(buf, sizeof(buf), "LO %c%05d", state->working_longitude.sign ? '-' : '+', abs(_sunrise_sunset_face_latlon_from_struct(state->working_longitude)));
break; break;
} }
if (event.subsecond % 2) { if (event.subsecond % 2) {

View File

@@ -60,10 +60,6 @@ bool preferences_face_loop(movement_event_t event, movement_settings_t *settings
case EVENT_ACTIVATE: case EVENT_ACTIVATE:
// Do nothing; handled below. // Do nothing; handled below.
break; break;
case EVENT_MODE_BUTTON_UP:
watch_set_led_off();
movement_move_to_next_face();
return false;
case EVENT_LIGHT_BUTTON_DOWN: case EVENT_LIGHT_BUTTON_DOWN:
current_page = (current_page + 1) % PREFERENCES_FACE_NUM_PREFERENCES; current_page = (current_page + 1) % PREFERENCES_FACE_NUM_PREFERENCES;
*((uint8_t *)context) = current_page; *((uint8_t *)context) = current_page;
@@ -202,7 +198,6 @@ bool preferences_face_loop(movement_event_t event, movement_settings_t *settings
return false; return false;
} }
watch_set_led_off();
return true; return true;
} }

View File

@@ -183,6 +183,5 @@ bool set_time_face_loop(movement_event_t event, movement_settings_t *settings, v
void set_time_face_resign(movement_settings_t *settings, void *context) { void set_time_face_resign(movement_settings_t *settings, void *context) {
(void) settings; (void) settings;
(void) context; (void) context;
watch_set_led_off();
watch_store_backup_data(settings->reg, 0); watch_store_backup_data(settings->reg, 0);
} }

View File

@@ -97,6 +97,16 @@ void watch_enable_analog_input(const uint8_t pin) {
case A4: case A4:
gpio_set_pin_function(pin, PINMUX_PB00B_ADC_AIN8); gpio_set_pin_function(pin, PINMUX_PB00B_ADC_AIN8);
break; break;
#ifdef TEMPSENSE
case TEMPSENSE:
gpio_set_pin_function(pin, PINMUX_PA03B_ADC_AIN1);
break;
#endif
#ifdef IRSENSE
case IRSENSE:
gpio_set_pin_function(pin, PINMUX_PA04B_ADC_AIN4);
break;
#endif
default: default:
return; return;
} }
@@ -114,7 +124,15 @@ uint16_t watch_get_analog_pin_level(const uint8_t pin) {
return _watch_get_analog_value(ADC_INPUTCTRL_MUXPOS_AIN11_Val); return _watch_get_analog_value(ADC_INPUTCTRL_MUXPOS_AIN11_Val);
case A4: case A4:
return _watch_get_analog_value(ADC_INPUTCTRL_MUXPOS_AIN8_Val); return _watch_get_analog_value(ADC_INPUTCTRL_MUXPOS_AIN8_Val);
default: #ifdef TEMPSENSE
case TEMPSENSE:
return _watch_get_analog_value(ADC_INPUTCTRL_MUXPOS_AIN1_Val);
#endif
#ifdef IRSENSE
case IRSENSE:
return _watch_get_analog_value(ADC_INPUTCTRL_MUXPOS_AIN4_Val);
#endif
default:
return 0; return 0;
} }
} }

View File

@@ -26,7 +26,7 @@
#include "watch_utility.h" #include "watch_utility.h"
const char * watch_utility_get_weekday(watch_date_time date_time) { const char * watch_utility_get_weekday(watch_date_time date_time) {
static const char weekdays[7][3] = {"MO", "TU", "WE", "TH", "FR", "SA", "SU"}; static const char weekdays[7][3] = {"LU", "MA", "MI", "JU", "VI", "SA", "do"};
return weekdays[watch_utility_get_iso8601_weekday_number(date_time.unit.year + WATCH_RTC_REFERENCE_YEAR, date_time.unit.month, date_time.unit.day) - 1]; return weekdays[watch_utility_get_iso8601_weekday_number(date_time.unit.year + WATCH_RTC_REFERENCE_YEAR, date_time.unit.month, date_time.unit.day) - 1];
} }