npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-chaktl-temp

v1.0.2-e

Published

library to provide all APIs to communicate with the CHAKTL Smart Temperature Scanner by Thinkerbell Labs

Downloads

6

Readme

react-native-chaktl-temp

Getting started

  1. Use this library to make your application compatible with the Chakravyuh Smart Temperature Scanner
  2. Use the Chakravyuh Scanner with the provided Type A to C converter to use with you Android phone
  3. Enable OTG Storage in Settings > System (some older Android phone may not require this step)

Installation

iOS

  1. NOT COMPATIBLE

Android

  1. npm install react-native-chaktl-temp in the Application directory

OR

  1. Open up android/app/src/main/java/[...]/MainActivity.java
  • Add import com.reactlibrary.RNReactNativeChaktlTemp_2Package; to the imports at the top of the file
  • Add new RNReactNativeChaktlTemp_2Package() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-chaktl-temp'
    project(':react-native-chaktl-temp').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-chaktl-temp/android')
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      compile project(':react-native-chaktl-temp')

API


// call to test library
    @ReactMethod
    public void toastTest() {
        Toast.makeText(getReactApplicationContext(), "CHAKTL Toast Test", Toast.LENGTH_SHORT).show();
    }

    // call on mount to initialize the gun
    @ReactMethod
    public void addUsbReceivers(){
        String result = this.tempGun.addUsbReceivers(getCurrentActivity(), getReactApplicationContext());
        Toast.makeText(getReactApplicationContext(), "USB Receivers added: " + result   , Toast.LENGTH_SHORT).show();
    }

    // Deprecated
    @ReactMethod
    public void initMcpConnection(){
        String result = this.tempGun.setMcp2221(getCurrentActivity(), getReactApplicationContext());
        Toast.makeText(getReactApplicationContext(), result, Toast.LENGTH_SHORT).show();
    }

    // call to get last unread temperature (check getUnreadTempStatus) // -1 failure, -2: Scannee too close, -3 Scannne too far
    @ReactMethod
    public void getTempFromGun(Callback tempCallback){
        double temp = this.tempGun.getBodyTempFromGun();
        tempCallback.invoke(temp);
    }

    // DO NOT USE IN PRODUCTION :: THIS DOES NOT RESTRICT OUT OF RANGE TEMP COLLECTION
    @RequiresApi(api = Build.VERSION_CODES.O)
    @ReactMethod
    public void getForceTempFromGun(Callback tempCallback){
        double temp = this.tempGun.getTempFromGun();
        tempCallback.invoke(temp);
    }

    // DO NOT USE IN PRODUCTION
    @ReactMethod
    public void getTrigger(Callback triggerCallback){
        boolean trigger = this.tempGun.getTriggerStatus();
        triggerCallback.invoke(trigger);
    }

    // call after reading temp to reset the flag
    @ReactMethod
    public void resetUnreadTempStatus(){
        this.tempGun.setUnReadTempFromGunPresent(Boolean.FALSE);
    }

    // call to check if new temp has been recorded by the temp gun
    @ReactMethod
    public void getUnreadTempStatus(Callback getUnreadTempStatusCallback){
        boolean unReadTempFromGunPresent = this.tempGun.getUnReadTempFromGunPresent();
        getUnreadTempStatusCallback.invoke(unReadTempFromGunPresent);
    }

    // call to check if anyone is in temperature gun's range // 0: TOO CLOSE, 1: IN RANGE, 2: TOO FAR
    @ReactMethod
    public void getProximityStatusFromTempGun(Callback getProximityStatusFromTempGunCallback){
        int proximityStatusFromTempGun = this.tempGun.getProximityStatusFromTempGun();
        getProximityStatusFromTempGunCallback.invoke(proximityStatusFromTempGun);
    }

    // call to set whether the gun is in hands free mode
    @ReactMethod
    public void setHandsFreeMode(Boolean handsFreeMode){
        this.tempGun.setHandsFreeModeActivated(handsFreeMode);
    }

    // call to get whether the gun is in hands free mode
    @ReactMethod
    public void getHandsFreeMode(Callback getHandsFreeModeCallback){
        boolean handsFreeModeActivated = this.tempGun.getHandsFreeModeActivated();
        getHandsFreeModeCallback.invoke(handsFreeModeActivated);
    }

    // call to check if Chakravyuh temperature Gun is successfully connected
    @ReactMethod
    public void getIsTempGunConnected(Callback getIsTempGunConnectedCallback){
        boolean isTempGunConnected = this.tempGun.getTempGunConnected();
        getIsTempGunConnectedCallback.invoke(isTempGunConnected);
    }

    // call to set whether the buzzer on the gun is activated or not
    @ReactMethod
    public void setBuzzerActivation(Boolean BuzzerActivation){
        this.tempGun.setBuzzerActivated(BuzzerActivation);
    }

    // call to get whether the buzzer on the gun is activated or not
    @ReactMethod
    public void getBuzzerActivation(Callback getBuzzerActivationCallback){
        boolean isBuzzerActivated = this.tempGun.getBuzzerActivated();
        getBuzzerActivationCallback.invoke(isBuzzerActivated);
    }

    // call to set whether the gun returns temperature in Celcius or not
    @ReactMethod
    public void setTempUnitCelcius(Boolean isTempUnitCelcius){
        this.tempGun.setTempUnitCelcius(isTempUnitCelcius);
    }

    // call to get whether the gun returns temperature in Celcius or not
    @ReactMethod
    public void getTempUnitCelcius(Callback getTempUnitCelciusCallback){
        boolean isTempUnitCelcius = this.tempGun.getTempUnitCelcius();
        getTempUnitCelciusCallback.invoke(isTempUnitCelcius);
    }

Sample Usage

import {NativeModules} from 'react-native';

export default class App extends React.Component {
  constructor(props) {

    // initialize the package
    this.testChakTl = NativeModules.RNReactNativeChaktlTemp_2;
  }

  componentDidMount() {
   // attach USB handlers to detect the temperature gun and initialize the connection on detection
   this.testChakTl.addUsbReceivers();

   // checking if temp gun is connected
    var timer;
    function checkIfGunConnected(repeat, _this) {
      if (repeat) {
        _this.testChakTl.getIsTempGunConnected((t) => {
          _this.setState({
            gunConnected: t,
          });
          if (_this.state.gunConnected) {
            repeat = false;
          }
          console.log('temp gun connected logged :' + t);
        });
        timer = setTimeout(() => checkIfGunConnected(repeat, _this), 1000);
      } else {
        clearTimeout(timer);
        _this.checkTempContinuously();
        console.log(' checkIfGunConnected stopped');
        return;
      }
    }

    checkIfGunConnected(true, this);
  }


   // checking if new temp is available post successful connection
  checkTempContinuously = () => {
    (function checkAndFetchNewtemp(repeat, _this) {
      if (repeat) {
      // checking if temp gun is connected
        if (!_this.state.gunConnected) {
          _this.testChakTl.getIsTempGunConnected((t) => {
            _this.setState({
              gunConnected: t,
            });
            if (_this.state.gunConnected) {
              repeat = false;
            }
            console.log('temp gun connected logged :' + t);
          });
        } else {
          // Checking if new temp is available to be read
          _this.testChakTl.getUnreadTempStatus((t) => {
            if (t) {
              _this.testChakTl.getTempFromGun((t) => {
              // if temp gun fails mark as disconnected
                if (t == -1) {
                  repeat = false;
                  _this.setState({
                    gunConnected: false,
                  });
                  console.log('temp request failed :' + t);
                }
                _this.setState({
                  temp: t,
                });

                console.log('temp request logged :' + t);
              });
              // resetting unread Temp flag to avoid rereading same value
              _this.testChakTl.resetUnreadTempStatus();
            }
            console.log('getUnreadTempStatus request logged :' + t);
          });

          // check if someone is in range
          _this.testChakTl.getProximityStatusFromTempGun((t) => {
            if (t != _this.state.range) {
              _this.setState({
                range: t,
              });
              console.log('range request logged :' + t);
            }

          });
        }

        if (repeat) {
          _this.timer = setTimeout(
            () => _this.checkTempContinuously(repeat, _this),
            500,
          );
        } else {
          clearTimeout(_this.timer);
          _this.checkGunContinuously();
          console.log(' checkIfGunConnected stopped');
          return;
        }
      } else {
        clearTimeout(_this.timer);
        _this.checkGunContinuously();
        console.log(' checkIfGunConnected stopped');
        return;
      }
    })(true, this);
  };

  // enabling/disabling the buzzer sound on the temperature gun
  onBuzzerToggle = () => {
    if (this.state.buzzerActivated) {
      this.setState({
        buzzerActivated: false,
      });
    } else {
      this.setState({
        buzzerActivated: true,
      });
    }

    console.log('buzzerActivated state logged :' + this.state.buzzerActivated);
    this.testChakTl.setBuzzerActivation(this.state.buzzerActivated);
  };

  // enabling/disabling the hands free mode on the temperature gun
  onHandsFreeToggle = () => {
    if (this.state.handsFree) {
      this.setState({
        handsFree: false,
      });
    } else {
      this.setState({
        handsFree: true,
      });
    }

    console.log('handsfree state logged :' + this.state.handsFree);
    this.testChakTl.setHandsFreeMode(this.state.handsFree);
    this.testChakTl.getHandsFreeMode((t) => {
    console.log('handsfree request logged :' + t);
    });
  };

  // changing the unit of temperature on the temperature gun
  onCelciusToggle = () => {
    if (this.state.isCelcius) {
      this.setState({
        isCelcius: false,
      });
    } else {
      this.setState({
        isCelcius: true,
      });
    }

    console.log('isCelcius state logged :' + this.state.isCelcius);
    this.testChakTl.setTempUnitCelcius(this.state.isCelcius);
    this.testChakTl.getTempUnitCelcius((t) => {
      console.log('isCelcius request logged :' + t);
    });
  };