diff options
author | Benji Dial <benji@benjidial.net> | 2024-07-31 13:36:53 -0400 |
---|---|---|
committer | Benji Dial <benji@benjidial.net> | 2024-07-31 13:36:53 -0400 |
commit | b1cf9e5dfbc8967bd7cb2a22ec1e5e521f4e0e6e (patch) | |
tree | 00837891f9b9bf232e540a6f9b3e16f2438865c3 /applications | |
parent | 86b343f17175ef3e1fad2197636f75770466aa7c (diff) | |
download | hilbert-os-b1cf9e5dfbc8967bd7cb2a22ec1e5e521f4e0e6e.tar.gz |
add clock
Diffstat (limited to 'applications')
-rw-r--r-- | applications/clock/makefile | 12 | ||||
-rw-r--r-- | applications/clock/source/main.cpp | 63 | ||||
-rw-r--r-- | applications/init/source/main.cpp | 2 |
3 files changed, 76 insertions, 1 deletions
diff --git a/applications/clock/makefile b/applications/clock/makefile new file mode 100644 index 0000000..949e6ce --- /dev/null +++ b/applications/clock/makefile @@ -0,0 +1,12 @@ +SOURCES = \ + main.cpp + +build/%.cpp.o: source/%.cpp + @mkdir -p $(@D) + $(HILBERT_CC) -c $^ -o $@ + +build/clock.elf: $(SOURCES:%=build/%.o) + $(HILBERT_CC) $^ -ldaguerre -lpake -o $@ + +clean: + rm -rf build diff --git a/applications/clock/source/main.cpp b/applications/clock/source/main.cpp new file mode 100644 index 0000000..3a1270d --- /dev/null +++ b/applications/clock/source/main.cpp @@ -0,0 +1,63 @@ +#include <pake/widgets/fixed-text.hpp> +#include <daguerre/psf.hpp> +#include <pake/window.hpp> +#include <ctime> + +static daguerre::fixed_font<bool> *font; + +std::string the_time() { + + time_t t = time(0); + + //convert to edt - TODO: timezones in euler + t -= 4 * 3600 * 1024; + + tm *gt = gmtime(&t); + + int hour = (gt->tm_hour - 1) % 12 + 1; + int min = gt->tm_min; + int sec = gt->tm_sec; + bool pm = gt->tm_hour >= 12; + + std::string s; + s.resize(8); + + s[0] = hour / 10 + '0'; s[1] = hour % 10 + '0'; + s[3] = min / 10 + '0'; s[4] = min % 10 + '0'; + + s[2] = sec % 2 == 0 ? ':' : ' '; + + s[5] = ' '; + s[6] = pm ? 'p' : 'a'; + s[7] = 'm'; + + if (s[0] == '0') + s.erase(0, 1); + + return s; + +} + +int main(int, char **) { + + font = new daguerre::fixed_font<bool>( + daguerre::try_load_psf("/assets/terminus/10x18-bold.psf").value()); + + pake::widgets::fixed_text *text = + new pake::widgets::fixed_text(the_time(), font, + euler::syscall::encode_color(0xaa, 0xaa, 0xaa), + euler::syscall::encode_color(0x00, 0x00, 0x00), + pake::halign::center, pake::valign::center); + + pake::window w(90, 28, "Clock"); + w.set_root(std::unique_ptr<pake::widget>(text)); + w.render_and_send_to_compositor(); + w.show(); + + while (1) { + euler::syscall::sleep(512); + text->set_text(the_time()); + w.render_and_send_to_compositor(); + } + +} diff --git a/applications/init/source/main.cpp b/applications/init/source/main.cpp index ca137a4..c281bc0 100644 --- a/applications/init/source/main.cpp +++ b/applications/init/source/main.cpp @@ -6,6 +6,6 @@ int main(int, char **) { euler::syscall::process_handle dummy; euler::syscall::start_process("/bin/compositor", {}, {}, dummy); - euler::syscall::start_process("/bin/hello", {}, {}, dummy); + euler::syscall::start_process("/bin/clock", {}, {}, dummy); return 0; } |