Skip to content

Commit 7fb3324

Browse files
author
okay
committed
[kobo][remux] updates to support kobo
* fix event flood on kobo to use ABS_DISTANCE * remux works on kobo and support nickel (32bpp) and rmkit apps (16 bpp) * draw as modal on kobo * suspend/resume sickel watchdog when managing nickel * remux rotation shenanigans * suspend mode is only relevant to remarkable
1 parent d2079d1 commit 7fb3324

File tree

7 files changed

+170
-33
lines changed

7 files changed

+170
-33
lines changed

src/input_demo/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
EXE=input_demo
22
FILES=main.cpy
33
ASSET_DIR=assets/
4+
DRAFT=input_demo.draft
45

56
include ../actions.make

src/remux/apps.cpy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include "config.launcher.h"
22

3-
#ifdef REMARKABLE
3+
#ifndef DEV
44
#define BIN_DIR "/home/root/apps/"
5-
#define DOT_BIN_DIR "/home/root/.apps/"
5+
#define DOT_BIN_DIR "/opt/bin/apps/"
66
#define DRAFT_DIR "/etc/draft/"
77
#define OPT_DRAFT_DIR "/opt/etc/draft/"
88
#define CACHE_DIR "/home/root/.cache/remux"
@@ -135,6 +135,7 @@ class AppReader:
135135
if dont_add:
136136
continue
137137

138+
138139
base_str := string(base_s)
139140
name_str := base_str
140141
if ends_with(base_str, EXE_EXT):

src/remux/config.launcher.cpy

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ struct RMApp:
99

1010
bool always_show = false
1111
bool manage_power = true
12+
int bpp = 16
1213

1314
// this will contain a framebuffer snapshot if we have one
1415
char *snapshot = NULL
@@ -26,8 +27,35 @@ RMApp APP_XOCHITL = RMApp %{
2627
name : "Remarkable",
2728
always_show : true,
2829
manage_power : false,
30+
bpp: 16
2931
}
3032

