|
| 1 | +var MetaWear = require('../index')//require('metawear'); |
| 2 | +var ref = require('ref'); |
| 3 | + |
| 4 | +MetaWear.discoverByAddress('c8:4b:aa:97:50:05', function(device) { |
| 5 | +//MetaWear.discover(function (device) { |
| 6 | + console.log('got em'); |
| 7 | + // you can be notified of disconnects |
| 8 | + device.on('disconnect', function () { |
| 9 | + console.log('we got disconnected! :( '); |
| 10 | + }); |
| 11 | + // Call connect and set up - this calls mbl_mw_metawearboard_initialize() |
| 12 | + device.connectAndSetUp(function (error) { |
| 13 | + console.log('were connected!'); |
| 14 | + // Adjust link speed - set the min conn interval to 7.5ms and the max conn interval to 7.5ms |
| 15 | + // Adjust link speed - set the latency to 0ms and the timeout to 4000ms |
| 16 | + // Connection interval = how often devices talk - min is 7.5ms, it increases in steps of 1.25ms |
| 17 | + // Slave latency = metawear can choose not to answer when central asks for an update (i.e metawear can sleep longer - doesn't affect transfer speeds) |
| 18 | + // Connection supervision timeout = determines timeout from last data exchange (tells central how long to wait to attempt to reconnect to a lost conn - if your metawear goes in and out of range often, it is better to have a short timeout) |
| 19 | + // This is not guaranteed to work, central can reject peripheral and vice-versa. Apple only accepts 15ms for example. |
| 20 | + MetaWear.mbl_mw_settings_set_connection_parameters(device.board, 7.5, 7.5, 0, 4000); |
| 21 | + console.log('link speed updated'); |
| 22 | + // Everything we know about the device: |
| 23 | + console.log(device); |
| 24 | + // Calls using CDK CPP: |
| 25 | + model = MetaWear.mbl_mw_metawearboard_get_model(device.board); |
| 26 | + console.log('Model: ' + model); |
| 27 | + device.modelDescription = MetaWear.mbl_mw_metawearboard_get_model_name(device.board); |
| 28 | + console.log('Model Name: ' + device.modelDescription); |
| 29 | + var present = MetaWear.mbl_mw_metawearboard_lookup_module(device.board, 'GYRO'); |
| 30 | + console.log('Gyroscope: ' + (present == -1 ? 'Not Present' : 'Present')); |
| 31 | + present = MetaWear.mbl_mw_metawearboard_lookup_module(device.board, 'ACCELEROMETER'); |
| 32 | + console.log('Accelerometer: ' + (present == -1 ? 'Not Present' : 'Present')); |
| 33 | + present = MetaWear.mbl_mw_metawearboard_lookup_module(device.board, 'MAGNETOMETER'); |
| 34 | + console.log('Magnetometer: ' + (present == -1 ? 'Not Present' : 'Present')); |
| 35 | + present = MetaWear.mbl_mw_metawearboard_lookup_module(device.board, 'SENSOR_FUSION'); |
| 36 | + console.log('Sensor Fusion: ' + (present == -1 ? 'Not Present' : 'Present')); |
| 37 | + // Calls Noble APIs: |
| 38 | + device.readManufacturerName(function (error, manufacturerName) { |
| 39 | + console.log('Manufacturer Name: ' + manufacturerName); |
| 40 | + }); |
| 41 | + device.readSerialNumber(function (error, serialNumber) { |
| 42 | + console.log('Serial #: ' + serialNumber); |
| 43 | + }); |
| 44 | + device.readHardwareRevision(function (error, hardwareRevision) { |
| 45 | + console.log('Hardware Revision: ' + hardwareRevision); |
| 46 | + }); |
| 47 | + device.readFirmwareRevision(function (error, firmwareRevision) { |
| 48 | + console.log('Firmware Revision: ' + firmwareRevision); |
| 49 | + }); |
| 50 | + device.readModelNumber(function (error, modelNumber) { |
| 51 | + device.modelNumber = modelNumber; |
| 52 | + console.log('Model #: ' + modelNumber); |
| 53 | + |
| 54 | + }); |
| 55 | + setTimeout(function () { |
| 56 | + device.disconnect(function (error) { |
| 57 | + console.log('disconnect call finished'); |
| 58 | + process.exit(0); |
| 59 | + }); |
| 60 | + }, 1000); |
| 61 | + }); |
| 62 | +}); |
0 commit comments