The keyboard Bluetooth module DIY guide version 0.3 based on the Neptune development board realizes the "touch" connection and supports the compilation and burning of HUAWEI DevEco Device Tool under Linux. I typed a word on my phone to reply. I always pressed the wrong one after another because the switch between upper and lower case was too "secret"? Login is something to answer, phone typing is not easy, computer login is too difficult? Operate multiple devices at the same time, switch multiple keyboards back and forth to make yourself confused? At this time, developers may need an enhanced version of the peripheral keyboard, not only the mobile phone is easily connected, but also supports simultaneous connection of multiple devices.
1 Introduction
In the previous tweet, we have brought developers version 0.1 of the DIY guide for the keyboard Bluetooth module based on the Runhe Neptune development board (hereinafter referred to as the Neptune development board), and transform the wired keyboard into a Bluetooth keyboard, so that one keyboard can be multi-operated The system/terminal device recognizes the function used. After several months of updates, this time we bring you the v0.3 version of the keyboard Bluetooth module DIY guide based on the Neptune development board, which brings you several heavy updates:
1. Support the "touch" connection of mobile phones equipped with HarmonyOS system
2. Support HUAWEI DevEco Device Tool one-stop compilation and burning
- Based on the original support for 4 OSs (HarmonyOS, Windows, Linux, Android), initial support for ios is newly added
4. From the original support for up to 2 devices to the current support for up to 5 devices to switch freely
More project update details can be viewed through the link below:
https://gitee.com/openharmony-sig/vendor_oh_fun/tree/master/hihope_neptune-oh_hid
In the previous version, we have learned about the hardware environment construction and USB serial port (CH340) acquisition and other related information. This time let us focus on the implementation of the "touch" and HUAWEI DevEco Device Tool that developers are most concerned about. One-stop compiling and burning steps, let us understand it together~
2. The realization of "touch"
2.1 Interpreting the realization of "touch" from the perspective of experience
The schematic diagram of the user using "touch" to realize the Bluetooth keyboard connection is as follows:
The user pulls up the FA application by touching the NFC tag
Get the MAC information of the Bluetooth device (development board);
At the same time, the Bluetooth scan in the mobile phone will compare the acquired Bluetooth list with the MAC information of the development board;
When the MAC information of the same development board is matched, the Bluetooth connection result will be fed back, and the Bluetooth device will be connected;
At the same time, the result of a successful connection will be notified to the user through the FA application that is pulled up, and the user can see the prompt of the successful connection on the interface. The effect can be seen video
2.2 Interpreting the realization of "touch one touch" from the perspective of principle
In this process, touching the NFC tag can pull up the FA application and obtain the MAC address of the development board. The key point is that the FA application information and the MAC address of the development board have been written into the NFC tag. The user turns on the NFC switch on the phone, The mobile phone can read the relevant information when it is in the NFC tag, pull up the FA application and obtain the MAC address of the development board for matching.
However, what is actually written into the NFC tag is the Product ID of the FA application (you need to apply for it in Huawei’s official “App Debugging Assistant” APP). After the application is completed, pass the Huawei Quick Service Smart Platform (the following and the figure are abbreviated as HAG) Create and publish the FA service, associate the Product ID with the FA application package name, and the developer writes the Product ID into the NFC tag. When the user touches the NFC tag, the HAG terminal will query the corresponding product ID Name the package and pull it up.
The Bluetooth device obtains the device MAC address code through the tool, and writes the MAC address code into the NFC tag. When the user touches the NFC tag, the MAC address code written into it will be obtained, which matches and connects with the current Bluetooth list of the mobile phone. Bluetooth devices with the same MAC address.
Let us analyze this process in detail. Since we already have a Product ID and the service has been released, we will focus on how to implement the FA application information and the process of writing the MAC address of the development board to the NFC tag.
2.3 Learning from the hands-on process to "touch one touch" to achieve
Next, let us learn more about the FA application information and the process of writing the MAC address of the development board to the NFC tag.
2.3.1. Understand the structure of sample data written to NFC
We will provide developers with a sample structure of data for writing to NFC. Developers only need to make a small amount of changes to write directly into the NFC tag.
The data sample structure string is as follows:
D20C1A6170702F68776F6E65686F702001004800393935330081060005200685919106286DCD824FEF
in:
39393533 represents the Ascill code of 9953, 9953 is the Product Id that we have applied for for the FA application;
286DCD824FEF is used to represent the hardware code (MAC address) of the BLE device. We will obtain the MAC address of the target BLE device and replace it in the future;
2.3.2. Get the MAC address of the BLE device
Install the "BLE Debug Assistant" in the "Huawei App Market" (this tool is used to obtain the MAC address of the target ble device), open the modification tool, find the Bluetooth keyboard, and obtain the MAC address of the Bluetooth keyboard: 286DCD7C0E67
2.3.3 Replace the MAC address of the target device
Replace the MAC address obtained through the BLE debugging assistant in 2.3.2: 286DCD7C0E67 with the MAC address of the sample: 286DCD824FEF, and the assembled string is:
D20C1A6170702F68776F6E65686F702001004800393935330081060005200685919106286DCD7C0E67
2.3.4 Use HW AirLink tool to write NFC
1) Install HW AirLink tool
We will download the NFC writing tool HW AirLink, the download link is as follows:
After downloading and decompressing, use the cmd command line tool to open the Windows device (please ensure that the adb tool is installed on the Windows device) to install, and execute the following command to complete the installation:
adb –r –d hilinkcert-tool-1.0.0.3.apk
As shown in the figure:
After the installation is complete, as shown in the figure:
2) Enter the invitation code
After opening the tool, click "add", you will be asked to enter an invitation code, enter "b4zd8bz3":
3) Put into the buffer area
Click NFC, select NFC WRITE among them, and enter the NFC data input area. At this time, the status is "Buffer area to be written":
Check "byte code", and replace the assembled string obtained in step 3
D20C1A6170702F68776F6E65686F702001004800393935330081060005200685919106286DCD7C0E67
Enter it and click "Put into Cache", the status is "Written into Cache" at this time.
4) Write NFC sticker
Install the developed FA application on the phone, turn on the NFC function of the phone, and use the back of the phone (NFC sensor) to approach the designated NFC tag to complete the writing.
Please note that you need to close the mobile network when writing, and try to use a blank NFC tag for writing.
After the writing is completed, the "Write Successful" pop-up box will pop up at the bottom of HW AirLink, which means that the writing is successful.
At this point, we have a clear understanding of how to touch the NFC to pull up the FA application and complete the pairing of the Bluetooth keyboard. Then let us enter the second key update-how to use HUAWEI DevEco Device Tool (hereinafter referred to as DevEco Device Tool) under the Linux platform to complete the compilation and burning in one stop.
3. The realization of one-stop compilation and burning
This time we will use Huawei DevEco Device Tool (V2.2.0 Beta1) to compile and burn the W800 development board corresponding to the Bluetooth keyboard module in the Linux environment.
3.1 Compile
3.1.1. HPM environment setup
HPM (harmony package manager) is the Harmony package manager. It is a component package manager launched by Huawei Harmony. You can easily obtain the required components from the official website and download only the components used in the current project as needed, making the project files more streamlined.
We will build and compile the environment under the Linux environment, choose to install the tools under Ubuntu, and prepare to download and configure the software according to the development environment. For the preparation of the Ubuntu development environment, please refer to the following link, we will not go into details here.
· Ubuntu development environment preparation
https://device.harmonyos.com/cn/docs/ide/user-guides/install_ubuntu-0000001072959308
Note: If some steps fail to execute, please restart ubuntu and try again.
3.1.2 HPM pull source code
After the hpm development environment is set up, first enter in Ubuntu:
hpm init -t dist
Realize directory initialization, as shown in the figure:
enter:
hpm i @hihope/neptune_bluetoothkeyboard
Download the corresponding components and dependent packages, as shown in the figure:
After the execution is completed, "Installed" is displayed, indicating successful download, as shown in the figure:
Finally, execute the compile command
hpm dist
As shown in the figure:
After the execution is completed, it displays: "Build success!", which means the compilation is successful, as shown in the figure:
The compiled img file is located in the out directory, as shown in the figure:
Open the "out/neptune/wifiiot_neptune/" folder, you can find the "w800.img" file, which is the generated firmware, as shown in the figure:
3.2 Burn
3.2.1. Get the compiled firmware
In the same way, this time we will complete the burning in the Linux environment. We will burn the firmware of the "w800.img" file in the "out/neptune/wifiiot_neptune/" folder. At the same time, we also provide developers with compiled firmware, which can be obtained at the following link:
https://gitee.com/openharmony-sig/vendor_oh_fun/tree/master/hihope_neptune-oh_hid
3.2.2 Firmware burning
The detailed steps of the firmware burning process in Linux environment are as follows:
1) Connect the Neptune development board to the virtual machine through the serial port
Connect the Neptune development board to the USB port of the computer through the serial port. As shown in the figure:
In the pop-up "New USB Device Detected" window, choose to connect to the virtual machine, choose Ubuntu64 for the virtual machine name, and click OK.
Open VMware, click on in turn: virtual machine->removable device->QinHeng USB Serial->display in the status bar, check whether it is displayed, as shown in the figure:
At this point, the Neptune development board has successfully connected to the virtual machine through the serial port.
2) Create a new Device Tool project
DevEco Device Tool is deployed on Visual Studio Code as a plug-in, so we need to open "Extentions" in Visual Studio Code first, find and open DevEco Device Tool, click "New DevEco Project" to create a new project, and enter the relevant information of the project:
Project name: Name (custom)
Development board model: Board (select w800), currently we are using W800 development board
Bundle (choose @hihope/neptune_iot), as shown in the figure:
3) Set the location of burning firmware
Click Partiton Configuration (step ①), click the folder icon (step ②), as shown in the figure:
Find the folder location where the firmware is located (you can customize the path, please copy the target firmware to this location in advance), as shown in the figure:
Select the target firmware "OpenHarmony_HID_V0.3.img" (step ①), click the button: "Open "OpenHarmony_HID_V0.3.img" (step ②), as shown in the figure:
Click Save to save.
After completing the board selection and burning firmware location setting, we need to configure the port and burning protocol.
4) Set the port and burning protocol
Click: "w800", as shown in the figure:
Set the burning port, upload_port, select the default value "/dev/ttyUSB0", if not, you can enter "/dev/ttyUSB0"
Fill in the burning protocol, upload_protocol, select "xmodem", that is, select the file transfer protocol for serial communication.
Set upload_partitions, select "partition:w800_app", that is, select which file you want to burn. The selection result is shown in the figure:
After the configuration is complete, click Save to save the configuration.
5) View the opened project
Click Open to open the project. Click the Explorer icon in the upper left corner of Visual Studio Code to view the opened project:
Remove irrelevant items to prevent compilation exceptions, as shown in the figure:
6) Burn the firmware
Click DevEco, and select Upload in the pop-up PROJECT TASKS, as shown in the figure:
According to the prompt "Please reset the board", click the RST button of the development board, as shown in the figure:
At this time, it will show that the programming is in progress. When the progress bar shows 100% and the word "SUCCESS" appears below, it means that the programming is successful, as shown in the figure:
4. End
After multiple versions of the update, the keyboard Bluetooth module 0.3 version based on the Neptune development board will bring developers a touch to pull up the FA, realize the connection of the mobile phone and the keyboard through Bluetooth, so that the keyboard becomes a mobile phone peripheral. Control the phone input, and the program that realizes this version has been burned into it, and the writing of the NFC tag has also been realized. You can download the detailed "operation document" on gitee to understand~ At the same time, developers can use DevEco in the Linux environment. Device Tool compiles and burns the development board (W800), interested developers should try this new version quickly~
HarmonyOS development journey
▼▼▼Fun development board open source community link▼▼▼
https://gitee.com/openharmony-sig/vendor_oh_fun
▼▼▼Scan the QR code to register a Huawei account, start the HarmonyOS development journey, and get the latest learning resources. ▼▼▼
▼▼▼Download DevEco Studio on PC▼▼▼
▼▼▼Experience the fun of distributed development in all scenarios▼▼▼
https://device.harmonyos.com/cn/ide#download
Welcome partners and developers to join HarmonyOS
Every developer is the spark of fire we want to gather
Together to create infinite possibilities in the era of Internet of Everything
Original link: https://developer.huawei.com/consumer/cn/forum/topic/0202624226147860150?fid=0101587865002800104
Original author: HarmonyOS Device
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。