Skip to content

Commit

Permalink
make the name easily changeable
Browse files Browse the repository at this point in the history
  • Loading branch information
joonazan committed May 29, 2020
1 parent 0d75ca8 commit 895be93
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/multiplication/multiplication.ino
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void loop() {
// I do initialization in loop because this array must live as long as the program
BLETypes::IInput* inputs[] = { &in };

BLE.start(SERVICE_UUID, inputs);
BLE.start(SERVICE_UUID, "multiplication service", inputs);

while(true) {
BLE.poll();
Expand Down
7 changes: 6 additions & 1 deletion extras/nina-src/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ void app_main(void)
} else if (msg.type == BLE_CREATE_INPUT) {
BleBackend_add_input(id, msg.length);
} else if (msg.type == BLE_START) {
BleBackend_start("testname", &id->u);
const uint16_t namelen = msg.length;
char *name = malloc(namelen + 1);
read_from_uart(name, namelen);
name[namelen] = '\0';

BleBackend_start(name, &id->u);
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/FastBLE.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class BLEClass {
return { id, cb };
};

void start(ble_uuid_any_t, BLETypes::IInput**);
void start(ble_uuid_any_t, const char *, BLETypes::IInput**);
void poll();

private:
Expand Down
7 changes: 6 additions & 1 deletion src/FastBle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void BLEClass::init_if_not_initialized() {
while(!Serial2);
}

void BLEClass::start(ble_uuid_any_t svc_id, BLETypes::IInput** inputs) {
void BLEClass::start(ble_uuid_any_t svc_id, const char *name, BLETypes::IInput** inputs) {
init_if_not_initialized();

_inputs = inputs;
Expand All @@ -28,12 +28,17 @@ void BLEClass::start(ble_uuid_any_t svc_id, BLETypes::IInput** inputs) {
inputs[i]->setup();
}

uint16_t name_length = 0;
while(name[name_length++] != '\0');

SetupMessage msg
{
type: BLE_START,
uuid: svc_id,
length: name_length,
};
Serial2.write((uint8_t*)&msg, sizeof(SetupMessage));
Serial2.write((uint8_t*)name, name_length);
}

void BLEClass::poll() {
Expand Down
6 changes: 5 additions & 1 deletion src/protocol/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ enum SetupMessageType
};

// A number of Create Output / Input messages can be sent
//
// Then a Start message should be sent with the uuid field set to the
// UUID that the Service containing the characteristics should have.
// UUID that the Service containing the characteristics should have and
// the length field set to the length of the device's name.
//
// Then length bytes (the name) should be sent.

typedef struct {
uint8_t type;
Expand Down

0 comments on commit 895be93

Please sign in to comment.