package com.zzliaoyuan.power_sensor.readUHF;

import android.content.Context;

import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.zzliaoyuan.power_sensor.fragment.UHFReadTagFragment;

public class ReadUHFModule extends ReactContextBaseJavaModule {
    Context context;
    public ReadUHFModule(ReactApplicationContext reactContext) {
        super(reactContext);
        this.context = reactContext;
    }

    @Override
    public String getName() {
        return "ReadUHF";
    }

    @ReactMethod
    public void changeFlag(Integer type) {
        if(type == null)
            type = 1;
        UHFReadTagFragment.getInstance().setUserModel();
    }

    @ReactMethod
    public void doRead() {
        UHFReadTagFragment.getInstance().myOnKeyDwon();
    }

    @ReactMethod
    public void getPower(Callback callback) {
        int power = 30;
        try {
            power = UHFReadTagFragment.getInstance().getPower();
        } catch (Exception e) {
            e.printStackTrace();
        }
        callback.invoke(power);
    }

    @ReactMethod
    public void setPower(Integer power) {
        UHFReadTagFragment.getInstance().setPower(power);
    }
}
