@@ -59,16 +59,44 @@ void usb_host_task(device_t *state) {
5959 tuh_task ();
6060}
6161
62+ mouse_report_t * screensaver_pong (device_t * state ) {
63+ static mouse_report_t report = {0 };
64+ static int dx = 20 , dy = 25 ;
65+
66+ /* Check if we are bouncing off the walls and reverse direction in that case. */
67+ if (report .x + dx < MIN_SCREEN_COORD || report .x + dx > MAX_SCREEN_COORD )
68+ dx = - dx ;
69+
70+ if (report .y + dy < MIN_SCREEN_COORD || report .y + dy > MAX_SCREEN_COORD )
71+ dy = - dy ;
72+
73+ report .x += dx ;
74+ report .y += dy ;
75+
76+ return & report ;
77+ }
78+
79+ mouse_report_t * screensaver_jitter (device_t * state ) {
80+ const int16_t jitter_distance = 2 ;
81+ static mouse_report_t report = {
82+ .x = jitter_distance ,
83+ .y = jitter_distance ,
84+ .mode = RELATIVE ,
85+ };
86+
87+ report .x = - report .x ;
88+ report .y = - report .y ;
89+
90+ return & report ;
91+ }
92+
6293/* Have something fun and entertaining when idle. */
6394void screensaver_task (device_t * state ) {
6495 const int mouse_move_delay = 5000 ;
96+ static int last_pointer_move = 0 ;
6597 screensaver_t * screensaver = & state -> config .output [BOARD_ROLE ].screensaver ;
6698 uint64_t inactivity_period = time_us_64 () - state -> last_activity [BOARD_ROLE ];
6799
68- static mouse_report_t report = {0 };
69- static int last_pointer_move = 0 ;
70- static int dx = 20 , dy = 25 , jitter = 1 ;
71-
72100 /* If we're not enabled, nothing to do here. */
73101 if (screensaver -> mode == DISABLED )
74102 return ;
@@ -90,29 +118,22 @@ void screensaver_task(device_t *state) {
90118 if ((time_us_32 ()) - last_pointer_move < mouse_move_delay )
91119 return ;
92120
121+ mouse_report_t * report ;
93122 switch (screensaver -> mode ) {
94123 case PONG :
95- /* Check if we are bouncing off the walls and reverse direction in that case. */
96- if (report .x + dx < MIN_SCREEN_COORD || report .x + dx > MAX_SCREEN_COORD )
97- dx = - dx ;
98-
99- if (report .y + dy < MIN_SCREEN_COORD || report .y + dy > MAX_SCREEN_COORD )
100- dy = - dy ;
101-
102- report .x += dx ;
103- report .y += dy ;
104-
124+ report = screensaver_pong (state );
105125 break ;
106126
107127 case JITTER :
108- report .x = state -> pointer_x + jitter ;
109- report .y = state -> pointer_y + jitter ;
110- jitter = - jitter ;
128+ report = screensaver_jitter (state );
111129 break ;
130+
131+ default :
132+ return ;
112133 }
113134
114135 /* Move mouse pointer */
115- queue_mouse_report (& report , state );
136+ queue_mouse_report (report , state );
116137
117138 /* Update timer of the last pointer move */
118139 last_pointer_move = time_us_32 ();
0 commit comments