|
1 | 1 | /*
|
2 |
| - * Sets BLE characteristic options |
3 |
| - * Use BLE Scanner etc on Android to see them |
4 |
| - */ |
| 2 | + Sets BLE characteristic options |
| 3 | + Use BLE Scanner etc on Android to see them |
| 4 | +
|
| 5 | + Also shows how to set transmit power during initial configuration, |
| 6 | + or at any stage whilst running by using bleGamepad.setTXPowerLevel(int8_t) |
| 7 | +
|
| 8 | + The only valid values are: -12, -9, -6, -3, 0, 3, 6 and 9 |
| 9 | + Values correlate to dbm |
| 10 | +
|
| 11 | + You can get the currently set TX power level by calling bleGamepad.setTXPowerLevel() |
| 12 | +
|
| 13 | +*/ |
5 | 14 |
|
6 | 15 | #include <Arduino.h>
|
7 | 16 | #include <BleGamepad.h>
|
8 | 17 |
|
| 18 | +int8_t txPowerLevel = 3; |
| 19 | + |
9 | 20 | BleGamepad bleGamepad("Custom Contoller Name", "lemmingDev", 100); // Set custom device name, manufacturer and initial battery level
|
10 | 21 | BleGamepadConfiguration bleGamepadConfig; // Create a BleGamepadConfiguration object to store all of the options
|
11 |
| - |
| 22 | + |
12 | 23 | void setup()
|
13 | 24 | {
|
14 |
| - Serial.begin(115200); |
15 |
| - Serial.println("Starting BLE work!"); |
16 |
| - bleGamepadConfig.setAutoReport(false); |
17 |
| - bleGamepadConfig.setControllerType(CONTROLLER_TYPE_GAMEPAD); // CONTROLLER_TYPE_JOYSTICK, CONTROLLER_TYPE_GAMEPAD (DEFAULT), CONTROLLER_TYPE_MULTI_AXIS |
18 |
| - bleGamepadConfig.setVid(0xe502); |
19 |
| - bleGamepadConfig.setPid(0xabcd); |
20 |
| - |
21 |
| - bleGamepadConfig.setModelNumber("1.0"); |
22 |
| - bleGamepadConfig.setSoftwareRevision("Software Rev 1"); |
23 |
| - bleGamepadConfig.setSerialNumber("9876543210"); |
24 |
| - bleGamepadConfig.setFirmwareRevision("2.0"); |
25 |
| - bleGamepadConfig.setHardwareRevision("1.7"); |
26 |
| - |
27 |
| - // Some non-Windows operating systems and web based gamepad testers don't like min axis set below 0, so 0 is set by default |
28 |
| - //bleGamepadConfig.setAxesMin(0x8001); // -32767 --> int16_t - 16 bit signed integer - Can be in decimal or hexadecimal |
29 |
| - bleGamepadConfig.setAxesMin(0x0000); // 0 --> int16_t - 16 bit signed integer - Can be in decimal or hexadecimal |
30 |
| - bleGamepadConfig.setAxesMax(0x7FFF); // 32767 --> int16_t - 16 bit signed integer - Can be in decimal or hexadecimal |
31 |
| - |
32 |
| - bleGamepad.begin(&bleGamepadConfig); // Begin gamepad with configuration options |
| 25 | + Serial.begin(115200); |
| 26 | + Serial.println("Starting BLE work!"); |
| 27 | + bleGamepadConfig.setAutoReport(false); |
| 28 | + bleGamepadConfig.setControllerType(CONTROLLER_TYPE_GAMEPAD); // CONTROLLER_TYPE_JOYSTICK, CONTROLLER_TYPE_GAMEPAD (DEFAULT), CONTROLLER_TYPE_MULTI_AXIS |
| 29 | + bleGamepadConfig.setVid(0xe502); |
| 30 | + bleGamepadConfig.setPid(0xabcd); |
| 31 | + bleGamepadConfig.setTXPowerLevel(txPowerLevel); // Defaults to 9 if not set. (Range: -12 to 9 dBm) |
| 32 | + |
| 33 | + bleGamepadConfig.setModelNumber("1.0"); |
| 34 | + bleGamepadConfig.setSoftwareRevision("Software Rev 1"); |
| 35 | + bleGamepadConfig.setSerialNumber("9876543210"); |
| 36 | + bleGamepadConfig.setFirmwareRevision("2.0"); |
| 37 | + bleGamepadConfig.setHardwareRevision("1.7"); |
| 38 | + |
| 39 | + // Some non-Windows operating systems and web based gamepad testers don't like min axis set below 0, so 0 is set by default |
| 40 | + //bleGamepadConfig.setAxesMin(0x8001); // -32767 --> int16_t - 16 bit signed integer - Can be in decimal or hexadecimal |
| 41 | + bleGamepadConfig.setAxesMin(0x0000); // 0 --> int16_t - 16 bit signed integer - Can be in decimal or hexadecimal |
| 42 | + bleGamepadConfig.setAxesMax(0x7FFF); // 32767 --> int16_t - 16 bit signed integer - Can be in decimal or hexadecimal |
| 43 | + |
| 44 | + bleGamepad.begin(&bleGamepadConfig); // Begin gamepad with configuration options |
| 45 | + |
| 46 | + // Change power level to 6 |
| 47 | + bleGamepad.setTXPowerLevel(6); |
| 48 | + |
33 | 49 | }
|
34 | 50 |
|
35 | 51 | void loop()
|
36 | 52 | {
|
37 |
| - if (bleGamepad.isConnected()) |
38 |
| - { |
| 53 | + if (bleGamepad.isConnected()) |
| 54 | + { |
39 | 55 |
|
40 |
| - } |
| 56 | + } |
41 | 57 | }
|
0 commit comments