//---------------------------------------------GAS SUBS------------------------------------------------------------------------------------------------------
void powerOn(){ //Gas Sensor
    dta_test[0] = 11;
    dta_test[1] = 1;
    write_i2c(0x16, dta_test, 2);
}

void powerOff(){ //Gas Sensor
    dta_test[0] = 11;
    dta_test[1] = 0;
    write_i2c(0x16, dta_test, 2);
}

void write_i2c(unsigned char addr, unsigned char *dta, unsigned char dta_len){ //Gas Sensor
    Wire.beginTransmission(addr);
    for(int i=0; i<dta_len; i++)
    {Wire.write(dta[i]);}
    Wire.endTransmission();
}

unsigned int get_addr_dta2(unsigned char addr_reg){ //Gas Sensor
    START:
    Wire.beginTransmission(0x16);
    Wire.write(addr_reg);
    Wire.endTransmission();
    delay(5); //CRITICAL - DO NOT REMOVE
    Wire.requestFrom(0x16, 2);

    unsigned int dta = 0;
    unsigned char raw[10];
    int cnt = 0;
    
    while(Wire.available()){raw[cnt++] = Wire.read();}
    
    if(cnt == 0)goto START;

    dta = raw[0];
    dta <<= 8;
    dta += raw[1];
    
    switch(addr_reg){
        case CH_VALUE_NH3:
        if(dta > 0)
        {adcValueR0_NH3_Buf = dta;}
        else 
        {dta = adcValueR0_NH3_Buf;}
        
        break;
        case CH_VALUE_CO:
        
        if(dta > 0){adcValueR0_CO_Buf = dta;}
        else {dta = adcValueR0_CO_Buf;}
        
        break;
        case CH_VALUE_NO2:
        if(dta > 0){adcValueR0_NO2_Buf = dta;}
        else {dta = adcValueR0_NO2_Buf;}
        
        break;
        
        default:;
    }
    return dta;
}


unsigned int get_addr_dta(unsigned char addr_reg, unsigned char __dta){ //Gas Sensor
    START: 
    Wire.beginTransmission(0x16);
    Wire.write(addr_reg);
    Wire.write(__dta);
    Wire.endTransmission();
    delay(5); //CRITICAL, DO NOT REMOVE
    Wire.requestFrom(0x16, 2);
    
    unsigned int dta = 0;
    unsigned char raw[10];
    int cnt = 0;
    while(Wire.available()){raw[cnt++] = Wire.read();}
    
    if(cnt == 0)goto START;
    
    dta = raw[0];
    dta <<= 8;
    dta += raw[1];

    return dta;
}

void ledOn() //Gas Sensor
    {
        dta_test[0] = CMD_CONTROL_LED;
        dta_test[1] = 1;
        write_i2c(0x16, dta_test, 2);
    }
void ledOff() //Gas Sensor
    {
        dta_test[0] = CMD_CONTROL_LED;
        dta_test[1] = 0;
        write_i2c(0x16, dta_test, 2);
    }
