auralix / alx-202-af-10-1-auralix-c-lib

GNU General Public License v3.0
0 stars 0 forks source link

AlxTmp1075_GetTemp_degC - I2C return not handled correctly #44

Open tomazvidovic opened 1 year ago

tomazvidovic commented 1 year ago

Function should return Alx_Status, temperature should be returned by pointer argument.. also C++ lib should be changed accordingly

float AlxTmp1075_GetTemp_degC(AlxTmp1075* me)
{
    ALX_TMP1075_ASSERT(me->isInit == true);
    ALX_TMP1075_ASSERT(me->wasCtorCalled == true);

    // auralix/alx-202-af-10-1-auralix-c-lib#12 Prepare variables
    Alx_Status status = Alx_Err;

    // auralix/alx-202-af-10-1-auralix-c-lib#13 Read temperature data
    status = AlxTmp1075_Reg_Read(me, &me->reg.R0_Temp);
    if (status != Alx_Ok) { ALX_TMP1075_TRACE("Err_AlxTmp1075_Reg_Read"); }

    // auralix/alx-202-af-10-1-auralix-c-lib#14 Shift value to get rid of the 4 unused bits
    me->temp_raw = me->reg.R0_Temp.val.T  >> 4;

    // auralix/alx-202-af-10-1-auralix-c-lib#15 Calculate
    me->temp_degC = me->temp_raw  * me->DEG_C_PER_BIT;

    return me->temp_degC;
}