Skip to content

Commit

Permalink
Add touch commands
Browse files Browse the repository at this point in the history
  • Loading branch information
pipe01 committed Jun 22, 2024
1 parent 0e60057 commit b79f466
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 5 deletions.
2 changes: 1 addition & 1 deletion frontend/wasm/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<title>InfiniEmu</title>
<script src="https://cdn.jsdelivr.net/npm/@zip.js/[email protected]/dist/zip.min.js"></script>
<style>
#sleepCover {
Expand Down
79 changes: 76 additions & 3 deletions src/commander.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "commander.h"

#include <string.h>
#include <time.h>

#define END \
{ \
Expand Down Expand Up @@ -141,11 +142,68 @@ COMMAND(cmd_step)
pinetime_step(cder->pt);
}

COMMAND(cmd_wait)
{
char *end;
int ms = strtol(args, &end, 0);

if (end == args || *end != '\0' || ms < 0)
{
commander_outputf(cder, "Invalid number of milliseconds: %s\n", args);
return;
}

struct timespec ts = {
.tv_sec = ms / 1000,
.tv_nsec = (ms % 1000) * 1000000,
};
nanosleep(&ts, NULL);
}

COMMAND(cmd_pinetime_touch_swipe)
{
cst816s_t *touch = pinetime_get_cst816s(cder->pt);

touch_gesture_t gesture;
if (strcmp(args, "left") == 0)
gesture = GESTURE_SLIDELEFT;
else if (strcmp(args, "right") == 0)
gesture = GESTURE_SLIDERIGHT;
else if (strcmp(args, "up") == 0)
gesture = GESTURE_SLIDEUP;
else if (strcmp(args, "down") == 0)
gesture = GESTURE_SLIDEDOWN;
else
{
commander_outputf(cder, "Invalid gesture: %s\n", args);
return;
}

cst816s_do_touch(touch, gesture, PINETIME_LCD_WIDTH / 2, PINETIME_LCD_HEIGHT / 2);
}

COMMAND(cmd_pinetime_touch_release)
{
cst816s_t *touch = pinetime_get_cst816s(cder->pt);

cst816s_release_touch(touch);
}

static command_t commands[] = {
{
.name = "help",
.handler = cmd_help,
},
{
.name = "step",
.handler = cmd_step,
.description = "Step the emulator by one instruction",
},
{
.name = "wait",
.handler = cmd_wait,
.description = "Wait for a given number of milliseconds",
},
{
.name = "nrf52",
.children = (command_t[]){
Expand Down Expand Up @@ -176,9 +234,24 @@ static command_t commands[] = {
},
},
{
.name = "step",
.handler = cmd_step,
.description = "Step the emulator by one instruction",
.name = "pinetime",
.children = (command_t[]){
{
.name = "touch",
.children = (command_t[]){
{
.name = "swipe",
.handler = cmd_pinetime_touch_swipe,
},
{
.name = "release",
.handler = cmd_pinetime_touch_release,
},
END,
},
},
END,
},
},
END,
};
Expand Down
2 changes: 1 addition & 1 deletion src/component/i2c/cst816s.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,4 @@ void cst816s_release_touch(cst816s_t *cst)
cst->has_touch = true;

pins_clear(cst->pins, cst->irqPin);
}
}

0 comments on commit b79f466

Please sign in to comment.