Skip to content

Commit ec4f8b9

Browse files
Allow Windows to turn off screen/sleep (#11)
* Change HID polling interval and optimize report sending Updated HID polling interval from 10ms to 100ms and modified report sending logic to only send changes. * Add workflow_dispatch event to GitHub Actions * Upgrade upload-artifact action to version 4 * Document changes for Windows/monitor sleep support Added a section to highlight changes regarding Windows/monitor sleep compatibility. * Remove original changes section from README
1 parent b79d2be commit ec4f8b9

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

.github/workflows/action.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
release:
77
types:
88
- created
9+
workflow_dispatch:
910

1011
jobs:
1112
build:
@@ -46,7 +47,7 @@ jobs:
4647
shell: bash
4748
run: cmake --build . --parallel ${{steps.core_count.outputs.output}}
4849

49-
- uses: actions/upload-artifact@v3
50+
- uses: actions/upload-artifact@v4
5051
with:
5152
name: ${{ matrix.hardware }}.uf2
52-
path: ${{github.workspace}}/build/*.uf2
53+
path: ${{github.workspace}}/build/*.uf2

src/main.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,10 @@ void tud_resume_cb(void)
126126
// tud_hid_report_complete_cb() is used to send the next report after previous one is complete
127127
void hid_task(void)
128128
{
129-
// Poll every 10ms
129+
// Poll every 100ms
130130
const uint32_t interval_ms = 100;
131131
static uint32_t start_ms = 0;
132+
static uint8_t prev_report[7] = {0}; // Track previous report
132133

133134
if (board_millis() - start_ms < interval_ms)
134135
return; // not enough time
@@ -139,15 +140,16 @@ void hid_task(void)
139140
return;
140141

141142
uint8_t report[7] = {0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00};
142-
143143
report[3] = !gpio_get(BUTTON_1_GPIO);
144144
report[4] = !gpio_get(BUTTON_2_GPIO);
145145
report[5] = !gpio_get(BUTTON_3_GPIO);
146146

147-
// send pedal hid report
148-
tud_hid_report(1, &report, 7);
147+
// Only send the report if there's a change
148+
if (memcmp(report, prev_report, sizeof(report)) != 0) {
149+
tud_hid_report(1, &report, sizeof(report));
150+
memcpy(prev_report, report, sizeof(report));
151+
}
149152
}
150-
151153
// Invoked when sent REPORT successfully to host
152154
// Application can use this to send the next report
153155
// Note: For composite reports, report[0] is report ID
@@ -278,4 +280,4 @@ void neopixel_task(void)
278280
put_pixel(ledColor);
279281
}
280282
}
281-
}
283+
}

0 commit comments

Comments
 (0)