Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added BLE Radio on/off scanning. #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

btetz14
Copy link

@btetz14 btetz14 commented Jun 25, 2019

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;

Copy link
Owner

@urish urish left a comment

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
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
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