microDS18B20 icon indicating copy to clipboard operation
microDS18B20 copied to clipboard

getResolution()

Open cubik2k opened this issue 2 years ago • 2 comments

added getResolution()

cubik2k avatar Nov 26 '22 21:11 cubik2k

You left sum and crc, it's doesn't make sense :) it would be better to get resolution byte from readTemp routine

GyverLibs avatar Nov 27 '22 08:11 GyverLibs

Yes, you are right, thank you :)

do you mean this: ?

    // прочитать температуру с датчика. true если успешно
    bool readTemp(uint8_t idx = 0) {
        state[idx] = 1;
        if (!oneWire_reset(DS_PIN)) return 0;       // датчик оффлайн
        addressRoutine(idx);                   		// Процедура адресации
        oneWire_write(0xBE, DS_PIN);                // Запросить температуру
        uint8_t res = 0;                            // variable for resolution
        uint8_t crc = 0;                            // обнуляем crc
        int16_t temp;                               // переменная для расчёта температуры
        uint16_t sum = 0;                           // контрольная сумма
        for (uint8_t i = 0; i < 9; i++) {           // Считать RAM
            uint8_t data = oneWire_read(DS_PIN);    // Прочитать данные
            sum += data;
            #if (DS_CHECK_CRC == true)
            _ds_crc8_upd(crc, data);                // Обновить значение CRC8
            #endif
            if (i == 0) temp = data;
            else if (i == 1) temp |= (data << 8);
            if (i == 4) res = data;
        }
        if (sum == 0x8F7 || !sum || crc) return 0;  // датчик оффлайн или данные повреждены        
        if (temp != 0x0550) _buf[idx] = temp;       // пропускаем первое чтение (85 градусов)
        if (res != 0x00) _res[idx] = res;           // reading resolution
        return 1;
    }

cubik2k avatar Nov 27 '22 09:11 cubik2k