Обновлена библиотека для датчиков с py32 модуля
This commit is contained in:
@@ -17,6 +17,9 @@ OneWire_t OW;
|
||||
*/
|
||||
HAL_StatusTypeDef DS18B20_IsValidAddress(uint8_t *ROM)
|
||||
{
|
||||
if(ROM == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
uint8_t check_family = (*ROM == DS18B20_FAMILY_CODE);
|
||||
/* Calculate CRC */
|
||||
uint8_t crc = OneWire_CRC8(ROM, 7);
|
||||
@@ -34,6 +37,9 @@ HAL_StatusTypeDef DS18B20_IsValidAddress(uint8_t *ROM)
|
||||
*/
|
||||
HAL_StatusTypeDef DS18B20_IsValid(uint8_t *ROM)
|
||||
{
|
||||
if(ROM == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
if(*ROM == DS18B20_FAMILY_CODE)
|
||||
return HAL_OK;
|
||||
else
|
||||
@@ -49,6 +55,11 @@ HAL_StatusTypeDef DS18B20_IsValid(uint8_t *ROM)
|
||||
uint8_t DS18B20_GetResolution(OneWire_t* OW, uint8_t *ROM) {
|
||||
uint8_t conf;
|
||||
|
||||
if(OW == NULL)
|
||||
return HAL_ERROR;
|
||||
if(ROM == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
/* Check valid ROM */
|
||||
if (DS18B20_IsValid(ROM) != HAL_OK)
|
||||
return 0;
|
||||
@@ -85,6 +96,11 @@ uint8_t DS18B20_GetResolution(OneWire_t* OW, uint8_t *ROM) {
|
||||
HAL_StatusTypeDef DS18B20_SetResolution(OneWire_t* OW, uint8_t *ROM,
|
||||
DS18B20_Res_t Resolution)
|
||||
{
|
||||
if(OW == NULL)
|
||||
return HAL_ERROR;
|
||||
if(ROM == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
uint8_t th, tl, conf;
|
||||
|
||||
/* Check valid ROM */
|
||||
@@ -146,6 +162,11 @@ HAL_StatusTypeDef DS18B20_SetResolution(OneWire_t* OW, uint8_t *ROM,
|
||||
*/
|
||||
HAL_StatusTypeDef DS18B20_StartConvT(OneWire_t* OW, uint8_t *ROM)
|
||||
{
|
||||
if(OW == NULL)
|
||||
return HAL_ERROR;
|
||||
if(ROM == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
/* Check if device is DS18B20 */
|
||||
if(DS18B20_IsValid(ROM) != HAL_OK)
|
||||
return HAL_ERROR;
|
||||
@@ -167,6 +188,9 @@ HAL_StatusTypeDef DS18B20_StartConvT(OneWire_t* OW, uint8_t *ROM)
|
||||
*/
|
||||
HAL_StatusTypeDef DS18B20_StartConvTAll(OneWire_t* OW)
|
||||
{
|
||||
if(OW == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
/* Reset pulse */
|
||||
OneWire_Reset(OW);
|
||||
|
||||
@@ -189,6 +213,15 @@ HAL_StatusTypeDef DS18B20_StartConvTAll(OneWire_t* OW)
|
||||
*/
|
||||
HAL_StatusTypeDef DS18B20_CalcTemperature(OneWire_t* OW, uint8_t *ROM, uint8_t *Scratchpad, float *Destination)
|
||||
{
|
||||
if(OW == NULL)
|
||||
return HAL_ERROR;
|
||||
if(ROM == NULL)
|
||||
return HAL_ERROR;
|
||||
if(Scratchpad == NULL)
|
||||
return HAL_ERROR;
|
||||
if(Destination == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
uint16_t temperature;
|
||||
uint8_t resolution;
|
||||
int8_t digit, minus = 0;
|
||||
@@ -256,8 +289,6 @@ HAL_StatusTypeDef DS18B20_CalcTemperature(OneWire_t* OW, uint8_t *ROM, uint8_t *
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t scratchpad_buff[8];
|
||||
/**
|
||||
* @brief The function is used as read scratchpad from device
|
||||
* @retval status in OK = 1, Failed = 0
|
||||
@@ -267,8 +298,12 @@ uint8_t scratchpad_buff[8];
|
||||
*/
|
||||
HAL_StatusTypeDef DS18B20_ReadScratchpad(OneWire_t* OW, uint8_t *ROM, uint8_t *Scratchpad)
|
||||
{
|
||||
if(OW == NULL)
|
||||
return HAL_ERROR;
|
||||
if(ROM == NULL)
|
||||
return HAL_ERROR;
|
||||
if(Scratchpad == NULL)
|
||||
Scratchpad = scratchpad_buff;
|
||||
return HAL_ERROR;
|
||||
|
||||
/* Reset line */
|
||||
OneWire_Reset(OW);
|
||||
@@ -303,6 +338,8 @@ HAL_StatusTypeDef DS18B20_ReadScratchpad(OneWire_t* OW, uint8_t *ROM, uint8_t *S
|
||||
*/
|
||||
HAL_StatusTypeDef DS18B20_WaitForEndConvertion(OneWire_t* OW)
|
||||
{
|
||||
if(OW == NULL)
|
||||
return HAL_ERROR;
|
||||
uint32_t tickstart = HAL_GetTick();
|
||||
|
||||
/* Wait until line is released, then coversion is completed */
|
||||
@@ -315,6 +352,22 @@ HAL_StatusTypeDef DS18B20_WaitForEndConvertion(OneWire_t* OW)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief The function is used to wait for end of convertion without blocking
|
||||
* @param OW OneWire HandleTypedef
|
||||
*/
|
||||
HAL_StatusTypeDef DS18B20_WaitForEndConvertion_NonBlocking(OneWire_t* OW)
|
||||
{
|
||||
if(OW == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
/* If line is pull down - conversion is ongoing */
|
||||
if(OneWire_ReadBit(OW) == 0)
|
||||
return HAL_BUSY;
|
||||
else
|
||||
return HAL_OK; // convertion done
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief The function is used as set temperature alarm range on
|
||||
@@ -328,6 +381,11 @@ HAL_StatusTypeDef DS18B20_WaitForEndConvertion(OneWire_t* OW)
|
||||
HAL_StatusTypeDef DS18B20_SetTempAlarm(OneWire_t* OW, uint8_t *ROM, int8_t Low,
|
||||
int8_t High)
|
||||
{
|
||||
if(OW == NULL)
|
||||
return HAL_ERROR;
|
||||
if(ROM == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
uint8_t tl, th, conf;
|
||||
|
||||
/* Check if device is DS18B20 */
|
||||
@@ -396,6 +454,11 @@ HAL_StatusTypeDef DS18B20_SetTempAlarm(OneWire_t* OW, uint8_t *ROM, int8_t Low,
|
||||
HAL_StatusTypeDef DS18B20_WriteUserBytes(OneWire_t* OW, uint8_t *ROM, int16_t UserBytes12,
|
||||
int16_t UserBytes34, uint8_t UserBytesMask)
|
||||
{
|
||||
if(OW == NULL)
|
||||
return HAL_ERROR;
|
||||
if(ROM == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
uint8_t ub1, ub2, conf, ub3, ub4;
|
||||
uint8_t UserByte1 = UserBytes12 & 0xFF;
|
||||
uint8_t UserByte2 = UserBytes12 >> 8;
|
||||
@@ -475,35 +538,35 @@ HAL_StatusTypeDef DS18B20_WriteUserBytes(OneWire_t* OW, uint8_t *ROM, int16_t Us
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief The function is used as search device that had temperature alarm
|
||||
* triggered and store it in DS18B20 alarm data structure
|
||||
* @retval status of search, OK = 1, Failed = 0
|
||||
* @param DS DS18B20 HandleTypedef
|
||||
* @param OW OneWire HandleTypedef
|
||||
*/
|
||||
uint8_t DS18B20_AlarmSearch(DS18B20_Drv_t *DS, OneWire_t* OW)
|
||||
{
|
||||
uint8_t t = 0;
|
||||
///**
|
||||
// * @brief The function is used as search device that had temperature alarm
|
||||
// * triggered and store it in DS18B20 alarm data structure
|
||||
// * @retval status of search, OK = 1, Failed = 0
|
||||
// * @param DS DS18B20 HandleTypedef
|
||||
// * @param OW OneWire HandleTypedef
|
||||
// */
|
||||
//uint8_t DS18B20_AlarmSearch(DS18B20_Drv_t *DS, OneWire_t* OW)
|
||||
//{
|
||||
// uint8_t t = 0;
|
||||
|
||||
/* Reset Alarm in DS */
|
||||
for(uint8_t i = 0; i < OW->RomCnt; i++)
|
||||
{
|
||||
for(uint8_t j = 0; j < 8; j++)
|
||||
{
|
||||
DS->AlmAddr[i][j] = 0;
|
||||
}
|
||||
}
|
||||
// /* Reset Alarm in DS */
|
||||
// for(uint8_t i = 0; i < OW->RomCnt; i++)
|
||||
// {
|
||||
// for(uint8_t j = 0; j < 8; j++)
|
||||
// {
|
||||
// DS->AlmAddr[i][j] = 0;
|
||||
// }
|
||||
// }
|
||||
|
||||
/* Start alarm search */
|
||||
while (OneWire_Search(OW, DS18B20_CMD_ALARM_SEARCH))
|
||||
{
|
||||
/* Store ROM of device which has alarm flag set */
|
||||
OneWire_GetDevRom(OW, DS->AlmAddr[t]);
|
||||
t++;
|
||||
}
|
||||
return (t > 0) ? 1 : 0;
|
||||
}
|
||||
// /* Start alarm search */
|
||||
// while (OneWire_Search(OW, DS18B20_CMD_ALARM_SEARCH))
|
||||
// {
|
||||
// /* Store ROM of device which has alarm flag set */
|
||||
// OneWire_GetDevRom(OW, DS->AlmAddr[t]);
|
||||
// t++;
|
||||
// }
|
||||
// return (t > 0) ? 1 : 0;
|
||||
//}
|
||||
|
||||
/**
|
||||
* @brief The function is used to initialize the DS18B20 sensor, and search
|
||||
@@ -514,6 +577,10 @@ uint8_t DS18B20_AlarmSearch(DS18B20_Drv_t *DS, OneWire_t* OW)
|
||||
*/
|
||||
HAL_StatusTypeDef DS18B20_Search(DS18B20_Drv_t *DS, OneWire_t *OW)
|
||||
{
|
||||
if(OW == NULL)
|
||||
return HAL_ERROR;
|
||||
|
||||
|
||||
OW->RomCnt = 0;
|
||||
/* Search all OneWire devices ROM */
|
||||
while(1)
|
||||
|
||||
Reference in New Issue
Block a user