blob: 58b497d3003869a95c898ca7142fbc2d8f1348fa [file] [log] [blame]
Adrien Destugues69b1f062017-06-05 13:44:30 +02001/*
2 * Copyright 2017, Adrien Destugues, pulkomandy@pulkomandy.tk
3 * Distributed under terms of the MIT license.
4 */
5
6// Contiki includes
7#include "ctk.h"
8#include "program-handler.h"
9
10#include "clock-conf.h"
Adrien Destugues613f8592017-06-05 20:19:46 +020011#include "cfs-fatfs.h"
Adrien Destugues69b1f062017-06-05 13:44:30 +020012
13// Applications
14#include "netconf-dsc.h"
15#include "dhcp-dsc.h"
16#include "www-dsc.h"
17#include "webserver-dsc.h"
18#include "ftp-dsc.h"
19#include "telnet-dsc.h"
20#include "email-dsc.h"
21#include "irc-dsc.h"
22#include "editor-dsc.h"
23#include "calc-dsc.h"
24#include "processes-dsc.h"
25#include "shell-dsc.h"
26#include "about-dsc.h"
27
28// Bitbox includes
29#include "lib/textmode/textmode.h"
30
31void conio_init(void)
32{
33 // Clear display and set a visible palette (default is black on black)
34 clear();
35
Adrien Destugues613f8592017-06-05 20:19:46 +020036 // Make sure unused color are black on black
Adrien Destugues69b1f062017-06-05 13:44:30 +020037 for (int i = 0; i < 256; i++)
38 set_palette(i, 0, 0);
39
Adrien Destugues613f8592017-06-05 20:19:46 +020040 // Set up an ad hoc palette just so it looks good. Later on we can maybe
41 // add this to the settings application?
42 set_palette(0, RGB(0, 0, 0), RGB(0, 0, 0)); // border (ok, unused?)
Adrien Destugues69b1f062017-06-05 13:44:30 +020043 set_palette(1, RGB(0, 0, 0), RGB(146, 146, 255)); // screen (ok)
44 set_palette(3, RGB(0, 0, 0), RGB(128, 128, 128)); // open menu (ok)
45 set_palette(4, RGB(0, 0, 0), RGB(255, 128, 128)); // active menu item (ok)
Adrien Destugues613f8592017-06-05 20:19:46 +020046 set_palette(5, RGB(0, 0, 0), RGB(240,240,240)); // dialogs (ok)
47 set_palette(6, RGB(100,100,255), RGB(255,128,128)); // highlighted hyperlinks (ok)
48 set_palette(7, RGB(0,0,64), RGB(192,192,255)); // moving window (ok)
Adrien Destugues69b1f062017-06-05 13:44:30 +020049 set_palette(8, RGB(64,64,64), RGB(192,192,192)); // inactive window/widgets
50
51 set_palette(2+16, RGB(0, 0, 0), RGB(255, 255, 255)); // menu (ok)
Adrien Destugues613f8592017-06-05 20:19:46 +020052 set_palette(6+16, RGB(0, 0, 255), RGB(240,240,240)); // hyperlinks (ok)
53 set_palette(7+16, RGB(0,0,0), RGB(255,128,128)); // focus widget
Adrien Destugues69b1f062017-06-05 13:44:30 +020054
55}
56
Adrien Destugues613f8592017-06-05 20:19:46 +020057
58// Use the vga_frame counter as a main clock. It would be nice to have a
59// millisecond-precision (or more) clock, but this will do for now.
Adrien Destugues69b1f062017-06-05 13:44:30 +020060clock_time_t clock_time(void)
61{
62 return vga_frame;
63}
64
Adrien Destugues613f8592017-06-05 20:19:46 +020065
66// For debugging purposes only. Actually I didn't see it being called yet.
Adrien Destugues69b1f062017-06-05 13:44:30 +020067void
68log_message(const char *part1, const char *part2)
69{
70 printf("%s%s\n", part1, part2);
71}
72
73void bitbox_main(void)
74{
75 ek_init();
76 conio_init();
77 ctk_init();
Adrien Destugues613f8592017-06-05 20:19:46 +020078 cfs_fatfs_init(NULL);
Adrien Destugues69b1f062017-06-05 13:44:30 +020079 program_handler_init();
80
81#if 0
82 program_handler_add(&netconf_dsc, "Network setup", 1);
83 program_handler_add(&dhcp_dsc, "DHCP client", 1);
84 program_handler_add(&www_dsc, "Web browser", 1);
85 program_handler_add(&webserver_dsc, "Web server", 1);
86 program_handler_add(&ftp_dsc, "FTP client", 1);
87 program_handler_add(&telnet_dsc, "Telnet", 1);
88 program_handler_add(&email_dsc, "E-mail", 1);
89 program_handler_add(&irc_dsc, "IRC client", 1);
90#endif
91 program_handler_add(&editor_dsc, "Editor", 1);
92 program_handler_add(&calc_dsc, "Calculator", 1);
93 program_handler_add(&processes_dsc, "Processes", 1);
Adrien Destugues7987cb22017-06-05 14:01:01 +020094 program_handler_add(&shell_dsc, "Command shell", 1);
Adrien Destugues69b1f062017-06-05 13:44:30 +020095 program_handler_add(&about_dsc, "About Contiki", 0);
96
97 // Call ek_run until everything is initialized. Then, load welcome.prg.
98 while(1) {
99 if(ek_run() == 0) {
100 //program_handler_load("welcome.prg", NULL);
101 //TODO we don't have a loader; so call the init func directly
102 break;
103 }
104 }
105 // Run the main loop.
106 while(1) {
107 if (ek_run() == 0) {
108 // We are out of events to run, sleep a little.
109 wait_vsync(1);
110 }
111 }
112}