Skip to content

Commit

Permalink
First working build of "flexible triggers and actions" for Release 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacwisdom committed Jul 17, 2021
1 parent c3f37ae commit a6f5b1f
Show file tree
Hide file tree
Showing 11 changed files with 447 additions and 228 deletions.
17 changes: 12 additions & 5 deletions RemarkableLamyEraser.pro
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,36 @@ INCLUDEPATH += /opt/codex/rm11x/2.5.2/sysroots/x86_64-codexsdk-linux/usr/lib/arm

HEADERS += \
actions.h \
configuration.h \
orientation.h \
triggers.h \

SOURCES += \
configuration.c \
orientation.c \
actions.c \
triggers.c \
main.c \


OTHER_FILES += \
RemarkableLamyEraser.conf\
RemarkableLamyEraser/LamyEraser.service \
README.md \
triggers_struct.h \
triggers_struct.c \

conf.files = RemarkableLamyEraser/LamyEraser.conf
conf.path = /home/root/.config/LamyEraser

service.files = RemarkableLamyEraser/LamyEraser.service

service.path = /home/root/RemarkableLamyEraser

target.path = /home/root/RemarkableLamyEraser
service.path = /home/root/RemarkableLamyEraser


INSTALLS += \
target \
service
service \
conf \

DISTFILES += \
RemarkableLamyEraser/LamyEraser.conf
36 changes: 36 additions & 0 deletions RemarkableLamyEraser/LamyEraser.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# RemarkableLamyEraser Configuration File~
# Set up your triggers and effects here
# Any trigger left blank will have no effect.
# Effects are divided into tools and actions :
# Actions are compatible with click-type actions

# The available actions are:
# toolbar : presses the toolbar panel button
# writing : presses the writing utensil button
# undo : presses the undo button
# redo : presses the redo button

# Tools are compatible with press&hold type triggers, or with click type triggers as toggles
# The available tools are:
# erase : changes to eraser tool. on deactivation, changes back to writing utensil
# note that on the RM2, this mode uses special features available from the marker plus.
# erase-selection : changes to erase selection tool. on deactivation, changes back to writing utensil
# select : changes to select tool. on deactivation, changes back to writing utensil

# Example valid configuration lines:
# click erase
# press&hold select



click erase
double-click undo
triple-click
quadruple-click
quintuple-click

