@@ -195,41 +195,30 @@ static void send_hid_report(uint8_t report_id, uint32_t btn)
195195 }
196196 }
197197 break ;
198- default : break ;
199- }
200- }
201-
202- /* use this to send stylus touch signal through USB. */
203- static void send_stylus_touch (uint16_t x , uint16_t y , bool state )
204- {
205- // skip if hid is not ready yet
206- if ( !tud_hid_ready () ) return ;
207-
208- static bool has_stylus_pen = false;
209-
210- hid_stylus_report_t report =
211- {
212- .attr = 0 ,
213- .x = 0 ,
214- .y = 0
215- };
216-
217- report .x = x ;
218- report .y = y ;
219198
220- if (state )
221- {
222- report .attr = STYLUS_ATTR_TIP_SWITCH | STYLUS_ATTR_IN_RANGE ;
223- tud_hid_report (REPORT_ID_STYLUS_PEN , & report , sizeof (report ));
199+ case REPORT_ID_STYLUS_PEN : {
200+ static bool touch_state = false;
201+ hid_stylus_report_t report = {
202+ .attr = 0 ,
203+ .x = 0 ,
204+ .y = 0
205+ };
224206
225- has_stylus_pen = true;
226- }else
227- {
228- report .attr = 0 ;
229- if (has_stylus_pen ) tud_hid_report (REPORT_ID_STYLUS_PEN , & report , sizeof (report ));
230- has_stylus_pen = false;
207+ if (btn ) {
208+ report .attr = STYLUS_ATTR_TIP_SWITCH | STYLUS_ATTR_IN_RANGE ;
209+ report .x = 100 ;
210+ report .y = 100 ;
211+ tud_hid_report (REPORT_ID_STYLUS_PEN , & report , sizeof (report ));
212+ touch_state = true;
213+ } else {
214+ report .attr = 0 ;
215+ if (touch_state ) tud_hid_report (REPORT_ID_STYLUS_PEN , & report , sizeof (report ));
216+ touch_state = false;
217+ }
218+ }
219+ break ;
220+ default : break ;
231221 }
232-
233222}
234223
235224// Every 10ms, we will sent 1 report for each HID profile (keyboard, mouse etc ..)
@@ -239,14 +228,6 @@ void hid_task(void)
239228 // Poll every 10ms
240229 const uint32_t interval_ms = 10 ;
241230 static uint32_t start_ms = 0 ;
242- static uint32_t touch_ms = 0 ;
243- static bool touch_state = false;
244-
245- if (board_millis () - touch_ms < 100 ) {
246- touch_ms = board_millis ();
247- send_stylus_touch (0 , 0 , touch_state = !touch_state );
248- return ;
249- }
250231
251232 if ( board_millis () - start_ms < interval_ms ) return ; // not enough time
252233 start_ms += interval_ms ;
0 commit comments