@@ -61,10 +61,6 @@ void TestUpdateRawInputs(CuTest *t)
6161 memset ((s32 * )raw , 0 , sizeof (raw ));
6262 for (int i = 1 ; i <= NUM_TX_INPUTS ; i ++ ) {
6363 TEST_CHAN_SetChannelValue (i , (i + 1 ) * 200 );
64- Model .mixers [i ].src = i ;
65- Model .mixers [i ].dest = i ;
66- Model .mixers [i ].scalar = 100 ;
67- Model .mixers [i ].flags = MUX_REPLACE ;
6864 }
6965 MIXER_UpdateRawInputs ();
7066 s32 expected [] = {
@@ -105,6 +101,161 @@ void TestUpdateRawInputs(CuTest *t)
105101 }
106102}
107103
104+ void TestGetCachedInputs (CuTest * t )
105+ {
106+ s32 cache [NUM_SOURCES + 1 ];
107+ for (int i = 0 ; i < NUM_SOURCES + 1 ; i ++ ) {
108+ cache [i ] = i + 1 ;
109+ raw [i ] = i ;
110+ }
111+ CuAssertIntEquals (t , 0 , MIXER_GetCachedInputs (cache , 1 ));
112+ for (int i = 0 ; i < NUM_SOURCES + 1 ; i ++ ) {
113+ CuAssertIntEquals (t , i + 1 , cache [i ]);
114+ }
115+ CuAssertIntEquals (t , 1 , MIXER_GetCachedInputs (cache , 0 ));
116+ for (int i = 0 ; i < NUM_SOURCES + 1 ; i ++ ) {
117+ //values from 1 - NUM_TX_INPUTS should match raw
118+ CuAssertIntEquals (t , i ? (i <= NUM_TX_INPUTS ? i : i + 1 ) : 1 , cache [i ]);
119+ }
120+ }
121+
122+ void TestCalcChannels (CuTest * t )
123+ {
124+ memset (& Model , 0 , sizeof (Model ));
125+ memset ((s32 * )raw , 0 , sizeof (raw ));
126+ for (int i = 0 ; i < 4 ; i ++ ) {
127+ TEST_CHAN_SetChannelValue (i , (i + 1 ) * 200 );
128+ Model .mixers [i ].src = i + 1 ;
129+ Model .mixers [i ].dest = NUM_OUT_CHANNELS + i ;
130+ Model .mixers [i ].scalar = 100 ;
131+ Model .mixers [i ].flags = MUX_REPLACE ;
132+ }
133+ for (int i = 0 ; i < NUM_OUT_CHANNELS ; i ++ ) {
134+ Model .limits [i ].servoscale = 100 ;
135+ Model .limits [i ].max = 200 ;
136+ Model .limits [i ].min = 200 ;
137+ }
138+ Model .templates [5 ] = MIXERTEMPLATE_CYC1 ;
139+ Model .templates [6 ] = MIXERTEMPLATE_CYC2 ;
140+ Model .templates [7 ] = MIXERTEMPLATE_CYC3 ;
141+ MIXER_CalcChannels ();
142+ s32 expected [NUM_OUT_CHANNELS ] = {0 , 0 , 0 , 0 , 0 , 1000 , 800 , 600 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };
143+ for (int i = 0 ; i < NUM_OUT_CHANNELS ; i ++ ) {
144+ CuAssertIntEquals (t , expected [i ], Channels [i ]);
145+ }
146+ }
147+
148+ void TestGetInputs (CuTest * t )
149+ {
150+ CuAssertPtrEquals (t , (void * )raw , (void * )MIXER_GetInputs ());
151+ }
152+
153+ void TestGetChannel (CuTest * t )
154+ {
155+ memset (& Model , 0 , sizeof (Model ));
156+ memset ((s32 * )raw , 0 , sizeof (raw ));
157+ raw [NUM_INPUTS + 1 ] = 1000 ;
158+ CuAssertIntEquals (t , 1000 , MIXER_GetChannel (0 , 0 ));
159+
160+ Model .num_ppmin = PPM_IN_TRAIN1 << 6 ;
161+ Model .train_sw = INP_GEAR1 ;
162+ raw [Model .train_sw ] = 100 ;
163+ ppmSync = 1 ;
164+ ppmChannels [0 ] = 2000 ;
165+ CuAssertIntEquals (t , 2000 , MIXER_GetChannel (0 , 0 ));
166+
167+ ppmSync = 0 ;
168+ Channels [0 ] = 3000 ;
169+ CuAssertIntEquals (t , 3000 , MIXER_GetChannel (0 , 0 ));
170+ }
171+
172+ void TestGetChannelDisplayScale (CuTest * t )
173+ {
174+ memset (& Model , 0 , sizeof (Model ));
175+ Model .limits [0 ].displayscale = 100 ;
176+ CuAssertIntEquals (t , 100 , MIXER_GetChannelDisplayScale (0 ));
177+ CuAssertIntEquals (t , DEFAULT_DISPLAY_SCALE , MIXER_GetChannelDisplayScale (NUM_OUT_CHANNELS ));
178+ }
179+
180+ void TestGetChannelDisplayFormat (CuTest * t )
181+ {
182+ memset (& Model , 0 , sizeof (Model ));
183+ strcpy (Model .limits [0 ].displayformat , "%" );
184+ CuAssertStrEquals (t , "%" , MIXER_GetChannelDisplayFormat (0 ));
185+ CuAssertStrEquals (t , DEFAULT_DISPLAY_FORMAT , MIXER_GetChannelDisplayFormat (NUM_OUT_CHANNELS ));
186+ }
187+
188+ void TestCreateCyclicOutput (CuTest * t )
189+ {
190+ s32 rawdata [NUM_SOURCES + 1 ] = {0 };
191+ memset (& Model , 0 , sizeof (Model ));
192+ s32 cyc [3 ] = {0 };
193+ rawdata [NUM_INPUTS + NUM_OUT_CHANNELS + 1 ] = 1000 ;
194+ rawdata [NUM_INPUTS + NUM_OUT_CHANNELS + 2 ] = 2000 ;
195+ rawdata [NUM_INPUTS + NUM_OUT_CHANNELS + 3 ] = 3000 ;
196+ MIXER_CreateCyclicOutput (rawdata , cyc );
197+ for (int i = 0 ; i < 3 ; i ++ ) {
198+ CuAssertIntEquals (t , rawdata [NUM_INPUTS + NUM_OUT_CHANNELS + 1 + i ], cyc [i ]);
199+ }
200+ Model .swash_type = SWASH_TYPE_LAST ;
201+ memset (cyc , 0 , sizeof (cyc ));
202+ MIXER_CreateCyclicOutput (rawdata , cyc );
203+ for (int i = 0 ; i < 3 ; i ++ ) {
204+ CuAssertIntEquals (t , rawdata [NUM_INPUTS + NUM_OUT_CHANNELS + 1 + i ], cyc [i ]);
205+ }
206+
207+ Model .swash_invert = SWASH_INV_ELEVATOR_MASK | SWASH_INV_AILERON_MASK | SWASH_INV_COLLECTIVE_MASK ;
208+ memset (cyc , 0 , sizeof (cyc ));
209+ MIXER_CreateCyclicOutput (rawdata , cyc );
210+ for (int i = 0 ; i < 3 ; i ++ ) {
211+ CuAssertIntEquals (t , - rawdata [NUM_INPUTS + NUM_OUT_CHANNELS + 1 + i ], cyc [i ]);
212+ }
213+ Model .swash_invert = 0 ;
214+
215+ Model .swash_type = SWASH_TYPE_120 ;
216+ {
217+ memset (cyc , 0 , sizeof (cyc ));
218+ Model .swashmix [0 ] = 25 ;
219+ Model .swashmix [1 ] = 50 ;
220+ Model .swashmix [2 ] = 75 ;
221+ MIXER_CreateCyclicOutput (rawdata , cyc );
222+ s32 expected [] = {1250 , 3000 , 2500 };
223+ for (int i = 0 ; i < 3 ; i ++ ) {
224+ CuAssertIntEquals (t , expected [i ], cyc [i ]);
225+ }
226+ }
227+
228+ Model .swash_type = SWASH_TYPE_120X ;
229+ {
230+ memset (cyc , 0 , sizeof (cyc ));
231+ MIXER_CreateCyclicOutput (rawdata , cyc );
232+ s32 expected [] = {2000 , 3375 , 1375 };
233+ for (int i = 0 ; i < 3 ; i ++ ) {
234+ CuAssertIntEquals (t , expected [i ], cyc [i ]);
235+ }
236+ }
237+
238+ Model .swash_type = SWASH_TYPE_140 ;
239+ {
240+ memset (cyc , 0 , sizeof (cyc ));
241+ MIXER_CreateCyclicOutput (rawdata , cyc );
242+ s32 expected [] = {1250 , 3500 , 3000 };
243+ for (int i = 0 ; i < 3 ; i ++ ) {
244+ CuAssertIntEquals (t , expected [i ], cyc [i ]);
245+ }
246+ }
247+
248+ Model .swash_type = SWASH_TYPE_90 ;
249+ {
250+ memset (cyc , 0 , sizeof (cyc ));
251+ MIXER_CreateCyclicOutput (rawdata , cyc );
252+ s32 expected [] = {1250 , 2500 , 2000 };
253+ for (int i = 0 ; i < 3 ; i ++ ) {
254+ CuAssertIntEquals (t , expected [i ], cyc [i ]);
255+ }
256+ }
257+ }
258+
108259void TestApplyMixerSimple (CuTest * t )
109260{
110261 struct Mixer initmixer = {
0 commit comments