|
297 | 297 |
|
298 | 298 | var maxRecords = 64;
|
299 | 299 |
|
300 |
| - var BLEsense = |
| 300 | + var NiclaSenseME = |
301 | 301 | {
|
302 | 302 | temperature:
|
303 | 303 | {
|
|
373 | 373 | }
|
374 | 374 | }
|
375 | 375 |
|
376 |
| - const sensors = Object.keys(BLEsense); |
| 376 | + const sensors = Object.keys(NiclaSenseME); |
377 | 377 | const SERVICE_UUID = '6fbe1da7-0000-44de-92c4-bb6e04fb0212';
|
378 | 378 | var bytesReceived = 0;
|
379 | 379 | var bytesPrevious = 0;
|
|
440 | 440 | // Set up the characteristics
|
441 | 441 | for (const sensor of sensors) {
|
442 | 442 | msg('characteristic ' + sensor + "...");
|
443 |
| - BLEsense[sensor].characteristic = await service.getCharacteristic(BLEsense[sensor].uuid); |
| 443 | + NiclaSenseME[sensor].characteristic = await service.getCharacteristic(NiclaSenseME[sensor].uuid); |
444 | 444 | // Set up notification
|
445 |
| - if (BLEsense[sensor].properties.includes("BLENotify")) { |
446 |
| - BLEsense[sensor].characteristic.addEventListener('characteristicvaluechanged', function (event) { handleIncoming(BLEsense[sensor], event.target.value); }); |
447 |
| - await BLEsense[sensor].characteristic.startNotifications(); |
| 445 | + if (NiclaSenseME[sensor].properties.includes("BLENotify")) { |
| 446 | + NiclaSenseME[sensor].characteristic.addEventListener('characteristicvaluechanged', function (event) { handleIncoming(NiclaSenseME[sensor], event.target.value); }); |
| 447 | + await NiclaSenseME[sensor].characteristic.startNotifications(); |
448 | 448 | }
|
449 | 449 | // Set up polling for read
|
450 |
| - if (BLEsense[sensor].properties.includes("BLERead")) { |
451 |
| - BLEsense[sensor].polling = setInterval(function () { |
452 |
| - BLEsense[sensor].characteristic.readValue().then(function (data) { handleIncoming(BLEsense[sensor], data); }) |
| 450 | + if (NiclaSenseME[sensor].properties.includes("BLERead")) { |
| 451 | + NiclaSenseME[sensor].polling = setInterval(function () { |
| 452 | + NiclaSenseME[sensor].characteristic.readValue().then(function (data) { handleIncoming(NiclaSenseME[sensor], data); }) |
453 | 453 | }
|
454 | 454 | , 500);
|
455 | 455 | }
|
456 | 456 |
|
457 |
| - BLEsense[sensor].rendered = false; |
| 457 | + NiclaSenseME[sensor].rendered = false; |
458 | 458 | }
|
459 | 459 | pairButton.style.backgroundColor = 'green';
|
460 | 460 | pairButton.style.color = 'white';
|
|
501 | 501 | snack("Device disconnected, please retry", 1)
|
502 | 502 | // clear read polling
|
503 | 503 | for (const sensor of sensors) {
|
504 |
| - if (typeof BLEsense[sensor].polling !== 'undefined') { |
505 |
| - clearInterval(BLEsense[sensor].polling); |
| 504 | + if (typeof NiclaSenseME[sensor].polling !== 'undefined') { |
| 505 | + clearInterval(NiclaSenseME[sensor].polling); |
506 | 506 | }
|
507 | 507 | }
|
508 | 508 | // clear color picker write
|
|
514 | 514 | }
|
515 | 515 |
|
516 | 516 | function BLEwriteTo(sensor) {
|
517 |
| - if (BLEsense[sensor].writeBusy) return; // dropping writes when one is in progress instead of queuing as LED is non-critical / realtime |
518 |
| - BLEsense[sensor].writeBusy = true; // Ensure no write happens when GATT operation in progress |
519 |
| - BLEsense[sensor].characteristic.writeValue(BLEsense[sensor].writeValue) |
| 517 | + if (NiclaSenseME[sensor].writeBusy) return; // dropping writes when one is in progress instead of queuing as LED is non-critical / realtime |
| 518 | + NiclaSenseME[sensor].writeBusy = true; // Ensure no write happens when GATT operation in progress |
| 519 | + NiclaSenseME[sensor].characteristic.writeValue(NiclaSenseME[sensor].writeValue) |
520 | 520 | .then(_ => {
|
521 |
| - BLEsense[sensor].writeBusy = false; |
| 521 | + NiclaSenseME[sensor].writeBusy = false; |
522 | 522 | })
|
523 | 523 | .catch(error => {
|
524 | 524 | console.log(error);
|
|
530 | 530 | <script>
|
531 | 531 |
|
532 | 532 | function initColorPicker() {
|
533 |
| - BLEsense.led.colorPicker = new iro.ColorPicker("#color-picker-container", { |
| 533 | + NiclaSenseME.led.colorPicker = new iro.ColorPicker("#color-picker-container", { |
534 | 534 | width: 150,
|
535 | 535 | color: "rgb(255, 0, 0)",
|
536 | 536 | borderWidth: 1,
|
|
539 | 539 | sliderMargin: 6
|
540 | 540 | });
|
541 | 541 | // RGB Color Picker
|
542 |
| - BLEsense.led.colorPicker.on('color:change', updateModelLed); |
| 542 | + NiclaSenseME.led.colorPicker.on('color:change', updateModelLed); |
543 | 543 | function updateModelLed(color) {
|
544 | 544 | ledLight.color.setHex("0x" + color.hexString.substring(1, 7));
|
545 | 545 | ledMaterial.color.set(color.hexString) // where r, g, and b are 0 to 1
|
546 | 546 | var rgb_values = Uint8Array.of(color.rgb.r, color.rgb.g, color.rgb.b);
|
547 |
| - BLEsense['led'].writeValue = rgb_values; |
| 547 | + NiclaSenseME['led'].writeValue = rgb_values; |
548 | 548 | BLEwriteTo('led');
|
549 | 549 | }
|
550 | 550 | }
|
|
554 | 554 | var colorIndex = 0;
|
555 | 555 | function initGraph(sensor) {
|
556 | 556 | var title = sensor;
|
557 |
| - var series = Object.keys(BLEsense[sensor].data); |
| 557 | + var series = Object.keys(NiclaSenseME[sensor].data); |
558 | 558 | var format = [];
|
559 | 559 | series.forEach(function (item) {
|
560 | 560 | colorIndex++;
|
|
649 | 649 | ctx.fillStyle = "#111111";
|
650 | 650 | ctx.fillRect(0, 0, canvas.width, canvas.height);
|
651 | 651 | for (i = 0; i < maxRecords; i++) {
|
652 |
| - R = BLEsense[sensor].data.R[i]; |
653 |
| - G = BLEsense[sensor].data.G[i]; |
654 |
| - B = BLEsense[sensor].data.B[i]; |
| 652 | + R = NiclaSenseME[sensor].data.R[i]; |
| 653 | + G = NiclaSenseME[sensor].data.G[i]; |
| 654 | + B = NiclaSenseME[sensor].data.B[i]; |
655 | 655 | total = R + G + B;
|
656 | 656 | R = R / total * 255; G = G / total * 255; B = B / total * 255;
|
657 | 657 | ctx.fillStyle = "rgba(" + R + "," + G + "," + B + ")";
|
|
662 | 662 | Array.prototype.latest = function () { return this[this.length - 1]; };
|
663 | 663 |
|
664 | 664 | function graph(sensor) {
|
665 |
| - var labels = Object.keys(BLEsense[sensor].data); |
| 665 | + var labels = Object.keys(NiclaSenseME[sensor].data); |
666 | 666 | var values = [];
|
667 | 667 | // after
|
668 | 668 | labels.forEach(function (label) {
|
669 |
| - values.push(BLEsense[sensor].data[label]); |
| 669 | + values.push(NiclaSenseME[sensor].data[label]); |
670 | 670 | });
|
671 | 671 | Plotly.restyle(sensor, { y: values });
|
672 | 672 | }
|
673 | 673 |
|
674 | 674 | function digit(sensor) {
|
675 |
| - const value = BLEsense[sensor].data[sensor].latest(); |
| 675 | + const value = NiclaSenseME[sensor].data[sensor].latest(); |
676 | 676 | const div = document.getElementById(sensor + "-value");
|
677 | 677 | if (!Number.isNaN(value)) { div.innerHTML = Math.round(value * 10) / 10; };
|
678 | 678 | }
|
679 | 679 |
|
680 | 680 | function update3d(sensor) {
|
681 | 681 |
|
682 | 682 | // Get the quaternion values
|
683 |
| - var x = BLEsense['quaternion'].data.x.latest(); |
684 |
| - var y = BLEsense['quaternion'].data.y.latest(); |
685 |
| - var z = BLEsense['quaternion'].data.z.latest(); |
686 |
| - var w = BLEsense['quaternion'].data.w.latest(); |
| 683 | + var x = NiclaSenseME['quaternion'].data.x.latest(); |
| 684 | + var y = NiclaSenseME['quaternion'].data.y.latest(); |
| 685 | + var z = NiclaSenseME['quaternion'].data.z.latest(); |
| 686 | + var w = NiclaSenseME['quaternion'].data.w.latest(); |
687 | 687 |
|
688 | 688 | // Construct the quaternion object with the values and apply that to the 3D model
|
689 | 689 | const quaternion = new THREE.Quaternion(x, y, z, w);
|
|
710 | 710 | var skip_frame = false;
|
711 | 711 | function draw() {
|
712 | 712 | function updateViz(sensor, fns) {
|
713 |
| - if (BLEsense[sensor].rendered == false) { // only render if new values are received |
| 713 | + if (NiclaSenseME[sensor].rendered == false) { // only render if new values are received |
714 | 714 | fns.forEach(function (fn) {
|
715 | 715 | fn(sensor);
|
716 | 716 | });
|
717 |
| - BLEsense[sensor].rendered = true; |
| 717 | + NiclaSenseME[sensor].rendered = true; |
718 | 718 | }
|
719 | 719 | }
|
720 | 720 | if (skip_frame == false) { // TODO update with fuction to iterate object with viz function as a property
|
|
0 commit comments