2021-09-08 22:16:40 +02:00
|
|
|
#include <gint/cpu.h>
|
2021-09-02 19:07:14 +02:00
|
|
|
#include <gint/display.h>
|
2021-09-02 19:41:13 +02:00
|
|
|
#include <gint/drivers/r61524.h>
|
2021-09-01 18:25:59 +02:00
|
|
|
#include <gint/gint.h>
|
2021-08-31 15:52:53 +02:00
|
|
|
#include <gint/keyboard.h>
|
2021-09-08 22:16:40 +02:00
|
|
|
#include <gint/mpu/power.h>
|
2021-08-31 15:52:53 +02:00
|
|
|
#include <gint/timer.h>
|
|
|
|
|
2021-09-02 19:07:14 +02:00
|
|
|
#include "battery.h"
|
2021-08-31 15:52:53 +02:00
|
|
|
#include "term.h"
|
2021-09-01 11:04:31 +02:00
|
|
|
#include "ui.h"
|
2021-08-31 15:52:53 +02:00
|
|
|
|
2021-09-02 19:07:14 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2021-09-08 22:16:40 +02:00
|
|
|
#include "fe/fe.h"
|
|
|
|
|
2021-08-31 15:52:53 +02:00
|
|
|
static char *LOREM_IPSUM =
|
2021-09-01 13:33:21 +02:00
|
|
|
"Lorem ipsum dolor sit amet, consectetur adipiscing elit.\nNam vitae purus dolor.\nPraesent in ex tempus, auctor velit at, "
|
|
|
|
"vulputate sapien.\nAenean semper, dui vitae iaculis mattis, odio libero aliquet elit, nec tempor nisl turpis vel arcu.\n"
|
|
|
|
"Vestibulum eleifend maximus enim at sollicitudin.\nNulla eu commodo justo.\nUt vitae pellentesque erat.\nDuis magna nisl, "
|
2021-09-02 19:07:14 +02:00
|
|
|
"eleifend ac massa at, blandit sollicitudin ipsum.\nIntegint_world_swrdum et malesuada fames ac ante ipsum primis in "
|
|
|
|
"faucibus.\n"
|
2021-09-01 13:33:21 +02:00
|
|
|
"Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.\nUt at libero in turpis porttitor "
|
|
|
|
"viverra.\nUt eu pellentesque purus.\nVestibulum aliquet facilisis ante, eget volutpat metus.\nCras semper lacus ac mauris "
|
|
|
|
"imperdiet, vel egestas est luctus.\nAliquam elit enim, dignissim nec enim vel, consequat ullamcorper libero.\nPellentesque "
|
|
|
|
"at "
|
|
|
|
"iaculis lctus.\nPraesent sed velit at tellus hendrerit mattis eu nec velit.\nPhasellus eu quam nec nisi mattis elementum "
|
|
|
|
"quis "
|
|
|
|
"nec enim.\nNulla efficitur turpis id tempus ultricies.\nPellentesque semper lacinia mi vitae feugiat.\nVestibulum leo nisi, "
|
|
|
|
"pretium quis felis non, mattis varius risus.\n"
|
|
|
|
"Suspendisse porttitor purus lacinia ante euismod, ut eleifend massa fermentum.\nProin pretium elementum massa, at efficitur "
|
2021-09-08 19:18:09 +02:00
|
|
|
"risus iaculis sed.\n";
|
2021-08-31 15:52:53 +02:00
|
|
|
|
|
|
|
static volatile int key_poll_timeout;
|
|
|
|
static int callback_keypoll(void) {
|
|
|
|
key_poll_timeout = 0;
|
|
|
|
return TIMER_STOP;
|
|
|
|
}
|
|
|
|
|
2021-09-08 19:22:36 +02:00
|
|
|
static char *feprgm = "(myfn)";
|
|
|
|
static char customfereadfn(fe_Context *ctx, void *udata) {
|
|
|
|
static int i = 0;
|
|
|
|
char c = feprgm[i];
|
|
|
|
|
|
|
|
if (c != '\0')
|
|
|
|
i++;
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int alive = 0;
|
|
|
|
static fe_Object *fefn(fe_Context *ctx, fe_Object *arg) {
|
|
|
|
alive++;
|
|
|
|
return fe_number(ctx, 1);
|
|
|
|
}
|
2021-09-02 19:41:13 +02:00
|
|
|
|
2021-09-08 22:15:46 +02:00
|
|
|
int main(int isappli, int optnum) {
|
2021-09-08 19:22:36 +02:00
|
|
|
char febuf[128 * 1024];
|
|
|
|
void *femem = (void *)febuf;
|
|
|
|
fe_Context *fectx = fe_open(femem, sizeof(febuf));
|
|
|
|
fe_set(fectx, fe_symbol(fectx, "myfn"), fe_cfunc(fectx, fefn));
|
|
|
|
int fegc = fe_savegc(fectx);
|
|
|
|
while (1) {
|
|
|
|
fe_Object *feobj = fe_read(fectx, customfereadfn, femem);
|
|
|
|
if (!feobj)
|
|
|
|
break;
|
|
|
|
|
|
|
|
fe_eval(fectx, feobj);
|
|
|
|
|
|
|
|
fe_restoregc(fectx, fegc);
|
|
|
|
}
|
|
|
|
// fe_close(fectx);
|
|
|
|
|
2021-09-01 11:04:31 +02:00
|
|
|
int tick_ctr = 0;
|
2021-09-01 13:33:34 +02:00
|
|
|
int shift_state = 0;
|
2021-09-01 18:08:43 +02:00
|
|
|
int alpha_state = 0;
|
2021-09-02 19:07:14 +02:00
|
|
|
int off_state = 0;
|
2021-09-02 19:41:13 +02:00
|
|
|
uint16_t backlight_save;
|
2021-08-31 15:52:53 +02:00
|
|
|
|
2021-09-09 22:09:33 +02:00
|
|
|
term_print(LOREM_IPSUM);
|
|
|
|
term_print("-----------------------------------------------------------------");
|
2021-09-08 22:16:40 +02:00
|
|
|
term_printf("isappli=%d optnum=%d\n", isappli, optnum);
|
|
|
|
|
2021-09-02 19:07:14 +02:00
|
|
|
set_statusbar(tick_ctr, shift_state, alpha_state, get_battery_voltage());
|
2021-09-01 14:28:01 +02:00
|
|
|
set_menubar();
|
|
|
|
tgrid_display();
|
2021-09-01 14:24:10 +02:00
|
|
|
|
2021-08-31 15:52:53 +02:00
|
|
|
while (1) {
|
2021-09-02 19:07:14 +02:00
|
|
|
const int timer = timer_configure(TIMER_ANY, 20000, GINT_CALL(callback_keypoll));
|
2021-08-31 15:52:53 +02:00
|
|
|
key_poll_timeout = 1;
|
2021-09-01 18:25:59 +02:00
|
|
|
key_event_t kev = getkey_opt(GETKEY_NONE, &key_poll_timeout);
|
2021-08-31 17:22:45 +02:00
|
|
|
timer_start(timer);
|
2021-09-02 19:07:14 +02:00
|
|
|
|
2021-09-01 18:08:43 +02:00
|
|
|
if (kev.type == KEYEV_DOWN) {
|
2021-09-02 19:07:14 +02:00
|
|
|
if (off_state) {
|
|
|
|
if (kev.key == KEY_ACON) {
|
|
|
|
off_state = 0;
|
2021-09-02 19:41:13 +02:00
|
|
|
|
|
|
|
// reset backlight
|
|
|
|
r61524_set(0x5a1, backlight_save & 0x00ff);
|
2021-09-02 19:07:14 +02:00
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-01 18:08:43 +02:00
|
|
|
if (kev.key == KEY_SHIFT)
|
|
|
|
shift_state = !shift_state;
|
|
|
|
|
|
|
|
if (kev.key == KEY_ALPHA)
|
|
|
|
alpha_state = !alpha_state;
|
|
|
|
|
2021-09-02 19:07:14 +02:00
|
|
|
if (kev.key == KEY_ACON && shift_state) {
|
|
|
|
off_state = 1;
|
|
|
|
|
2021-09-08 19:18:09 +02:00
|
|
|
// save, then turn backlight level off:
|
|
|
|
// force to display something
|
|
|
|
dclear(C_WHITE);
|
|
|
|
dupdate();
|
|
|
|
// store the backlight pwm
|
2021-09-02 19:41:13 +02:00
|
|
|
backlight_save = r61524_get(0x5a1) & 0x00ff;
|
2021-09-08 19:18:09 +02:00
|
|
|
// force vram clear
|
2021-09-03 16:19:29 +02:00
|
|
|
dclear(C_BLACK);
|
|
|
|
dupdate();
|
2021-09-08 19:18:09 +02:00
|
|
|
dclear(C_BLACK);
|
|
|
|
dupdate();
|
|
|
|
// force backlight pwm to 0
|
|
|
|
r61524_set(0x5a1, 0);
|
2021-09-03 16:19:29 +02:00
|
|
|
|
2021-09-02 19:07:14 +02:00
|
|
|
shift_state = 0;
|
|
|
|
alpha_state = 0;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-09-01 18:25:59 +02:00
|
|
|
if (kev.key == KEY_MENU && !shift_state && !alpha_state) {
|
|
|
|
// TODO: print pause menu
|
|
|
|
gint_osmenu();
|
|
|
|
}
|
|
|
|
|
2021-09-08 22:16:40 +02:00
|
|
|
if (kev.key == KEY_MENU && shift_state && !alpha_state) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
term_printf("tick_ctr=%d key=0x%x mod=%d shift=%d alpha=%d\n", tick_ctr, kev.key, kev.mod, kev.shift, kev.alpha);
|
2021-09-02 19:04:01 +02:00
|
|
|
|
|
|
|
set_statusbar(tick_ctr, shift_state, alpha_state, get_battery_voltage());
|
2021-09-01 14:28:01 +02:00
|
|
|
set_menubar();
|
2021-09-02 19:04:01 +02:00
|
|
|
|
2021-09-01 14:28:01 +02:00
|
|
|
tgrid_display();
|
2021-09-01 14:24:10 +02:00
|
|
|
|
2021-08-31 15:52:53 +02:00
|
|
|
tick_ctr++;
|
2021-09-01 14:24:10 +02:00
|
|
|
}
|
2021-08-31 15:52:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|