diff options
author | Joey Castillo <jose.castillo@gmail.com> | 2021-05-06 19:37:02 -0400 |
---|---|---|
committer | Joey Castillo <jose.castillo@gmail.com> | 2021-05-06 19:37:08 -0400 |
commit | 7ff91a2f678a5eb1f6b985a257a8e59bde6a973f (patch) | |
tree | 7dce8870b8b2ced4ffc57c19191f9a85780247f0 | |
parent | 471bdc60c0d38459702888c722a10f2ed1a8379b (diff) | |
download | Sensor-Watch-7ff91a2f678a5eb1f6b985a257a8e59bde6a973f.tar.gz Sensor-Watch-7ff91a2f678a5eb1f6b985a257a8e59bde6a973f.tar.bz2 Sensor-Watch-7ff91a2f678a5eb1f6b985a257a8e59bde6a973f.zip |
mars clock!
-rw-r--r-- | Smol Watch Project/My Project/.atmelstart/atmel_start_config.atstart | 10 | ||||
-rw-r--r-- | Smol Watch Project/My Project/Config/hpl_rtc_config.h | 2 | ||||
-rw-r--r-- | Smol Watch Project/My Project/My Project.cproj | 3 | ||||
-rw-r--r-- | Smol Watch Project/My Project/main.c | 26 | ||||
-rw-r--r-- | Smol Watch Project/My Project/mars_clock.c | 75 | ||||
-rw-r--r-- | Smol Watch Project/My Project/mars_clock.h | 2 |
6 files changed, 93 insertions, 25 deletions
diff --git a/Smol Watch Project/My Project/.atmelstart/atmel_start_config.atstart b/Smol Watch Project/My Project/.atmelstart/atmel_start_config.atstart index 0c082b91..741d4079 100644 --- a/Smol Watch Project/My Project/.atmelstart/atmel_start_config.atstart +++ b/Smol Watch Project/My Project/.atmelstart/atmel_start_config.atstart @@ -517,10 +517,10 @@ drivers: functionality: System api: HAL:HPL:GCLK configuration: - $input: 400000 - $input_id: External Crystal Oscillator 0.4-32MHz (XOSC) - RESERVED_InputFreq: 400000 - RESERVED_InputFreq_id: External Crystal Oscillator 0.4-32MHz (XOSC) + $input: 32768 + $input_id: 32kHz External Crystal Oscillator (XOSC32K) + RESERVED_InputFreq: 32768 + RESERVED_InputFreq_id: 32kHz External Crystal Oscillator (XOSC32K) _$freq_output_Generic clock generator 0: 4000000 _$freq_output_Generic clock generator 1: 400000 _$freq_output_Generic clock generator 2: 400000 @@ -762,7 +762,7 @@ drivers: functionality: Calendar api: HAL:Driver:Calendar configuration: - rtc_arch_init_reset: true + rtc_arch_init_reset: false rtc_arch_prescaler: Peripheral clock divided by 1024 rtc_cmpeo0: false rtc_event_control: false diff --git a/Smol Watch Project/My Project/Config/hpl_rtc_config.h b/Smol Watch Project/My Project/Config/hpl_rtc_config.h index 174f77a9..9085ca37 100644 --- a/Smol Watch Project/My Project/Config/hpl_rtc_config.h +++ b/Smol Watch Project/My Project/Config/hpl_rtc_config.h @@ -15,7 +15,7 @@ // <i> Note that the previous power down data in RTC is lost if it's enabled. // <id> rtc_arch_init_reset #ifndef CONF_RTC_INIT_RESET -#define CONF_RTC_INIT_RESET 1 +#define CONF_RTC_INIT_RESET 0 #endif // <o> Prescaler configuration diff --git a/Smol Watch Project/My Project/My Project.cproj b/Smol Watch Project/My Project/My Project.cproj index ac2e0cd8..af621b7b 100644 --- a/Smol Watch Project/My Project/My Project.cproj +++ b/Smol Watch Project/My Project/My Project.cproj @@ -200,7 +200,7 @@ <AcmeProjectActionInfo Action="File" Source="config/hpl_osc32kctrl_config.h" IsConfig="true" Hash="LayjFcrIUjhOQ+E6G5sHRA" />
<AcmeProjectActionInfo Action="File" Source="config/hpl_oscctrl_config.h" IsConfig="true" Hash="Vc5u27WzT+UPF5aLAxl2lQ" />
<AcmeProjectActionInfo Action="File" Source="config/hpl_port_config.h" IsConfig="true" Hash="rMTNR+5FXtu+wfT1NbfRRA" />
- <AcmeProjectActionInfo Action="File" Source="config/hpl_rtc_config.h" IsConfig="true" Hash="oTcobT9ydLDOqfpwUidHvg" />
+ <AcmeProjectActionInfo Action="File" Source="config/hpl_rtc_config.h" IsConfig="true" Hash="w/iGOvqHWjII6brxzrQCIg" />
<AcmeProjectActionInfo Action="File" Source="config/hpl_sercom_config.h" IsConfig="true" Hash="x/EmsaDJwEm2EI8zXUSlWw" />
<AcmeProjectActionInfo Action="File" Source="config/hpl_slcd_config.h" IsConfig="true" Hash="dUpqyZg3KRMbt3sjYhNt1Q" />
<AcmeProjectActionInfo Action="File" Source="config/hpl_systick_config.h" IsConfig="true" Hash="tlT3lNDKWFe82MiGWfQzcA" />
@@ -409,7 +409,6 @@ <Value>%24(PackRepoDir)\atmel\SAML22_DFP\1.2.77\include</Value>
</ListValues>
</armgcc.compiler.directories.IncludePaths>
- <armgcc.compiler.optimization.level>Optimize debugging experience (-Og)</armgcc.compiler.optimization.level>
<armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>True</armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>
<armgcc.compiler.optimization.DebugLevel>Maximum (-g3)</armgcc.compiler.optimization.DebugLevel>
<armgcc.compiler.warnings.AllWarnings>True</armgcc.compiler.warnings.AllWarnings>
diff --git a/Smol Watch Project/My Project/main.c b/Smol Watch Project/My Project/main.c index 3af1ed07..b803fb6d 100644 --- a/Smol Watch Project/My Project/main.c +++ b/Smol Watch Project/My Project/main.c @@ -4,38 +4,38 @@ #include "mars_clock.h" Watch watch; -bool locked = true; +bool local = true; void calendar_callback(struct calendar_descriptor *const calendar) { } static void mode_callback() { - locked = !locked; - gpio_set_pin_level(GREEN, !locked); + local = !local; + struct calendar_date_time date_time; + calendar_get_date_time(&CALENDAR_0, &date_time); + update_display(&watch, date_time, local); } static void light_callback() { - if (locked) return; struct calendar_date_time date_time; calendar_get_date_time(&CALENDAR_0, &date_time); date_time.time.min = (date_time.time.min + 1) % 60; watch_set_date_time(date_time); - update_display(&watch, date_time); + update_display(&watch, date_time, local); } static void alarm_callback() { - if (locked) return; struct calendar_date_time date_time; calendar_get_date_time(&CALENDAR_0, &date_time); date_time.time.sec = 0; watch_set_date_time(date_time); - update_display(&watch, date_time); + update_display(&watch, date_time, local); } static void tick_callback() { struct calendar_date_time date_time; calendar_get_date_time(&CALENDAR_0, &date_time); - update_display(&watch, date_time); + update_display(&watch, date_time, local); } int main(void) @@ -61,11 +61,11 @@ int main(void) watch_enable_date_time(&watch); struct calendar_date_time date_time; - date_time.date.year = 1; // reference year is 2020, add this to that. + date_time.date.year = 2021; date_time.date.month = 5; - date_time.date.day = 2; - date_time.time.hour = 7; - date_time.time.min = 15; + date_time.date.day = 6; + date_time.time.hour = 23; + date_time.time.min = 30; date_time.time.sec = 0; watch_set_date_time(date_time); /* struct calendar_alarm alarm; @@ -76,7 +76,7 @@ int main(void) alarm.callback = calendar_callback; calendar_set_alarm(&CALENDAR_0, &alarm, &calendar_callback); */ - update_display(&watch, date_time); + update_display(&watch, date_time, local); watch_enable_tick(tick_callback); while (1) { diff --git a/Smol Watch Project/My Project/mars_clock.c b/Smol Watch Project/My Project/mars_clock.c index 82a47d08..53ce3362 100644 --- a/Smol Watch Project/My Project/mars_clock.c +++ b/Smol Watch Project/My Project/mars_clock.c @@ -8,10 +8,79 @@ #include <math.h>
#include "mars_clock.h"
-// note: mars time not working, committing just the earth clock.
+static unsigned short days[4][12] =
+{
+ { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335},
+ { 366, 397, 425, 456, 486, 517, 547, 578, 609, 639, 670, 700},
+ { 731, 762, 790, 821, 851, 882, 912, 943, 974,1004,1035,1065},
+ {1096,1127,1155,1186,1216,1247,1277,1308,1339,1369,1400,1430},
+};
-void update_display(Watch *watch, struct calendar_date_time date_time) { +unsigned int date_time_to_epoch(struct calendar_date_time date_time)
+{
+ unsigned int second = date_time.time.sec;
+ unsigned int minute = date_time.time.min;
+ unsigned int hour = date_time.time.hour;
+ unsigned int day = date_time.date.day-1; // 0-30
+ unsigned int month = date_time.date.month-1; // 0-11
+ unsigned int year = date_time.date.year - 1970; // 0-99
+ return (((year/4*(365*4+1)+days[year%4][month]+day)*24+hour)*60+minute)*60+second;
+}
+
+void epoch_to_date_time(struct calendar_date_time date_time, unsigned int epoch)
+{
+ date_time.time.sec = epoch % 60;
+ epoch /= 60;
+ date_time.time.min = epoch % 60;
+ epoch /= 60;
+ date_time.time.hour = epoch % 24;
+ epoch /= 24;
+
+ unsigned int years = epoch/(365*4+1)*4;
+ epoch %= 365*4+1;
+
+ unsigned int year;
+ for (year=3; year>0; year--)
+ {
+ if (epoch >= days[year][0])
+ break;
+ }
+
+ unsigned int month;
+ for (month=11; month>0; month--)
+ {
+ if (epoch >= days[year][month])
+ break;
+ }
+
+ date_time.date.year = years+year;
+ date_time.date.month = month+1;
+ date_time.date.day = epoch-days[year][month]+1;
+}
+
+void h_to_hms(struct calendar_date_time *date_time, double h) {
+ unsigned int seconds = (unsigned int)(h * 3600.0);
+ date_time->time.hour = seconds / 3600;
+ seconds = seconds % 3600;
+ date_time->time.min = floor(seconds / 60);
+ date_time->time.sec = round(seconds % 60);
+}
+
+
+void update_display(Watch *watch, struct calendar_date_time date_time, bool local) { char buf[6]; - sprintf(&buf[0], "TE %02d%02d%02d", date_time.time.hour, date_time.time.min, date_time.time.sec); + if (local) { + sprintf(&buf[0], "TE %02d%02d%02d", date_time.time.hour, date_time.time.min, date_time.time.sec); + } else { + unsigned int now = date_time_to_epoch(date_time); + double jdut = 2440587.5 + ((double)now / 86400.0);
+ double jdtt = jdut + ((37.0 + 32.184) / 86400.0);
+ double jd2k = jdtt - 2451545.0;
+ double msd = ((jd2k - 4.5) / 1.0274912517) + 44796.0 - 0.0009626;
+ double mtc = fmod(24 * msd, 24);
+ struct calendar_date_time mars_time;
+ h_to_hms(&mars_time, mtc);
+ sprintf(&buf[0], "MA %02d%02d%02d", mars_time.time.hour, mars_time.time.min, mars_time.time.sec); + } watch_display_string(watch, buf, 0); } diff --git a/Smol Watch Project/My Project/mars_clock.h b/Smol Watch Project/My Project/mars_clock.h index dd0150e8..71b45f33 100644 --- a/Smol Watch Project/My Project/mars_clock.h +++ b/Smol Watch Project/My Project/mars_clock.h @@ -11,7 +11,7 @@ #include "hpl_calendar.h"
#include "watch-library/watch.h"
-void update_display(Watch *watch, struct calendar_date_time date_time);
+void update_display(Watch *watch, struct calendar_date_time date_time, bool local);
#endif /* MARS_CLOCK_H_ */
\ No newline at end of file |