@0x77/iqos.parser 中文文档教程

发布于 5年前 浏览 18 项目主页 更新于 3年前

iQOS.parser

用于持有人收费状态解析的解析器库。

在 iQOS 2.4+ 和 Chrome 76 上测试

iQOS commmunity npm GitHub 代码大小(以字节为单位) GitHub issues编辑iQOS.parser 演示

Q&A

TODO

  • Add charger support
  • Test on iQOS 3.0
  • Write connection library
  • etc… (P.S.: purpose your features on issues)

Where I can ask the question or bug report?

What is this?

  • This library contains simple function that parse the iQOS holder charge status

How to know that holder is not inside charger?

  • It will return -1

What i need to test it out?

  • Chrome that supports BLE.
  • Bluetooth-enabled iQOS (not tested on iQOS 3)
  • A simple code for access ble and display the status:
import HolderChargeEventHandler from '@0x77/iqos.parser';
let optionalServices = ["daebb240-b041-11e4-9e45-0002a5d5c51b"];
//f8a54120-b041-11e4-9be7-0002a5d5c51b battery status characteristic

console.log('Requesting any Bluetooth Device...');
navigator.bluetooth.requestDevice({
    acceptAllDevices: true,
    optionalServices: optionalServices
})
    .then(device => {
        console.log('Connecting to GATT Server...');
        return device.gatt.connect();
    })
    .then(server => {
        console.log('Getting Services...');
        return server.getPrimaryServices();
    })
    .then(services => {
        console.log('Getting Characteristics...');
        let queue = Promise.resolve();
        services.forEach(service => {
            queue = queue.then(_ => service.getCharacteristics().then(characteristics => {
                console.log('> Service: ' + service.uuid);
                characteristics.forEach(characteristic => {
                    // log('> C: ', characteristic.uuid.uuid);
                    console.log(characteristic.uuid);
                    if (characteristic.uuid == "f8a54120-b041-11e4-9be7-0002a5d5c51b") {
                        console.log("characteristic of battery found");
                        characteristic.startNotifications().then(characteristic => {
                            characteristic.addEventListener(
                                'characteristicvaluechanged', handleCharacteristicValueChanged
                            );

                        })
                            .catch(error => { console.log(error); });

                    }
                    console.log("Reinsert holder to begin...");
                });
            }));
        });
        return queue;
    })
    .catch(error => {
        console.log('Argh! ' + error);
    });

const handleCharacteristicValueChanged = (event) => {
    console.log(HolderChargeEventHandler(event));
}

iQOS.parser

A parser library for holder charge status parsing.

Tested on iQOS 2.4+ and Chrome 76

iQOS commmunity npm GitHub code size in bytes GitHub issuesEdit iQOS.parser demo

Q&A

TODO

  • Add charger support
  • Test on iQOS 3.0
  • Write connection library
  • etc… (P.S.: purpose your features on issues)

Where I can ask the question or bug report?

What is this?

  • This library contains simple function that parse the iQOS holder charge status

How to know that holder is not inside charger?

  • It will return -1

What i need to test it out?

  • Chrome that supports BLE.
  • Bluetooth-enabled iQOS (not tested on iQOS 3)
  • A simple code for access ble and display the status:
import HolderChargeEventHandler from '@0x77/iqos.parser';
let optionalServices = ["daebb240-b041-11e4-9e45-0002a5d5c51b"];
//f8a54120-b041-11e4-9be7-0002a5d5c51b battery status characteristic

console.log('Requesting any Bluetooth Device...');
navigator.bluetooth.requestDevice({
    acceptAllDevices: true,
    optionalServices: optionalServices
})
    .then(device => {
        console.log('Connecting to GATT Server...');
        return device.gatt.connect();
    })
    .then(server => {
        console.log('Getting Services...');
        return server.getPrimaryServices();
    })
    .then(services => {
        console.log('Getting Characteristics...');
        let queue = Promise.resolve();
        services.forEach(service => {
            queue = queue.then(_ => service.getCharacteristics().then(characteristics => {
                console.log('> Service: ' + service.uuid);
                characteristics.forEach(characteristic => {
                    // log('> C: ', characteristic.uuid.uuid);
                    console.log(characteristic.uuid);
                    if (characteristic.uuid == "f8a54120-b041-11e4-9be7-0002a5d5c51b") {
                        console.log("characteristic of battery found");
                        characteristic.startNotifications().then(characteristic => {
                            characteristic.addEventListener(
                                'characteristicvaluechanged', handleCharacteristicValueChanged
                            );

                        })
                            .catch(error => { console.log(error); });

                    }
                    console.log("Reinsert holder to begin...");
                });
            }));
        });
        return queue;
    })
    .catch(error => {
        console.log('Argh! ' + error);
    });

const handleCharacteristicValueChanged = (event) => {
    console.log(HolderChargeEventHandler(event));
}
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文