Skip to content

Added BLE Radio on/off scanning. - #53

Open
btetz14 wants to merge 1 commit into
urish:masterfrom
btetz14:master
Open

Added BLE Radio on/off scanning.#53
btetz14 wants to merge 1 commit into
urish:masterfrom
btetz14:master

Conversation

@btetz14

@btetz14 btetz14 commented Jun 25, 2019

Copy link
Copy Markdown

This adds BLE Radio on/off scanning. With a small update to bindings.js, noble.on stateChange will work.

This is the update needed to bindings.js

        case 'Start':
            this.state = 'poweredOn';
            this.emit('stateChange', this.state);
            break;
        // add this case below 'Start' in bindings.js
        case 'Stop':
            this.state = 'poweredOff';
            this.emit('stateChange', this.state);
            break;

@urish urish left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, please have a look at my comments

{
// Ble Radio On
JsonObject^ msg = ref new JsonObject();
msg->Insert("_type", JsonValue::CreateStringValue("Start"));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change to "start" and "stop" (camelCase) to keep consistent with the other values for _type

radio->StateChanged += ref new Windows::Foundation::TypedEventHandler<Windows::Devices::Radios::Radio^, Platform::Object^>(
[](Windows::Devices::Radios::Radio^ sender, Platform::Object^ args)
{
if (sender->State == Windows::Devices::Radios::RadioState::On)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exact same code repeats a few lines above. I'd refactor it into a function that gets the radio state, creates the message and calls writeObject. In addition, you can write it more concisely as:

JsonObject^ msg = ref new JsonObject();
if (sender->State == Windows::Devices::Radios::RadioState::On) {
    msg->Insert("_type", JsonValue::CreateStringValue("start"));
} else {
    msg->Insert("_type", JsonValue::CreateStringValue("stop"));
}
writeObject(msg);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants