1212#include " cppmain.h"
1313
1414
15- HidFFB::HidFFB () {
15+ HidFFB::HidFFB (EffectsCalculator &ec) : effects_calc(&ec), effects(ec.effects)
16+ {
1617
1718 // Initialize reports
1819 blockLoad_report.effectBlockIndex = 1 ;
19- blockLoad_report.ramPoolAvailable = (MAX_EFFECTS -used_effects)*sizeof (FFB_Effect);
20+ blockLoad_report.ramPoolAvailable = (effects. size () -used_effects)*sizeof (FFB_Effect);
2021 blockLoad_report.loadStatus = 1 ;
2122
22- pool_report.ramPoolSize = MAX_EFFECTS *sizeof (FFB_Effect);
23- pool_report.maxSimultaneousEffects = MAX_EFFECTS ;
23+ pool_report.ramPoolSize = effects. size () *sizeof (FFB_Effect);
24+ pool_report.maxSimultaneousEffects = effects. size () ;
2425 pool_report.memoryManagement = 1 ;
2526
2627
@@ -30,12 +31,6 @@ HidFFB::HidFFB() {
3031HidFFB::~HidFFB () {
3132}
3233
33- void HidFFB::setEffectsCalculator (EffectsCalculator *ec) {
34- this ->effects_calc = ec;
35- assert (effects_calc != nullptr );
36- this ->effects_calc ->setEffectsArray (this ->effects );
37- this ->effects_calc ->setActive (this ->ffb_active );
38- }
3934
4035
4136bool HidFFB::getFfbActive (){
@@ -169,7 +164,7 @@ void HidFFB::hidOut(uint8_t report_id, hid_report_type_t report_type, uint8_t co
169164
170165
171166void HidFFB::free_effect (uint16_t idx){
172- if (idx < MAX_EFFECTS ){
167+ if (idx < this -> effects . size () ){
173168 effects_calc->logEffectType (effects[idx].type , true ); // Effect off
174169 effects[idx].type =FFB_EFFECT_NONE;
175170 for (int i=0 ; i< MAX_AXIS; i++) {
@@ -263,7 +258,7 @@ void HidFFB::ffb_control(uint8_t cmd){
263258
264259
265260void HidFFB::set_constant_effect (FFB_SetConstantForce_Data_t* data){
266- if (data->effectBlockIndex == 0 || data->effectBlockIndex > MAX_EFFECTS ){
261+ if (data->effectBlockIndex == 0 || data->effectBlockIndex > effects. size () ){
267262 return ;
268263 }
269264 cfUpdatePeriodAvg.addValue ((uint32_t )(HAL_GetTick () - lastCfUpdate));
@@ -302,15 +297,15 @@ void HidFFB::new_effect(FFB_CreateNewEffect_Feature_Data_t* effect){
302297 // reportFFBStatus.effectBlockIndex = index;
303298 blockLoad_report.effectBlockIndex = index;
304299 used_effects++;
305- blockLoad_report.ramPoolAvailable = (MAX_EFFECTS -used_effects)*sizeof (FFB_Effect);
300+ blockLoad_report.ramPoolAvailable = (effects. size () -used_effects)*sizeof (FFB_Effect);
306301 blockLoad_report.loadStatus = 1 ;
307302 sendStatusReport (index);
308303
309304
310305}
311306void HidFFB::set_effect (FFB_SetEffect_t* effect){
312307 uint8_t index = effect->effectBlockIndex ;
313- if (index > MAX_EFFECTS || index == 0 )
308+ if (index > effects. size () || index == 0 )
314309 return ;
315310
316311 FFB_Effect* effect_p = &effects[index-1 ];
@@ -344,7 +339,7 @@ void HidFFB::set_effect(FFB_SetEffect_t* effect){
344339}
345340
346341void HidFFB::set_condition (FFB_SetCondition_Data_t *cond){
347- if (cond->effectBlockIndex == 0 || cond->effectBlockIndex > MAX_EFFECTS ){
342+ if (cond->effectBlockIndex == 0 || cond->effectBlockIndex > effects. size () ){
348343 return ;
349344 }
350345 uint8_t axis = cond->parameterBlockOffset ;
@@ -368,7 +363,7 @@ void HidFFB::set_condition(FFB_SetCondition_Data_t *cond){
368363}
369364
370365void HidFFB::set_effect_operation (FFB_EffOp_Data_t* report){
371- if (report->effectBlockIndex == 0 || report->effectBlockIndex > MAX_EFFECTS ){
366+ if (report->effectBlockIndex == 0 || report->effectBlockIndex > effects. size () ){
372367 return ; // Invalid ID
373368 }
374369 // Start or stop effect
@@ -407,7 +402,7 @@ void HidFFB::set_effect_operation(FFB_EffOp_Data_t* report){
407402
408403
409404void HidFFB::set_envelope (FFB_SetEnvelope_Data_t *report){
410- if (report->effectBlockIndex == 0 || report->effectBlockIndex > MAX_EFFECTS ){
405+ if (report->effectBlockIndex == 0 || report->effectBlockIndex > effects. size () ){
411406 return ;
412407 }
413408 FFB_Effect *effect = &effects[report->effectBlockIndex - 1 ];
@@ -420,7 +415,7 @@ void HidFFB::set_envelope(FFB_SetEnvelope_Data_t *report){
420415}
421416
422417void HidFFB::set_ramp (FFB_SetRamp_Data_t *report){
423- if (report->effectBlockIndex == 0 || report->effectBlockIndex > MAX_EFFECTS ){
418+ if (report->effectBlockIndex == 0 || report->effectBlockIndex > effects. size () ){
424419 return ;
425420 }
426421 FFB_Effect *effect = &effects[report->effectBlockIndex - 1 ];
@@ -430,7 +425,7 @@ void HidFFB::set_ramp(FFB_SetRamp_Data_t *report){
430425}
431426
432427void HidFFB::set_periodic (FFB_SetPeriodic_Data_t* report){
433- if (report->effectBlockIndex == 0 || report->effectBlockIndex > MAX_EFFECTS ){
428+ if (report->effectBlockIndex == 0 || report->effectBlockIndex > effects. size () ){
434429 return ;
435430 }
436431 FFB_Effect* effect = &effects[report->effectBlockIndex -1 ];
@@ -443,7 +438,7 @@ void HidFFB::set_periodic(FFB_SetPeriodic_Data_t* report){
443438}
444439
445440uint8_t HidFFB::find_free_effect (uint8_t type){ // Will return the first effect index which is empty or the same type
446- for (uint8_t i=0 ;i<MAX_EFFECTS ;i++){
441+ for (uint8_t i=0 ;i<effects. size () ;i++){
447442 if (effects[i].type == FFB_EFFECT_NONE){
448443 return (i+1 );
449444 }
@@ -452,7 +447,7 @@ uint8_t HidFFB::find_free_effect(uint8_t type){ //Will return the first effect i
452447}
453448
454449void HidFFB::reset_ffb (){
455- for (uint8_t i=0 ;i<MAX_EFFECTS ;i++){
450+ for (uint8_t i=0 ;i<effects. size () ;i++){
456451 free_effect (i);
457452 }
458453 // this->reportFFBStatus.effectBlockIndex = 1;
0 commit comments