@@ -68,10 +68,40 @@ bool ffPrintGamepad(FFGamepadOptions* options)
6868 return false;
6969 }
7070
71+ FF_LIST_AUTO_DESTROY filtered = ffListCreate (sizeof (FFGamepadDevice * ));
72+ FF_LIST_FOR_EACH (FFGamepadDevice , device , result )
73+ {
74+ bool ignored = false;
75+ FF_LIST_FOR_EACH (FFstrbuf , ignore , options -> ignores )
76+ {
77+ if (ffStrbufStartsWithIgnCase (& device -> name , ignore ))
78+ {
79+ ignored = true;
80+ break ;
81+ }
82+ }
83+ if (!ignored )
84+ {
85+ FFGamepadDevice * * ptr = ffListAdd (& filtered );
86+ * ptr = device ;
87+ }
88+ }
89+
90+ if (!filtered .length )
91+ {
92+ ffPrintError (FF_GAMEPAD_MODULE_NAME , 0 , & options -> moduleArgs , FF_PRINT_TYPE_DEFAULT , "All devices are ignored" );
93+ return false;
94+ }
95+
7196 uint8_t index = 0 ;
97+ FF_LIST_FOR_EACH (FFGamepadDevice * , pdevice , filtered )
98+ {
99+ FFGamepadDevice * device = * pdevice ;
100+ printDevice (options , device , filtered .length > 1 ? ++ index : 0 );
101+ }
102+
72103 FF_LIST_FOR_EACH (FFGamepadDevice , device , result )
73104 {
74- printDevice (options , device , result .length > 1 ? ++ index : 0 );
75105 ffStrbufDestroy (& device -> serial );
76106 ffStrbufDestroy (& device -> name );
77107 }
@@ -88,6 +118,21 @@ void ffParseGamepadJsonObject(FFGamepadOptions* options, yyjson_val* module)
88118 if (ffJsonConfigParseModuleArgs (key , val , & options -> moduleArgs ))
89119 continue ;
90120
121+ if (unsafe_yyjson_equals_str (key , "ignores" ))
122+ {
123+ yyjson_val * elem ;
124+ size_t eidx , emax ;
125+ yyjson_arr_foreach (val , eidx , emax , elem )
126+ {
127+ if (yyjson_is_str (elem ))
128+ {
129+ FFstrbuf * strbuf = ffListAdd (& options -> ignores );
130+ ffStrbufInitJsonVal (strbuf , elem );
131+ }
132+ }
133+ continue ;
134+ }
135+
91136 if (ffPercentParseJsonObject (key , val , & options -> percent ))
92137 continue ;
93138
@@ -99,6 +144,12 @@ void ffGenerateGamepadJsonConfig(FFGamepadOptions* options, yyjson_mut_doc* doc,
99144{
100145 ffJsonConfigGenerateModuleArgsConfig (doc , module , & options -> moduleArgs );
101146
147+ if (options -> ignores .length > 0 )
148+ {
149+ yyjson_mut_val * ignores = yyjson_mut_obj_add_arr (doc , module , "ignores" );
150+ FF_LIST_FOR_EACH (FFstrbuf , strbuf , options -> ignores )
151+ yyjson_mut_arr_append (ignores , yyjson_mut_strncpy (doc , strbuf -> chars , strbuf -> length ));
152+ }
102153 ffPercentGenerateJsonConfig (doc , module , options -> percent );
103154}
104155
@@ -120,6 +171,17 @@ bool ffGenerateGamepadJsonResult(FF_MAYBE_UNUSED FFGamepadOptions* options, yyjs
120171 yyjson_mut_val * obj = yyjson_mut_arr_add_obj (doc , arr );
121172 yyjson_mut_obj_add_strbuf (doc , obj , "serial" , & device -> serial );
122173 yyjson_mut_obj_add_strbuf (doc , obj , "name" , & device -> name );
174+
175+ bool ignored = false;
176+ FF_LIST_FOR_EACH (FFstrbuf , ignore , options -> ignores )
177+ {
178+ if (ffStrbufStartsWithIgnCase (& device -> name , ignore ))
179+ {
180+ ignored = true;
181+ break ;
182+ }
183+ }
184+ yyjson_mut_obj_add_bool (doc , obj , "ignored" , ignored );
123185 }
124186
125187 FF_LIST_FOR_EACH (FFGamepadDevice , device , result )
@@ -134,12 +196,18 @@ bool ffGenerateGamepadJsonResult(FF_MAYBE_UNUSED FFGamepadOptions* options, yyjs
134196void ffInitGamepadOptions (FFGamepadOptions * options )
135197{
136198 ffOptionInitModuleArg (& options -> moduleArgs , "" );
199+
200+ ffListInit (& options -> ignores , sizeof (FFstrbuf ));
137201 options -> percent = (FFPercentageModuleConfig ) { 50 , 20 , 0 };
138202}
139203
140204void ffDestroyGamepadOptions (FFGamepadOptions * options )
141205{
142206 ffOptionDestroyModuleArg (& options -> moduleArgs );
207+
208+ FF_LIST_FOR_EACH (FFstrbuf , str , options -> ignores )
209+ ffStrbufDestroy (str );
210+ ffListDestroy (& options -> ignores );
143211}
144212
145213FFModuleBaseInfo ffGamepadModuleInfo = {
0 commit comments