1 //############################################################################################
    2 // File_:   $RCSfile: 4C02_DDC-SE_LP.js,v $
    3 // Version: $Revision: 1.6 $
    4 // Date:    $Date: 2023/03/25 10:57:17 $
    5 //############################################################################################
    6 // Driver for 'DDC-SE01 LP sensor example'
    7 
    8 /*DriverDescription
    9 { 'ID' : 0x4C02,
   10   'Type' : 'Handler',
   11   'Internal' : false,
   12   'Versions' : [
   13     { 'Version' : 0x0000, 'Notes' : [
   14         'Initial release' ]
   15     }
   16   ] }
   17 DriverDescription*/
   18 
   19 "use strict";
   20 
   21 // Namespace: iqrf.sensor
   22 namespace( 'iqrf.sensor' );
   23 
   24 // This product sensors list
   25 iqrf.sensor.SensorsList =
   26   [
   27     iqrf.sensor.STD_SENSOR_TYPE_TEMPERATURE,  // 0
   28     iqrf.sensor.STD_SENSOR_TYPE_BINARYDATA7,  // 1 : FinalizeSensor Light
   29     iqrf.sensor.STD_SENSOR_TYPE_BINARYDATA7   // 2 : FinalizeSensor Potentiometer
   30   ];
   31 
   32 // Breakdown the Binary Data7 sensor values
   33 iqrf.sensor.FinalizeSensor = function ( sensor, index, frcCommand, extendedFrcData )
   34 {
   35   // Is it binary7 data type at the expected indexes, but not 2bit FRC (has no meaning to breakdown)?
   36   if ( sensor.type === iqrf.sensor.STD_SENSOR_TYPE_BINARYDATA7 && ( index === 1 || index === 2 ) && frcCommand !== iqrf.sensor.STD_SENSOR_FRC_2BITS )
   37   {
   38     // Yes, breakdown the value ...
   39     sensor.breakdown = [];
   40     // ... to the one value
   41     sensor.breakdown[0] =
   42       {
   43         // Keep quantity type
   44         id: sensor.id,
   45         type: sensor.type,
   46         // Find out the names based on the index
   47         name: index === 1 ? 'Light indicator'/* index 1 */ : 'Potentiometer'/* index 2 */,
   48         shortName: index === 1 ? 'light' : 'pot',
   49         // And the unit is...
   50         unit: '%',
   51         decimalPlaces: 1
   52       };
   53 
   54     if ( sensor.value !== undefined )
   55       // Compute the value the same way for both binary data7 sensors, i.e. convert binary values 0-127 to 100.0-0.0 %
   56       sensor.breakdown[0].value = isNaN( sensor.value ) ? NaN : iqrf.Round( ( 127 - sensor.value ) * 100.0 / 127, 1 );
   57   }
   58 };
   59 
   60 //############################################################################################