美文网首页
LF Bluetooth Android Demo Introd

LF Bluetooth Android Demo Introd

作者: 肚子大脖子细 | 来源:发表于2018-12-20 16:24 被阅读0次

    A Brief Introduction

    • The peripherals refer to Unique Scales Co., Ltd. Bluetooth body fat scale.
    • Because of the need for Bluetooth connectivity, the demo requires a real machine to run with.
    • If you need information other than your weight, you need to enter height, age, gender and step on with bare feet.
    • Height range: 30-220 cm; The value range of age: 10-99 years old; The units are 0 for kilograms, 1 for pounds, and 2 for pounds. Gender 1 is male and 0 is female. User group value range 0-9 (this value is required for certain scales)
    • During use the Demo, you need to turn on bluetooth and give the Demo location permission

    DEMO Download Address

    Instruction

    Demo's main page is as below


    261545290467_.pic.jpg
    • Click “ Binding device” After this controller is instantiated, it will start scanning nearby peripherals and make a record of your peripherals.

    • Click” Weighing” After being instantiated, this controller will also start scanning nearby peripherals and filtering to connect the bound devices. Therefore, the scale can only be weighed after being bound, otherwise the data cannot be received.

    • Click” Device management” This controller will show you the peripherals bound to the "Binding Devices" page in a list. You can remove the bound device by long press.

    • After receiving the data returned by the peripherals on the bind devices and weigh on scales pages, automatically stops the scan and disconnects the peripherals, and then returns the data back to the "home page" to update the weight column, which can be viewed by the Data details page.

    Introduce ppscalelibrary to your project

    Add the following permissions to the AndroidManifest file in the project directory

       <uses-permission android:name="android.permission.BLUETOOTH" />
        <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    

    Drag ppscalelibrary into the lib folder in the project directory and build. Gradle for dependencies

      repositories {
            flatDir {
                dirs 'lib'
            }
        }
      dependencies {
          implementation(name: 'ppscalelibrary_v1.0.0', ext: 'aar')
      }
    

    The use of ppscalelibrary

    Ppscalelibrary provides a utility class entry called BleManager, which is a singleton that ensures that the bluetooth state is the same when you call from different controllers.

     public static BleManager shareInstance(Context context)
    

    To get an instance object by calling a class method, pass in the current context.

     public void searchDevice(boolean isBinding, List<BleDeviceModel> deviceList, BleUserModel userModel, BleDataProtocoInterface protocoInterface) 
    
    • The input parameters isBinding and deviceList are strongly correlated.
      When isBinding is true, it means that bluetooth will ignore the peripherals contained in deviceList in the process of scanning the peripherals. False means that bluetooth only receives information about the peripheral contained in the deviceList when scanning the peripheral.
    • The input userModel is the user's body information
    Implement methods in the BleDataProtocoInterface interface class to get the information from the scale.
    void progressData(LFPeopleGeneral var1);
    
    • LFPeopleGeneral weighs data during the process
    void lockedData(LFPeopleGeneral var1, BleDeviceModel var2);
    
    • LFPeopleGeneral locks in the data, because the user may not have passed in information such as height and gender in the positive and negative range or for some other reason during the weighing process (wearing shoes, not stepping on electrodes, etc.), only weight and BMI data are locked in the data.
    • BleDeviceModel -scale device information
     void historyData(boolean var1, LFPeopleGeneral var2, String var3);
    
    • historyData is a callback that is run by a scale with historical data functions, and if your chosen model supports reading historical data, it will run the callback.
    void deviceInfo(BleDeviceModel var1);
    
    • BleDeviceModel scale device information
    public void stopSearch()
    
    • You need to call stopSearch before you leave the page.
    • Please refer to the code in BindingDeviceActivity and ScaleWeightActivity in the Demo for specific implementation.

    相关文章

      网友评论

          本文标题:LF Bluetooth Android Demo Introd

          本文链接:https://www.haomeiwen.com/subject/mcoykqtx.html