2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
26 #if defined(SIMULATOR_BUILD) && defined(SIMULATOR_MULTITHREAD)
33 #include "build/build_config.h"
35 #include "common/axis.h"
36 #include "common/utils.h"
38 #include "drivers/accgyro/accgyro.h"
39 #include "drivers/accgyro/accgyro_fake.h"
41 static int16_t fakeGyroADC
[XYZ_AXIS_COUNT
];
42 gyroDev_t
*fakeGyroDev
;
44 static void fakeGyroInit(gyroDev_t
*gyro
)
47 #if defined(SIMULATOR_BUILD) && defined(SIMULATOR_MULTITHREAD)
48 if (pthread_mutex_init(&gyro
->lock
, NULL
) != 0) {
49 printf("Create gyro lock error!\n");
54 void fakeGyroSet(gyroDev_t
*gyro
, int16_t x
, int16_t y
, int16_t z
)
62 gyro
->dataReady
= true;
67 STATIC_UNIT_TESTED
bool fakeGyroRead(gyroDev_t
*gyro
)
70 if (gyro
->dataReady
== false) {
74 gyro
->dataReady
= false;
76 gyro
->gyroADCRaw
[X
] = fakeGyroADC
[X
];
77 gyro
->gyroADCRaw
[Y
] = fakeGyroADC
[Y
];
78 gyro
->gyroADCRaw
[Z
] = fakeGyroADC
[Z
];
84 static bool fakeGyroReadTemperature(gyroDev_t
*gyro
, int16_t *temperatureData
)
87 UNUSED(temperatureData
);
91 bool fakeGyroDetect(gyroDev_t
*gyro
)
93 gyro
->initFn
= fakeGyroInit
;
94 gyro
->readFn
= fakeGyroRead
;
95 gyro
->temperatureFn
= fakeGyroReadTemperature
;
96 #if defined(SIMULATOR_BUILD)
97 gyro
->scale
= GYRO_SCALE_2000DPS
;
103 #endif // USE_FAKE_GYRO
108 static int16_t fakeAccData
[XYZ_AXIS_COUNT
];
109 accDev_t
*fakeAccDev
;
111 static void fakeAccInit(accDev_t
*acc
)
114 #if defined(SIMULATOR_BUILD) && defined(SIMULATOR_MULTITHREAD)
115 if (pthread_mutex_init(&acc
->lock
, NULL
) != 0) {
116 printf("Create acc lock error!\n");
121 void fakeAccSet(accDev_t
*acc
, int16_t x
, int16_t y
, int16_t z
)
129 acc
->dataReady
= true;
134 static bool fakeAccRead(accDev_t
*acc
)
137 if (acc
->dataReady
== false) {
141 acc
->dataReady
= false;
143 acc
->ADCRaw
[X
] = fakeAccData
[X
];
144 acc
->ADCRaw
[Y
] = fakeAccData
[Y
];
145 acc
->ADCRaw
[Z
] = fakeAccData
[Z
];
151 bool fakeAccDetect(accDev_t
*acc
)
153 acc
->initFn
= fakeAccInit
;
154 acc
->readFn
= fakeAccRead
;
155 acc
->revisionCode
= 0;
158 #endif // USE_FAKE_ACC