press&hold erase-selection
double-press&hold
triple-press&hold
quadruple-press&hold
quintuple-press&hold
Binary file modified RemarkableLamyEraser/RemarkableLamyEraser
Binary file not shown.
34 changes: 2 additions & 32 deletions actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static int toolEraserRM1 = 0;
void activateToolEraserRM1(int fd_touch, int rmVersion) {
printf("Deactivating ToolEraserRM1: writing eraser tool on\n");
toolbarOrientation orientation = getToolbarOrientation();
writeOrientedTapSequence(fd_touch, &orientation, rmVersion, 6, ERASER, ERASER_ERASE, TOOLBAR, ERASER, ERASER_ERASE, TOOLBAR);
writeOrientedTapSequence(fd_touch, &orientation, rmVersion, 6, ERASER_PANEL, ERASER_ERASE, TOOLBAR, ERASER_PANEL, ERASER_ERASE, TOOLBAR);
toolEraserRM1 = 1;
}
void deactivateToolEraserRM1(int fd_touch, int rmVersion) {
Expand All @@ -164,7 +164,7 @@ static int toolEraseSelect = 0;
void activateToolEraseSelect(int fd_touch, int rmVersion) {
printf("Deactivating ToolEraserRM1: writing eraser tool on\n");
toolbarOrientation orientation = getToolbarOrientation();
writeOrientedTapSequence(fd_touch, &orientation, rmVersion, 6, ERASER, ERASE_SELECT, TOOLBAR, ERASER, ERASE_SELECT, TOOLBAR);
writeOrientedTapSequence(fd_touch, &orientation, rmVersion, 6, ERASER_PANEL, ERASER_SELECT, TOOLBAR, ERASER_PANEL, ERASER_SELECT, TOOLBAR);
toolEraseSelect = 1;
}
void deactivateToolEraseSelect(int fd_touch, int rmVersion) {
Expand Down Expand Up @@ -200,34 +200,4 @@ void toggleToolSelect(int fd_touch, int rmVersion) {
activateToolSelect(fd_touch, rmVersion);
}

void actionSelect(struct input_event* ev_pen, int fd_touch, int RMversion) {
static toolbarOrientation orientation;
static int state = -1;
if (ev_pen->code == BTN_STYLUS) {
orientation = getToolbarOrientation();
if(ev_pen->value == 1) {
printf("writing select tool...\n");
writeOrientedTapSequence(fd_touch, &orientation, RMversion, 4, SELECT, TOOLBAR, SELECT, TOOLBAR);
state = 1;
}
else {
printf("writing writing tool...\n");
writeOrientedTapSequence(fd_touch, &orientation, RMversion, 4, WRITING, TOOLBAR, WRITING, TOOLBAR);
state = 0;
}
}
else if (ev_pen->code == BTN_TOOL_PEN && ev_pen->value == 1 && state != -1) {
if (state == 1) {
printf("writing select tool...\n");
writeOrientedTapSequence(fd_touch, &orientation, RMversion, 4, SELECT, TOOLBAR, SELECT, TOOLBAR);
}
else if (state == 0)
{
printf("writing writing tool...\n");
writeOrientedTapSequence(fd_touch, &orientation, RMversion, 4, WRITING, TOOLBAR, WRITING, TOOLBAR);
}
}
}



85 changes: 45 additions & 40 deletions actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,59 +5,64 @@
#include <stdbool.h>

#include "orientation.h"
//erase modes
#define PRESS_MODE 1
#define TOGGLE_MODE 2

#define PRESS_MODE_RM1 3 //press and hold mode for RM1
#define TOGGLE_MODE_RM1 4 //toggle mode for RM1

#define PRESS_MODE_RM2 5 //press and hold mode
#define TOGGLE_MODE_RM2 6 //toggle mode



#define TOOLBAR 0
//actions:
#define WRITING 1 //writing button
#define ERASER 2 //eraser button
#define ERASER_ERASE 3 //eraser: normal eraser button
#define ERASE_SELECT 4 //eraser: erase selection button
#define SELECT 5 //select button
#define UNDO 6 //undo button
#define REDO 7 //redo button
#define NUM_EFFECTS 9

//effects:
#define NULL_EFFECT 0 //null effect
#define TOOLBAR 1 //action: toolbar
#define WRITING 2 //action: writing
#define ERASER_PANEL 3 //<eraser (internal use only)>
#define ERASER_ERASE 4 //tool: eraser normal eraser button
#define ERASER_SELECT 5 //tool: erase-selection: erase selection button
#define SELECT 6 //tool: selection
#define UNDO 7 //action: undo button
#define REDO 8 //action: redo button

#define HOLD_OFF_OFFSET 0x0ff
#define ERASER_ERASE_OFF (ERASER_ERASE + HOLD_OFF_OFFSET)
#define ERASER_SELECT_OFF (ERASER_SELECT + HOLD_OFF_OFFSET)
#define SELECT_OFF (SELECT + HOLD_OFF_OFFSET)

#define TOGGLE_OFFSET 0xfff
#define ERASER_ERASE_TOGGLE (ERASER_ERASE + TOGGLE_OFFSET)
#define ERASER_SELECT_TOGGLE (ERASER_SELECT + TOGGLE_OFFSET)
#define SELECT_TOGGLE (SELECT + TOGGLE_OFFSET)

//Touch Screen Coordinates:
#define RM2_RHtoolX 60 //define one x coordinate for all panel tools
#define RM2_RHtoolY 50 //define one y coordinate for panel tools
#define RM2_LHtoolX 1360 //define one y coordinate for panel tools
#define RM2_LHtoolY 1820 //define one y coordinate for panel tools
static const int locationLookup[2][8][4][2] = {
static const int locationLookup[2][NUM_EFFECTS][4][2] = {
{ /* RM1 */
//RHP //RHL //LHP //LHL
{ {RM2_RHtoolX, 1820}, { 40, RM2_RHtoolY}, {RM2_LHtoolX, 1820}, { 40, RM2_LHtoolY} }, //TOOLBAR 0
{ {RM2_RHtoolX, 1680}, { 80, RM2_RHtoolY}, {RM2_LHtoolX, 1680}, { 80, RM2_LHtoolY} }, //WRITING 1
{ {RM2_RHtoolX, 1450}, { 430, RM2_RHtoolY}, {RM2_LHtoolX, 1450}, { 430, RM2_LHtoolY} }, //ERASER 2
{ { 280, 1450}, { 430, 270}, { 1140, 1450}, { 430, 1590} }, //ERASER_ERASE 3
{ { 280, 1330}, { 550, 270}, { 1140, 1340}, { 550, 1590} }, //ERASE_SELECT 4
{ {RM2_RHtoolX, 1330}, { 550, RM2_RHtoolY}, {RM2_LHtoolX, 1340}, { 550, RM2_LHtoolY} }, //SELECT 5
{ {RM2_RHtoolX, 1220}, { 670, RM2_RHtoolY}, {RM2_LHtoolX, 1220}, { 670, RM2_LHtoolY} }, //UNDO 6
{ {RM2_RHtoolX, 1090}, { 800, RM2_RHtoolY}, {RM2_LHtoolX, 1090}, { 800, RM2_LHtoolY} }, //REDO 7
{ { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0} }, //NO_EFFECT 0
{ {RM2_RHtoolX, 1820}, { 40, RM2_RHtoolY}, {RM2_LHtoolX, 1820}, { 40, RM2_LHtoolY} }, //TOOLBAR 1
{ {RM2_RHtoolX, 1680}, { 80, RM2_RHtoolY}, {RM2_LHtoolX, 1680}, { 80, RM2_LHtoolY} }, //WRITING 2
{ {RM2_RHtoolX, 1450}, { 430, RM2_RHtoolY}, {RM2_LHtoolX, 1450}, { 430, RM2_LHtoolY} }, //ERASER 3
{ { 280, 1450}, { 430, 270}, { 1140, 1450}, { 430, 1590} }, //ERASER_ERASE 4
{ { 280, 1330}, { 550, 270}, { 1140, 1340}, { 550, 1590} }, //ERASE_SELECT 5
{ {RM2_RHtoolX, 1330}, { 550, RM2_RHtoolY}, {RM2_LHtoolX, 1340}, { 550, RM2_LHtoolY} }, //SELECT 6
{ {RM2_RHtoolX, 1220}, { 670, RM2_RHtoolY}, {RM2_LHtoolX, 1220}, { 670, RM2_LHtoolY} }, //UNDO 7
{ {RM2_RHtoolX, 1090}, { 800, RM2_RHtoolY}, {RM2_LHtoolX, 1090}, { 800, RM2_LHtoolY} }, //REDO 8
},
{ /* RM2 */
//RHP //RHL //LHP //LHL
{ {RM2_RHtoolX, 1820}, { 40, RM2_RHtoolY}, {RM2_LHtoolX, 1820}, { 40, RM2_LHtoolY} }, //TOOLBAR 0
{ {RM2_RHtoolX, 1680}, { 80, RM2_RHtoolY}, {RM2_LHtoolX, 1680}, { 80, RM2_LHtoolY} }, //WRITING 1
{ {RM2_RHtoolX, 1450}, { 430, RM2_RHtoolY}, {RM2_LHtoolX, 1450}, { 430, RM2_LHtoolY} }, //ERASER 2
{ { 280, 1450}, { 430, 270}, { 1140, 1450}, { 430, 1590} }, //ERASER_ERASE 3
{ { 280, 1330}, { 550, 270}, { 1140, 1340}, { 550, 1590} }, //ERASE_SELECT 4
{ {RM2_RHtoolX, 1330}, { 550, RM2_RHtoolY}, {RM2_LHtoolX, 1340}, { 550, RM2_LHtoolY} }, //SELECT 5
{ {RM2_RHtoolX, 1220}, { 670, RM2_RHtoolY}, {RM2_LHtoolX, 1220}, { 670, RM2_LHtoolY} }, //UNDO 6
{ {RM2_RHtoolX, 1090}, { 800, RM2_RHtoolY}, {RM2_LHtoolX, 1090}, { 800, RM2_LHtoolY} }, //REDO 7
{ { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0} }, //NO_EFFECT 0
{ {RM2_RHtoolX, 1820}, { 40, RM2_RHtoolY}, {RM2_LHtoolX, 1820}, { 40, RM2_LHtoolY} }, //TOOLBAR 1
{ {RM2_RHtoolX, 1680}, { 80, RM2_RHtoolY}, {RM2_LHtoolX, 1680}, { 80, RM2_LHtoolY} }, //WRITING 2
{ {RM2_RHtoolX, 1450}, { 430, RM2_RHtoolY}, {RM2_LHtoolX, 1450}, { 430, RM2_LHtoolY} }, //ERASER 3
{ { 280, 1450}, { 430, 270}, { 1140, 1450}, { 430, 1590} }, //ERASER_ERASE 4
{ { 280, 1330}, { 550, 270}, { 1140, 1340}, { 550, 1590} }, //ERASE_SELECT 5
{ {RM2_RHtoolX, 1330}, { 550, RM2_RHtoolY}, {RM2_LHtoolX, 1340}, { 550, RM2_LHtoolY} }, //SELECT 6
{ {RM2_RHtoolX, 1220}, { 670, RM2_RHtoolY}, {RM2_LHtoolX, 1220}, { 670, RM2_LHtoolY} }, //UNDO 7
{ {RM2_RHtoolX, 1090}, { 800, RM2_RHtoolY}, {RM2_LHtoolX, 1090}, { 800, RM2_LHtoolY} }, //REDO 8
}
};



//static const struct input_event tool_touch_off = { .type = EV_KEY, .code =BTN_TOUCH, .value = 0}; //these might be used in the future to improve press and hold mode
static const struct input_event tool_pen_on = { .type = EV_KEY, .code = BTN_TOOL_PEN, .value = 1}; //used when pen approaches the screen
static const struct input_event tool_pen_off = { .type = EV_KEY, .code = BTN_TOOL_PEN, .value =0};
Expand All @@ -79,9 +84,9 @@ void activateToolEraserRM1(int fd_touch, int rmVersion);
void deactivateToolEraserRM1(int fd_touch, int rmVersion);
void toggleToolEraserRM1(int fd_touch, int rmVersion);

void activateToolEraseSelection(int fd_touch, int rmVersion);
void deactivateToolEraseSelection(int fd_touch, int rmVersion);
void toggleToolEraseSelection(int fd_touch, int rmVersion);
void activateToolEraseSelect(int fd_touch, int rmVersion);
void deactivateToolEraseSelect(int fd_touch, int rmVersion);
void toggleToolEraseSelect(int fd_touch, int rmVersion);

void activateToolSelect(int fd_touch, int rmVersion);
void deactivateToolSelect(int fd_touch, int rmVersion);
Expand Down
112 changes: 112 additions & 0 deletions configuration.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>

#include <configuration.h>



int getTriggerConfig(const char *path, struct configuration *config) {
//returns 0 on success
//returns 1 if error in configuration file
// returns -1 if configuration file doesn't exist
FILE *fp;
char* line;
int lineNum = 0;
size_t len =0;
ssize_t read;
char trigger[24] = "--";
char effect[24] = "--";
int readTrigger = -1, readEffect = -1;

fp = fopen(path, "r");
if (fp == NULL)
return -1;
while ((read = getline(&line, &len, fp)) != -1) {
lineNum++;
if (line[0] == '#' || line[0] == '\n') {
continue;
}

if ( (sscanf(line, "%s %s", trigger, effect) == 2) ) {
printf("Line %2d: Read trigger <%s> with effect <%s>\n", lineNum, trigger, effect);
}
else {
//printf("Line %2d: Read trigger <%s> has no effect.\n", lineNum, trigger);
strcpy(effect, "null");
}

for (int i = 0; i < NUM_TRIGGERS; i++){
if (!strcmp(trigger, triggers[i])) {
readTrigger = i;
break;
}
}
for (int j = 0; j < NUM_EFFECTS; j++) {
if (!strcmp(effect, effects[j])) {
readEffect = j;
break;
}
}
if (readTrigger == -1) {
printf("Invalid trigger %s in line %d of configuration file at %s\n", trigger, lineNum, path);
return 1;
}
if (readEffect == -1) {
printf("Invalid effect %s in line %d of configuration file at %s\n", effect, lineNum, path);
return 1;
}

switch(readTrigger) {
case TRIGGER_CLICK_1 :
config->click1Effect = readEffect;
break;
case TRIGGER_CLICK_2 :
config->click2Effect = readEffect;
break;
case TRIGGER_CLICK_3 :
config->click3Effect = readEffect;
break;
case TRIGGER_CLICK_4 :
config->click4Effect = readEffect;
break;
case TRIGGER_CLICK_5 :
config->click5Effect = readEffect;
break;
case TRIGGER_HOLD_1 :
config->hold1Effect = readEffect;
break;
case TRIGGER_HOLD_2 :
config->hold2Effect = readEffect;
break;
case TRIGGER_HOLD_3 :
config->hold3Effect = readEffect;
break;
case TRIGGER_HOLD_4 :
config->hold4Effect = readEffect;
break;
case TRIGGER_HOLD_5 :
config->hold5Effect = readEffect;
break;
}
strcpy(trigger, "--");
strcpy(effect, "--");
readTrigger = -1;
readEffect = -1;
}
fclose(fp);
return 0;
}
void printConfig(struct configuration *config) {
printf("click1Effect: %x\n", config->click1Effect);
printf("click2Effect: %x\n", config->click2Effect);
printf("click3Effect: %x\n", config->click3Effect);
printf("click4Effect: %x\n", config->click4Effect);
printf("click5Effect: %x\n", config->click5Effect);
printf("hold1Effect: %x\n", config->hold1Effect);
printf("hold2Effect: %x\n", config->hold2Effect);
printf("hold3Effect: %x\n", config->hold3Effect);
printf("hold4Effect: %x\n", config->hold4Effect);
printf("hold5Effect: %x\n", config->hold5Effect);
}
Loading

0 comments on commit a6f5b1f

Please sign in to comment.