Two development boards transmit control information through ble. One development board connects to paj7620 and provides gesture information through IIC bus. The other development board uses ble and USB HID. Ble is used to receive data, and USB HID is used to simulate keyboard input and control ppt
Figure 1
We need two development boards qn908x and gesture control device paj7620. We use IAR as development enviroment.The example we use is temperature_sensor, and
temperature_ colloctor. The SDK version is 2.2.3
3.1 temperature_sensor code
We want to implement IIC to read gesture information from paj7620 and send data.
The pins used by IIC are PA6 and PA7
Simply encapsulate the IIC reading and writing code in the code to create i2c_ operation.c and i2c_ operation.h. Realize IIC initialization and reading / writing register function in it
Figure 2
Figure 3
3.1.1 After having these functions, we begin to write gesture recognition code. First, we add two blank files paj7620.c and paj7620.h into our project.
Select bank register area
Figure 4
Wake up paj7620 to read device state
Figure 5
Initialize device
Figure 6
Gesture test function
Figure 7
3.1.2 When you are ready to read the device information,
You should initialize IIC and paj7620 in BleApp_Init function
Figure 8
In principle, we need to create a custom service for the PAJ device, but we replace the temperature data as our gesture control data. If you want to create a custom service, refer to this link custom profile
3.1.3 Create a timer that sends gesture data regularly.
In file temerature_sensor.c
Define a timer,static tmrTimerID_t dataTimerId;
Allocate a timer, dataTimerId = TMR_AllocateTimer();
Define the callback function of this timer
Figure 9
Start timer
Figure 10
Close the low power mode. #define cPWR_UsePowerDownMode 0
The most important thing here is to port USB HID into our project. The USB example
we use is the USB keyboard and mouse.
3.2.1 Add the OSA and USB folder under the example to the project directory, and copy the file to the corresponding folder according to the file structure of the original example.
Figure 11
3.2.2 Add header file directory after completion
Figure 12
At the same time, in this tab, add two macro definitions
USB_STACK_FREERTOS_HEAP_SIZE=16384
USB_STACK_FREERTOS
3.2.3 Next, we need to modify the main function in usb example . Open composite.c file.
Figure 13
It calls the APP_task. So this function also need to be modified.
Figure 14
3.2.4Find hid_mouse.c,Comment function USB_DeviceHidMouseAction
Find hid_keyboard.h. Define the gesture information.
Figure 15
Find hid_keyboard.c. We need to modify the function USB_DeviceHidKeyboardAction as following figure.
Figure 16
Among them, we also need to implement the following function. When the up hand gesture is detected, the previous ppt will be played. The down hand gesture will be the next PPT, the left hand gesture will exit PPT, and the forward hand gesture will play ppt
Figure 17
It also refers to an external variable gesture_from_server. The variable definition
is in file temperature_ collocation.c,.
3.2.5 After that, let's go to BleApp_Statemachinehandler function
in temperature_colloctor.c.
In case mApppRunning_c, we will call usb_main to initialize USB HID
Figure 18
3.2.6 In BleApp_PrintTemperature, we will save the gesture data to gesture_from_server
Figure 19
We finished the all steps.