Bluetooth Low Energy and Stepper Motor enabled device, compatible with the BlueST Protocol.
Dependencies: X_NUCLEO_IHM01A1
Bluetooth Low Energy and Stepper Motor enabled device, compatible with the BlueST Protocol.
Revision 2:b51fb6efcd55, committed 2018-08-06
- Comitter:
- Davidroid
- Date:
- Mon Aug 06 09:59:56 2018 +0000
- Parent:
- 1:84935552ca4d
- Commit message:
- Correct Custom Service UUID
Changed in this revision
source/CustomService.h | Show annotated file Show diff for this revision Revisions of this file |
source/main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/source/CustomService.h Thu May 10 12:18:51 2018 +0000 +++ b/source/CustomService.h Mon Aug 06 09:59:56 2018 +0000 @@ -48,7 +48,7 @@ #define COMMAND_DATA_LENGTH (sizeof(uint8_t) + sizeof(uint32_t)) #define MAX_DATA_LENGTH (COMMAND_DATA_LENGTH) -const UUID::LongUUIDBytes_t CUSTOM_STEPPER_MOTOR_SERVICE_UUID = {0x00,0x00,0x00,0x00,0x00,0x01,0x11,0xe1,0xac,0x36,0x00,0x02,0xa5,0xd5,0xc5,0x1b}; +const UUID::LongUUIDBytes_t CUSTOM_SERVICE_UUID = {0x00,0x00,0x00,0x00,0x00,0x01,0x11,0xe1,0x9a,0xb4,0x00,0x02,0xa5,0xd5,0xc5,0x1b}; const UUID::LongUUIDBytes_t CUSTOM_STEPPER_MOTOR_CHARACTERISTIC_UUID = {0x00,0x00,0x20,0x00,0x00,0x01,0x11,0xe1,0xac,0x36,0x00,0x02,0xa5,0xd5,0xc5,0x1b}; class CustomService { @@ -78,7 +78,7 @@ GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE) { GattCharacteristic *char_table[] = {&state_command}; - GattService motor_service(CUSTOM_STEPPER_MOTOR_SERVICE_UUID, char_table, sizeof(char_table) / sizeof(GattCharacteristic *)); + GattService motor_service(CUSTOM_SERVICE_UUID, char_table, sizeof(char_table) / sizeof(GattCharacteristic *)); ble.addService(motor_service); memset (packed_state_command, 0, MAX_DATA_LENGTH); }
--- a/source/main.cpp Thu May 10 12:18:51 2018 +0000 +++ b/source/main.cpp Mon Aug 06 09:59:56 2018 +0000 @@ -147,7 +147,7 @@ * Information about the characterisitc being updated. */ void on_data_written_callback(const GattWriteCallbackParams *params) { - uint32_t steps; + uint32_t steps = 3000; if (params->handle == custom_service->getValueHandle()) { //printf("--> COMMAND: %d\r\n", ((uint8_t *) (params->data))[0]); @@ -155,21 +155,25 @@ { //Stops running with HiZ case CustomService::MOTOR_STOP_RUNNING_WITHOUT_TORQUE: + //printf("--> %d %d\r\n", params->len, ((uint8_t *) (params->data))[0]); motor->hard_hiz(); motor->wait_while_active(); break; //Stops running with torque applied case CustomService::MOTOR_STOP_RUNNING_WITH_TORQUE: + //printf("--> %d %d\r\n", params->len, ((uint8_t *) (params->data))[0]); motor->hard_stop(); motor->enable(); motor->wait_while_active(); break; //Runs forward indefinitely case CustomService::MOTOR_RUN_FORWARD: + //printf("--> %d %d\r\n", params->len, ((uint8_t *) (params->data))[0]); motor->run(StepperMotor::FWD); break; //Runs backward indefinitely case CustomService::MOTOR_RUN_BACKWARD: + //printf("--> %d %d\r\n", params->len, ((uint8_t *) (params->data))[0]); motor->run(StepperMotor::BWD); break; //Moves steps forward @@ -178,9 +182,9 @@ (((uint8_t *) (params->data))[2] << 8 ) | (((uint8_t *) (params->data))[3] << 16) | (((uint8_t *) (params->data))[4] << 24)); + //printf("--> %d %d %d", params->len, ((uint8_t *) (params->data))[0], steps); motor->move(StepperMotor::FWD, steps); motor->wait_while_active(); - //printf("--> %d %d %d\r\n", params->len, ((uint8_t *) (params->data))[0], steps); break; //Moves steps backward case CustomService::MOTOR_MOVE_STEPS_BACKWARD: @@ -188,9 +192,9 @@ (((uint8_t *) (params->data))[2] << 8 ) | (((uint8_t *) (params->data))[3] << 16) | (((uint8_t *) (params->data))[4] << 24)); + //printf("--> %d %d %d", params->len, ((uint8_t *) (params->data))[0], steps); motor->move(StepperMotor::BWD, steps); motor->wait_while_active(); - //printf("--> %d %d %d\r\n", params->len, ((uint8_t *) (params->data))[0], steps); break; //Other default: @@ -234,7 +238,7 @@ /* Setup advertising data. */ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); - ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, (uint8_t *) CUSTOM_STEPPER_MOTOR_SERVICE_UUID, sizeof(CUSTOM_STEPPER_MOTOR_SERVICE_UUID)); + ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, (uint8_t *) CUSTOM_SERVICE_UUID, sizeof(CUSTOM_SERVICE_UUID)); ble.gap().accumulateScanResponse(GapAdvertisingData::MANUFACTURER_SPECIFIC_DATA, MANUFACTURER_SPECIFIC_DATA, sizeof(MANUFACTURER_SPECIFIC_DATA)); ble.gap().accumulateScanResponse(GapAdvertisingData::COMPLETE_LOCAL_NAME, (const uint8_t *) DEVICE_NAME, sizeof(DEVICE_NAME) - 1); ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);