ReSpeaker DSP V02
Dependencies: mbed MbedJSONValue
Diff: main.cpp
- Revision:
- 3:48258b86e182
- Parent:
- 2:59c1a24aed7c
- Child:
- 4:59319802012b
--- a/main.cpp Mon Feb 19 10:52:46 2018 +0000 +++ b/main.cpp Mon Feb 19 11:50:39 2018 +0000 @@ -6,7 +6,7 @@ Json Format: json:{"name":"dsp","filter":"none","mode":"off"}\r\n */ - + /* Board : Nucleo STM32F446RE @@ -58,7 +58,7 @@ #define DEBUG_MOD2 // json parse #define DEBUG_MOD3 // dsp handler #define DEBUG_MOD10 // responsivity msges to gui -//#define DEBUG_MOD11 // loop frequency indicator +#define DEBUG_MOD11 // loop frequency indicator // Sine generator #define PI_DOUBLE (3.141592653589793238462) @@ -130,6 +130,11 @@ typedef void(*functionPtr)(void); functionPtr FilterFunction; +// alternative functuin selection (faster mcu process) +uint8_t operationMode = 0; +// 0 - no filter +// 1 - High Pass filter + /////////////// // Functions // /////////////// @@ -190,15 +195,22 @@ /////////////////////// while(1) { // run selected filter - FilterFunction(); - + if (operationMode == 0) { + no_filter(); + } else if (operationMode == 1) { + highpass_filter(); + //pc.printf("Mode: %d \r\n", operationMode); + //wait(0.1); + } + // more elegant but much slower option: + //FilterFunction(); #ifdef DEBUG_MOD11 // toggle pin, Loop frequency indicator toggelState=!toggelState; mytoggle.write(toggelState); #endif - } -} + } // end loop +} // end main /////////////// // Functions // @@ -219,8 +231,8 @@ Dac_Reg += __HAL_DHR12R1_ALIGNEMENT(DAC_ALIGN_12B_R); // intialize filter function pointer - FilterFunction = no_filter;//highpath_filter;//no_filter; - + FilterFunction = no_filter;//highpass_filter;//no_filter; + operationMode = 0 ; } // Serial Event function @@ -388,11 +400,14 @@ // selected operation mode if ( filterType == "none" ) { FilterFunction = no_filter; + operationMode = 0 ; } else if( filterType == "hpf" ) { - FilterFunction = highpath_filter; + FilterFunction = highpass_filter; + operationMode = 1 ; } else { switch_dsp.printf("undefined filter %s \r\n", filterType.c_str()); FilterFunction = no_filter; + operationMode = 0 ; } // selected operation mode