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.
Diff: source/main.cpp
- Revision:
- 2:b51fb6efcd55
- Parent:
- 1:84935552ca4d
--- 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);