Adding simple jitter screensaver mode

This commit is contained in:
Thomas Johnstone 2024-07-15 16:12:50 +10:00
parent 0aa4addf2d
commit ef36b0d079
15 changed files with 67 additions and 41 deletions

Binary file not shown.

View File

@ -6,7 +6,7 @@ dd if=/dev/zero of=fat.img bs=2M count=1
mkdosfs -F12 -n DESKHOP -i 0 fat.img mkdosfs -F12 -n DESKHOP -i 0 fat.img
sudo mount -o loop -t vfat fat.img /mnt/disk/ sudo mount -o loop,x-mount.mkdir -t vfat fat.img /mnt/disk/
sudo cp ../webconfig/config.htm /mnt/disk/config.htm sudo cp ../webconfig/config.htm /mnt/disk/config.htm
sudo umount /mnt/disk sudo umount /mnt/disk

Binary file not shown.

View File

@ -18,7 +18,7 @@ const config_t default_config = {
.os = OUTPUT_A_OS, .os = OUTPUT_A_OS,
.pos = RIGHT, .pos = RIGHT,
.screensaver = { .screensaver = {
.enabled = SCREENSAVER_A_ENABLED, .mode = SCREENSAVER_A_MODE,
.only_if_inactive = SCREENSAVER_A_ONLY_IF_INACTIVE, .only_if_inactive = SCREENSAVER_A_ONLY_IF_INACTIVE,
.idle_time_us = SCREENSAVER_A_IDLE_TIME_SEC * 1000000, .idle_time_us = SCREENSAVER_A_IDLE_TIME_SEC * 1000000,
.max_time_us = SCREENSAVER_A_MAX_TIME_SEC * 1000000, .max_time_us = SCREENSAVER_A_MAX_TIME_SEC * 1000000,
@ -38,7 +38,7 @@ const config_t default_config = {
.os = OUTPUT_B_OS, .os = OUTPUT_B_OS,
.pos = LEFT, .pos = LEFT,
.screensaver = { .screensaver = {
.enabled = SCREENSAVER_B_ENABLED, .mode = SCREENSAVER_B_MODE,
.only_if_inactive = SCREENSAVER_B_ONLY_IF_INACTIVE, .only_if_inactive = SCREENSAVER_B_ONLY_IF_INACTIVE,
.idle_time_us = SCREENSAVER_B_IDLE_TIME_SEC * 1000000, .idle_time_us = SCREENSAVER_B_IDLE_TIME_SEC * 1000000,
.max_time_us = SCREENSAVER_B_MAX_TIME_SEC * 1000000, .max_time_us = SCREENSAVER_B_MAX_TIME_SEC * 1000000,

View File

@ -185,7 +185,7 @@ typedef struct {
/********* Configuration storage definitions **********/ /********* Configuration storage definitions **********/
#define CURRENT_CONFIG_VERSION 7 #define CURRENT_CONFIG_VERSION 8
enum os_type_e { enum os_type_e {
LINUX = 1, LINUX = 1,
@ -201,6 +201,12 @@ enum screen_pos_e {
MIDDLE = 3, MIDDLE = 3,
}; };
enum screensaver_mode_e {
DISABLED = 0,
PONG = 1,
JITTER = 2,
};
#define ITF_NUM_HID 0 #define ITF_NUM_HID 0
#define ITF_NUM_HID_REL_M 1 #define ITF_NUM_HID_REL_M 1
#define ITF_NUM_HID_VENDOR 1 #define ITF_NUM_HID_VENDOR 1
@ -214,7 +220,7 @@ typedef struct {
/* Define screensaver parameters */ /* Define screensaver parameters */
typedef struct { typedef struct {
uint8_t enabled; uint8_t mode;
uint8_t only_if_inactive; uint8_t only_if_inactive;
uint64_t idle_time_us; uint64_t idle_time_us;
uint64_t max_time_us; uint64_t max_time_us;

View File

@ -109,8 +109,8 @@
* *
**/ **/
#define SCREENSAVER_A_ENABLED 0 #define SCREENSAVER_A_MODE DISABLED
#define SCREENSAVER_B_ENABLED 0 #define SCREENSAVER_B_MODE DISABLED
/**================================================== * /**================================================== *
* *

View File

@ -17,7 +17,7 @@ const field_map_t api_field_map[] = {
{ 16, false, UINT8, 1, offsetof(device_t, config.output[0].os) }, { 16, false, UINT8, 1, offsetof(device_t, config.output[0].os) },
{ 17, false, UINT8, 1, offsetof(device_t, config.output[0].pos) }, { 17, false, UINT8, 1, offsetof(device_t, config.output[0].pos) },
{ 18, false, UINT8, 1, offsetof(device_t, config.output[0].mouse_park_pos) }, { 18, false, UINT8, 1, offsetof(device_t, config.output[0].mouse_park_pos) },
{ 19, false, UINT8, 1, offsetof(device_t, config.output[0].screensaver.enabled) }, { 19, false, UINT8, 1, offsetof(device_t, config.output[0].screensaver.mode) },
{ 20, false, UINT8, 1, offsetof(device_t, config.output[0].screensaver.only_if_inactive) }, { 20, false, UINT8, 1, offsetof(device_t, config.output[0].screensaver.only_if_inactive) },
/* Until we increase the payload size from 8 bytes, clamp to avoid exceeding the field size */ /* Until we increase the payload size from 8 bytes, clamp to avoid exceeding the field size */
@ -34,7 +34,7 @@ const field_map_t api_field_map[] = {
{ 46, false, UINT8, 1, offsetof(device_t, config.output[1].os) }, { 46, false, UINT8, 1, offsetof(device_t, config.output[1].os) },
{ 47, false, UINT8, 1, offsetof(device_t, config.output[1].pos) }, { 47, false, UINT8, 1, offsetof(device_t, config.output[1].pos) },
{ 48, false, UINT8, 1, offsetof(device_t, config.output[1].mouse_park_pos) }, { 48, false, UINT8, 1, offsetof(device_t, config.output[1].mouse_park_pos) },
{ 49, false, UINT8, 1, offsetof(device_t, config.output[1].screensaver.enabled) }, { 49, false, UINT8, 1, offsetof(device_t, config.output[1].screensaver.mode) },
{ 50, false, UINT8, 1, offsetof(device_t, config.output[1].screensaver.only_if_inactive) }, { 50, false, UINT8, 1, offsetof(device_t, config.output[1].screensaver.only_if_inactive) },
{ 51, false, UINT64, 7, offsetof(device_t, config.output[1].screensaver.idle_time_us) }, { 51, false, UINT64, 7, offsetof(device_t, config.output[1].screensaver.idle_time_us) },
{ 52, false, UINT64, 7, offsetof(device_t, config.output[1].screensaver.max_time_us) }, { 52, false, UINT64, 7, offsetof(device_t, config.output[1].screensaver.max_time_us) },

View File

@ -67,10 +67,10 @@ void screensaver_task(device_t *state) {
static mouse_report_t report = {0}; static mouse_report_t report = {0};
static int last_pointer_move = 0; static int last_pointer_move = 0;
static int dx = 20, dy = 25; static int dx = 20, dy = 25, jitter = 1;
/* If we're not enabled, nothing to do here. */ /* If we're not enabled, nothing to do here. */
if (!screensaver->enabled) if (screensaver->mode == DISABLED)
return; return;
/* System is still not idle for long enough to activate or we've been running for too long */ /* System is still not idle for long enough to activate or we've been running for too long */
@ -90,15 +90,26 @@ void screensaver_task(device_t *state) {
if ((time_us_32()) - last_pointer_move < mouse_move_delay) if ((time_us_32()) - last_pointer_move < mouse_move_delay)
return; return;
/* Check if we are bouncing off the walls and reverse direction in that case. */ switch (screensaver->mode) {
if (report.x + dx < MIN_SCREEN_COORD || report.x + dx > MAX_SCREEN_COORD) case PONG:
dx = -dx; /* Check if we are bouncing off the walls and reverse direction in that case. */
if (report.x + dx < MIN_SCREEN_COORD || report.x + dx > MAX_SCREEN_COORD)
dx = -dx;
if (report.y + dy < MIN_SCREEN_COORD || report.y + dy > MAX_SCREEN_COORD) if (report.y + dy < MIN_SCREEN_COORD || report.y + dy > MAX_SCREEN_COORD)
dy = -dy; dy = -dy;
report.x += dx; report.x += dx;
report.y += dy; report.y += dy;
break;
case JITTER:
report.x = state->pointer_x + jitter;
report.y = state->pointer_y + jitter;
jitter = -jitter;
break;
}
/* Move mouse pointer */ /* Move mouse pointer */
queue_mouse_report(&report, state); queue_mouse_report(&report, state);

2
webconfig/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
__pycache__
/venv/

View File

@ -995,16 +995,20 @@ img {
<div class="clearfix">
<label class="label-inline"> Enabled</label> <label class=""> Mode</label>
<input class="api" type="checkbox" name="name19" data-type="uint8" data-key="19"
onchange="valueChangedHandler(this)"
/>
</div> <select class="api" data-type="uint8" data-key="19" required>
<option disabled selected value></option>
<option value="0">Disabled</option>
<option value="1">Pong</option>
<option value="2">Jitter</option>
</select><br />
@ -1339,16 +1343,20 @@ img {
<div class="clearfix">
<label class="label-inline"> Enabled</label> <label class=""> Mode</label>
<input class="api" type="checkbox" name="name49" data-type="uint8" data-key="49"
onchange="valueChangedHandler(this)"
/>
</div> <select class="api" data-type="uint8" data-key="49" required>
<option disabled selected value></option>
<option value="0">Disabled</option>
<option value="1">Pong</option>
<option value="2">Jitter</option>
</select><br />
@ -1711,9 +1719,7 @@ async function sendReport(type, payload = [], sendBoth = false) {
} }
var report = makeReport(type, payload, false); var report = makeReport(type, payload, false);
await device.sendReport(mgmtReportId, report); await device.sendReport(mgmtReportId, report);
console.log(`Sent ${type} report ${report}`);
} }
function makeReport(type, payload, proxy=false) { function makeReport(type, payload, proxy=false) {
@ -1847,7 +1853,6 @@ async function readHandler() {
let incomingReport = await new Promise((resolve, reject) => { let incomingReport = await new Promise((resolve, reject) => {
const handleInputReport = (event) => { const handleInputReport = (event) => {
updateElement(element, event, dataType); updateElement(element, event, dataType);
console.log(new Uint8Array(event.data.buffer));
device.removeEventListener('inputreport', handleInputReport); device.removeEventListener('inputreport', handleInputReport);
resolve(); resolve();

File diff suppressed because one or more lines are too long

View File

@ -49,7 +49,7 @@ OUTPUT_ = [
FormField(7, "Screen Position", 1, {1: "Left", 2: "Right"}, "uint8"), FormField(7, "Screen Position", 1, {1: "Left", 2: "Right"}, "uint8"),
FormField(8, "Cursor Park Position", 0, {0: "Top", 1: "Bottom", 3: "Previous"}, "uint8"), FormField(8, "Cursor Park Position", 0, {0: "Top", 1: "Bottom", 3: "Previous"}, "uint8"),
FormField(1003, "Screensaver", elem="label"), FormField(1003, "Screensaver", elem="label"),
FormField(9, "Enabled", None, {}, "uint8", "checkbox"), FormField(9, "Mode", 0, {0: "Disabled", 1: "Pong", 2: "Jitter"}, "uint8"),
FormField(10, "Only If Inactive", None, {}, "uint8", "checkbox"), FormField(10, "Only If Inactive", None, {}, "uint8", "checkbox"),
FormField(11, "Idle Time (μs)", None, {}, "uint64"), FormField(11, "Idle Time (μs)", None, {}, "uint64"),
FormField(12, "Max Time (μs)", None, {}, "uint64"), FormField(12, "Max Time (μs)", None, {}, "uint64"),

View File

@ -23,7 +23,7 @@ def render(filename, *args, **kwargs):
def write_file(payload, filename=OUTPUT_FILENAME): def write_file(payload, filename=OUTPUT_FILENAME):
with open(filename, 'w') as file: with open(filename, 'w', encoding='utf-8') as file:
file.write(payload) file.write(payload)

View File

@ -0,0 +1,2 @@
Jinja2==3.1.4
MarkupSafe==2.1.5