mirror of
https://github.com/hrvach/deskhop.git
synced 2024-11-21 23:33:33 +01:00
Adding simple jitter screensaver mode
This commit is contained in:
parent
0aa4addf2d
commit
ef36b0d079
Binary file not shown.
@ -6,7 +6,7 @@ dd if=/dev/zero of=fat.img bs=2M count=1
|
||||
|
||||
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 umount /mnt/disk
|
||||
|
||||
|
BIN
disk/disk.img
BIN
disk/disk.img
Binary file not shown.
@ -18,7 +18,7 @@ const config_t default_config = {
|
||||
.os = OUTPUT_A_OS,
|
||||
.pos = RIGHT,
|
||||
.screensaver = {
|
||||
.enabled = SCREENSAVER_A_ENABLED,
|
||||
.mode = SCREENSAVER_A_MODE,
|
||||
.only_if_inactive = SCREENSAVER_A_ONLY_IF_INACTIVE,
|
||||
.idle_time_us = SCREENSAVER_A_IDLE_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,
|
||||
.pos = LEFT,
|
||||
.screensaver = {
|
||||
.enabled = SCREENSAVER_B_ENABLED,
|
||||
.mode = SCREENSAVER_B_MODE,
|
||||
.only_if_inactive = SCREENSAVER_B_ONLY_IF_INACTIVE,
|
||||
.idle_time_us = SCREENSAVER_B_IDLE_TIME_SEC * 1000000,
|
||||
.max_time_us = SCREENSAVER_B_MAX_TIME_SEC * 1000000,
|
||||
|
@ -185,7 +185,7 @@ typedef struct {
|
||||
|
||||
/********* Configuration storage definitions **********/
|
||||
|
||||
#define CURRENT_CONFIG_VERSION 7
|
||||
#define CURRENT_CONFIG_VERSION 8
|
||||
|
||||
enum os_type_e {
|
||||
LINUX = 1,
|
||||
@ -201,6 +201,12 @@ enum screen_pos_e {
|
||||
MIDDLE = 3,
|
||||
};
|
||||
|
||||
enum screensaver_mode_e {
|
||||
DISABLED = 0,
|
||||
PONG = 1,
|
||||
JITTER = 2,
|
||||
};
|
||||
|
||||
#define ITF_NUM_HID 0
|
||||
#define ITF_NUM_HID_REL_M 1
|
||||
#define ITF_NUM_HID_VENDOR 1
|
||||
@ -214,7 +220,7 @@ typedef struct {
|
||||
|
||||
/* Define screensaver parameters */
|
||||
typedef struct {
|
||||
uint8_t enabled;
|
||||
uint8_t mode;
|
||||
uint8_t only_if_inactive;
|
||||
uint64_t idle_time_us;
|
||||
uint64_t max_time_us;
|
||||
|
@ -109,8 +109,8 @@
|
||||
*
|
||||
**/
|
||||
|
||||
#define SCREENSAVER_A_ENABLED 0
|
||||
#define SCREENSAVER_B_ENABLED 0
|
||||
#define SCREENSAVER_A_MODE DISABLED
|
||||
#define SCREENSAVER_B_MODE DISABLED
|
||||
|
||||
/**================================================== *
|
||||
*
|
||||
|
@ -17,7 +17,7 @@ const field_map_t api_field_map[] = {
|
||||
{ 16, false, UINT8, 1, offsetof(device_t, config.output[0].os) },
|
||||
{ 17, false, UINT8, 1, offsetof(device_t, config.output[0].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) },
|
||||
|
||||
/* 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) },
|
||||
{ 47, false, UINT8, 1, offsetof(device_t, config.output[1].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) },
|
||||
{ 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) },
|
||||
|
29
src/tasks.c
29
src/tasks.c
@ -67,10 +67,10 @@ void screensaver_task(device_t *state) {
|
||||
|
||||
static mouse_report_t report = {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 (!screensaver->enabled)
|
||||
if (screensaver->mode == DISABLED)
|
||||
return;
|
||||
|
||||
/* 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)
|
||||
return;
|
||||
|
||||
/* 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;
|
||||
switch (screensaver->mode) {
|
||||
case PONG:
|
||||
/* 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)
|
||||
dy = -dy;
|
||||
if (report.y + dy < MIN_SCREEN_COORD || report.y + dy > MAX_SCREEN_COORD)
|
||||
dy = -dy;
|
||||
|
||||
report.x += dx;
|
||||
report.y += dy;
|
||||
report.x += dx;
|
||||
report.y += dy;
|
||||
|
||||
break;
|
||||
|
||||
case JITTER:
|
||||
report.x = state->pointer_x + jitter;
|
||||
report.y = state->pointer_y + jitter;
|
||||
jitter = -jitter;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Move mouse pointer */
|
||||
queue_mouse_report(&report, state);
|
||||
|
2
webconfig/.gitignore
vendored
Normal file
2
webconfig/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
__pycache__
|
||||
/venv/
|
Binary file not shown.
@ -995,16 +995,20 @@ img {
|
||||
|
||||
|
||||
|
||||
<div class="clearfix">
|
||||
|
||||
<label class="label-inline"> Enabled</label>
|
||||
|
||||
|
||||
<input class="api" type="checkbox" name="name19" data-type="uint8" data-key="19"
|
||||
onchange="valueChangedHandler(this)"
|
||||
/>
|
||||
<label class=""> Mode</label>
|
||||
|
||||
</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>
|
||||
|
||||
|
||||
<input class="api" type="checkbox" name="name49" data-type="uint8" data-key="49"
|
||||
onchange="valueChangedHandler(this)"
|
||||
/>
|
||||
<label class=""> Mode</label>
|
||||
|
||||
</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);
|
||||
await device.sendReport(mgmtReportId, report);
|
||||
|
||||
console.log(`Sent ${type} report ${report}`);
|
||||
await device.sendReport(mgmtReportId, report);
|
||||
}
|
||||
|
||||
function makeReport(type, payload, proxy=false) {
|
||||
@ -1847,7 +1853,6 @@ async function readHandler() {
|
||||
let incomingReport = await new Promise((resolve, reject) => {
|
||||
const handleInputReport = (event) => {
|
||||
updateElement(element, event, dataType);
|
||||
console.log(new Uint8Array(event.data.buffer));
|
||||
|
||||
device.removeEventListener('inputreport', handleInputReport);
|
||||
resolve();
|
||||
|
File diff suppressed because one or more lines are too long
@ -49,7 +49,7 @@ OUTPUT_ = [
|
||||
FormField(7, "Screen Position", 1, {1: "Left", 2: "Right"}, "uint8"),
|
||||
FormField(8, "Cursor Park Position", 0, {0: "Top", 1: "Bottom", 3: "Previous"}, "uint8"),
|
||||
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(11, "Idle Time (μs)", None, {}, "uint64"),
|
||||
FormField(12, "Max Time (μs)", None, {}, "uint64"),
|
||||
|
@ -23,7 +23,7 @@ def render(filename, *args, **kwargs):
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
|
2
webconfig/requirements.txt
Normal file
2
webconfig/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
Jinja2==3.1.4
|
||||
MarkupSafe==2.1.5
|
Loading…
Reference in New Issue
Block a user