33+
RMApp APP_NICKEL = RMApp %{
34+
bin : "nickel",
35+
which : "nickel",
36+
name : "Nickel",
37+
always_show : true,
38+
manage_power : false,
39+
bpp: 32
40+
}
41+
42+
RMApp APP_NONE = RMApp %{
43+
bin : "/usr/bin/false",
44+
which : "false",
45+
name : "",
46+
always_show : false,
47+
manage_power : false,
48+
}
49+
50+
#ifdef REMARKABLE
51+
RMApp APP_MAIN = APP_XOCHITL
52+
#elif KOBO
53+
RMApp APP_MAIN = APP_NICKEL
54+
#else
55+
RMApp APP_MAIN = APP_NONE
56+
#endif
57+
58+
3159
RMApp APP_KOREADER = RMApp %{
3260
bin:"/home/root/koreader/koreader.sh",
3361
which:"koreader.sh",
@@ -55,7 +83,7 @@ RMApp APP_EDIT = RMApp %{
5583

5684

5785
vector<RMApp> APPS = %{
58-
APP_XOCHITL
86+
APP_MAIN
5987
,APP_KOREADER
6088
,APP_FINGERTERM
6189
,APP_KEYWRITER

src/remux/launcher.cpy

Lines changed: 99 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@
1818
#include "../genie/gesture_parser.h"
1919
#include "config.h"
2020

21+
#ifdef REMARKABLE
22+
#define TOUCH_FLOOD_EVENT ABS_DISTANCE
23+
#define DRAW_APP_BEHIND_MODAL
24+
#define READ_XOCHITL_DATA
25+
#elif KOBO
26+
#define TOUCH_FLOOD_EVENT ABS_MT_DISTANCE
27+
#define DYNAMIC_BPP
28+
#define HAS_ROTATION
29+
#else
30+
#define TOUCH_FLOOD_EVENT ABS_DISTANCE
31+
#endif
32+
2133
TIMEOUT := 1
2234
// all time is in seconds
2335
MIN := 60
@@ -28,7 +40,7 @@ SHUTDOWN_THRESHOLD := HOURS * 10 // 10 hours
2840

2941
#include "apps.h"
3042

31-
DIALOG_WIDTH := 400
43+
DIALOG_WIDTH := 600
3244
DIALOG_HEIGHT := 800
3345

3446
LAST_ACTION := 0
@@ -38,16 +50,26 @@ MIN_DISPLAY_TIME := 500
3850

3951
string CURRENT_APP = "_"
4052
string NAO_BIN="/opt/bin/nao"
53+
vector<string> SICKEL = { "sickel" }
4154

4255
// start with Remarkable preloaded in the launch list
4356
// so we can switch back to it quickly
4457
deque<string> _launched = { "Remarkable", "_" }
4558

46-
59+
#ifdef HAS_ROTATION
4760
DEFAULT_LAUNCH_GESTURES := vector<string> %{
4861
"gesture=swipe; direction=up; zone=0 0 0.1 1",
4962
"gesture=swipe; direction=up; zone=0.9 0 1 1",
63+
"gesture=swipe; direction=down; zone=0 0 0.1 1",
64+
"gesture=swipe; direction=down; zone=0.9 0 1 1",
5065
}
66+
#else
67+
DEFAULT_LAUNCH_GESTURES := vector<string> %{
68+
"gesture=swipe; direction=up; zone=0 0 0.1 1",
69+
"gesture=swipe; direction=up; zone=0.9 0 1 1",
70+
}
71+
#endif
72+
5173

5274
USB_CHARGER_PATHS := %{
5375
"/sys/class/power_supply/max77818-charger/online",
@@ -66,6 +88,30 @@ class IApp:
6688
virtual void show_last_app() = 0;
6789

6890

91+
class Snapshot:
92+
public:
93+
int byte_size
94+
int bits_per_pixel
95+
int rotation
96+
int width, height
97+
char *fbmem
98+
99+
Snapshot(int w, h):
100+
fb := framebuffer::get()
101+
bits_per_pixel = fb->get_screen_depth()
102+
self.byte_size = w * h * bits_per_pixel / 8
103+
fbmem = (char*) malloc(w * h * bits_per_pixel / 8)
104+
memset(fbmem, WHITE, self.byte_size)
105+
106+
~Snapshot():
107+
if fbmem != NULL:
108+
free(fbmem)
109+
fbmem = NULL
110+
111+
void allocate():
112+
pass
113+
114+
69115
class NaoButton: public ui::Button:
70116
public:
71117
IApp *app
@@ -95,12 +141,11 @@ class StatusBar: public ui::Button:
95141

96142
class AppBackground: public ui::Widget:
97143
public:
98-
int byte_size
99144
bool snapped = false
100-
map<string, framebuffer::VirtualFB*> app_buffers;
145+
map<string, Snapshot*> app_buffers;
101146

102147
AppBackground(int x, y, w, h): ui::Widget(x, y, w, h):
103-
self.byte_size = w*h*sizeof(remarkable_color)
148+
pass
104149

105150
def snapshot():
106151
fb := framebuffer::get()
@@ -109,13 +154,13 @@ class AppBackground: public ui::Widget:
109154
vfb := self.get_vfb()
110155
debug "SNAPSHOTTING", CURRENT_APP
111156

112-
vfb->fbmem = (remarkable_color*) memcpy(vfb->fbmem, fb->fbmem, self.byte_size)
157+
vfb->fbmem = (char*) memcpy(vfb->fbmem, fb->fbmem, vfb->byte_size)
158+
vfb->rotation = util::rotation::get()
113159

114-
framebuffer::VirtualFB* get_vfb():
160+
Snapshot* get_vfb():
115161
if app_buffers.find(CURRENT_APP) == app_buffers.end():
116-
fw, fh := fb->get_display_size()
117-
app_buffers[CURRENT_APP] = new framebuffer::VirtualFB(fw, fh)
118-
app_buffers[CURRENT_APP]->clear_screen()
162+
vw, vh := fb->get_virtual_size()
163+
app_buffers[CURRENT_APP] = new Snapshot(vw, vh)
119164

120165
return app_buffers[CURRENT_APP]
121166

@@ -132,7 +177,19 @@ class AppBackground: public ui::Widget:
132177
fb->waveform_mode = WAVEFORM_MODE_GC16
133178
else:
134179
fb->waveform_mode = WAVEFORM_MODE_AUTO
135-
memcpy(fb->fbmem, vfb->fbmem, self.byte_size)
180+
memcpy(fb->fbmem, vfb->fbmem, vfb->byte_size)
181+
182+
#ifdef DYNAMIC_BPP
183+
if CURRENT_APP == APP_MAIN.name:
184+
fb->set_screen_depth(APP_MAIN.bpp)
185+
else:
186+
fb->set_screen_depth(vfb->bits_per_pixel)
187+
#endif
188+
189+
#ifdef HAS_ROTATION
190+
fb->set_rotation(vfb->rotation)
191+
#endif
192+
136193
fb->perform_redraw(true)
137194
fb->dirty = 1
138195

@@ -176,6 +233,9 @@ class AppDialog: public ui::Pager:
176233

177234

178235
void render():
236+
#ifndef DRAW_APP_BEHIND_MODAL
237+
fb->clear_screen()
238+
#endif
179239
ui::Pager::render()
180240
self.fb->draw_line(self.x+self.w, self.y, self.x+self.w, self.y+self.h, 2, BLACK)
181241

@@ -211,6 +271,8 @@ class AppDialog: public ui::Pager:
211271

212272
if bin != "":
213273
c->mouse.click += PLS_LAMBDA(auto &ev) {
274+
if app_name == APP_NICKEL.name:
275+
return
214276

215277
app->kill(app_name)
216278

@@ -262,7 +324,7 @@ class App: public IApp:
262324
if app_bg != NULL:
263325
delete app_bg
264326

265-
app_dialog = new AppDialog(0, 0, 600, 800, self)
327+
app_dialog = new AppDialog(0, 0, DIALOG_WIDTH, DIALOG_HEIGHT, self)
266328
app_dialog->populate()
267329
get_current_app()
268330
debug "CURRENT APP IS", CURRENT_APP
@@ -293,10 +355,12 @@ class App: public IApp:
293355
button_flood = build_button_flood()
294356

295357
notebook := ui::make_scene()
358+
#ifdef DRAW_APP_BEHIND_MODAL
296359
notebook->add(app_bg)
360+
#endif
297361
ui::MainLoop::set_scene(notebook)
298362

299-
#ifdef REMARKABLE
363+
#ifdef READ_XOCHITL_DATA
300364
self.update_thresholds()
301365
#endif
302366
return
@@ -378,7 +442,7 @@ class App: public IApp:
378442
debug "UNKNOWN API LINE:", line
379443

380444
def open_input_fifo():
381-
#ifndef REMARKABLE
445+
#if !defined(REMARKABLE) && !defined(KOBO)
382446
return
383447
#endif
384448

@@ -501,6 +565,11 @@ class App: public IApp:
501565
if ui::MainLoop::overlay_is_visible:
502566
return
503567

568+
#ifdef HAS_ROTATION
569+
util::rotation::reset()
570+
input::TouchEvent::set_rotation()
571+
#endif
572+
504573
last_display_time = std::chrono::system_clock::now();
505574

506575
ui::MainLoop::in.monitor(ui::MainLoop::in.wacom.fd)
@@ -526,6 +595,10 @@ class App: public IApp:
526595

527596
ui::MainLoop::in.grab()
528597

598+
#ifdef DYNAMIC_BPP
599+
fb->set_screen_depth(sizeof(remarkable_color)*8)
600+
#endif
601+
529602
def handle_key_event(input::SynKeyEvent ev):
530603
suspend_m.lock()
531604
LAST_ACTION = time(NULL)
@@ -557,6 +630,10 @@ class App: public IApp:
557630
last_ev := &ev
558631

559632
void term_apps(string name=""):
633+
#ifdef KOBO
634+
proc::groupkill(SIGSTOP, SICKEL)
635+
#endif
636+
560637
vector<string> term
561638
for auto a : app_dialog->get_apps():
562639
tokens := str_utils::split(a.bin, ' ')
@@ -574,6 +651,7 @@ class App: public IApp:
574651

575652
// TODO: power button will cause suspend screen, why not?
576653
void on_suspend():
654+
// suspend only works on REMARKABLE
577655
#ifndef REMARKABLE
578656
return
579657
#endif
@@ -583,24 +661,15 @@ class App: public IApp:
583661

584662
_w, _h := fb->get_display_size()
585663

586-
#ifdef REMARKABLE
587664
if file_exists("/usr/share/remarkable/sleeping.png"):
588665
fb->load_from_png("/usr/share/remarkable/sleeping.png")
589666
else:
590667
fb->load_from_png("/usr/share/remarkable/suspended.png")
591-
#else
592-
text := ui::Text(0, _h-64, _w, 100, "Press any button to wake")
593-
text.set_style(ui::Stylesheet().font_size(64).justify_center())
594-
595-
text.undraw()
596-
text.render()
597-
#endif
598668

599669

600670
fb->redraw_screen()
601671
ui::MainLoop::in.grab()
602672

603-
#ifdef REMARKABLE
604673
if rm2fb::IN_RM2FB_SHIM:
605674
sleep(1)
606675
_ := system("systemctl suspend")
@@ -630,7 +699,6 @@ class App: public IApp:
630699
LAST_ACTION = time(NULL)
631700

632701
_ = system("echo 0 > /sys/class/rtc/rtc0/wakealarm")
633-
#endif
634702

635703
debug "RESUMING FROM SUSPEND"
636704
ui::MainLoop::in.ungrab()
@@ -659,9 +727,9 @@ class App: public IApp:
659727

660728
i := 0
661729
while i < n:
662-
ev[i++] = input_event{ type:EV_ABS, code:ABS_DISTANCE, value:1 }
730+
ev[i++] = input_event{ type:EV_ABS, code:TOUCH_FLOOD_EVENT, value:1 }
663731
ev[i++] = input_event{ type:EV_SYN, code:0, value:0 }
664-
ev[i++] = input_event{ type:EV_ABS, code:ABS_DISTANCE, value:2 }
732+
ev[i++] = input_event{ type:EV_ABS, code:TOUCH_FLOOD_EVENT, value:2 }
665733
ev[i++] = input_event{ type:EV_SYN, code:0, value:0 }
666734

667735
return ev
@@ -742,9 +810,12 @@ class App: public IApp:
742810
// flood_button_queue()
743811

744812
bin := app.bin
745-
if app.which == "xochitl":
813+
if app.which == APP_XOCHITL.which:
746814
bin = get_xochitl_cmd()
747815

816+
if app.which == APP_NICKEL.which:
817+
proc::groupkill(SIGCONT, SICKEL)
818+
748819
if app.resume != "" and proc::check_process(app.which):
749820
proc::launch_process(app.resume)
750821
else:
@@ -825,7 +896,7 @@ class App: public IApp:
825896
putenv((char*) "KO_DONT_GRAB_INPUT=1")
826897

827898

828-
#ifdef REMARKABLE
899+
#if defined(REMARKABLE)
829900
_ := system("systemctl stop xochitl")
830901
self.term_apps()
831902
startup_cmd := CONFIG.get_value("start_app", "xochitl")

0 commit comments

Comments
 (0)