Инициализация датчиков сделана по функции в структуре. По какому алгоритму надо найти датчик (ROM, UserBytes, порядковый номер) та функцию и пихается в структуру

Сделан поиск потерянных датчиков по функции в структуре (по тому же алгоритму, которому они были найдены)
This commit is contained in:
2025-02-06 18:47:20 +03:00
parent 9296faa0fb
commit 1de01f5665
4 changed files with 303 additions and 84 deletions

View File

@@ -14,6 +14,7 @@
/* Includes ----------------------------------------------------------------*/
#include "dallas_tools.h"
#include "string.h"
/* Declarations and definitions --------------------------------------------*/
@@ -37,14 +38,31 @@ void Dallas_ReadAll(void)
HAL_StatusTypeDef result;
result = Dallas_StartConvertTAll(&OW, DALLAS_WAIT_BUS, 0);
result = Dallas_ReadTemperature(&AllSens.outdoor);
result = Dallas_ReadTemperature(&AllSens.indoor);
result = Dallas_ReadTemperature(&AllSens.bathroom);
result = Dallas_ReadTemperature(&AllSens.kitchen);
result = Dallas_ReadTemperature(&AllSens.big_room);
result = Dallas_ReadTemperature(&AllSens.small_room);
result = Dallas_ReadTemperature(&AllSens.living_room);
result = Dallas_ReadTemperature(&AllSens.basement);
if(Dallas_ReadTemperature(&AllSens.outdoor) == HAL_BUSY)
Dallas_ReplaceLostedSensor(&AllSens.outdoor);
if(Dallas_ReadTemperature(&AllSens.indoor) == HAL_BUSY)
Dallas_ReplaceLostedSensor(&AllSens.indoor);
if(Dallas_ReadTemperature(&AllSens.bathroom) == HAL_BUSY)
Dallas_ReplaceLostedSensor(&AllSens.bathroom);
if(Dallas_ReadTemperature(&AllSens.kitchen) == HAL_BUSY)
Dallas_ReplaceLostedSensor(&AllSens.kitchen);
if(Dallas_ReadTemperature(&AllSens.big_room) == HAL_BUSY)
Dallas_ReplaceLostedSensor(&AllSens.big_room);
if(Dallas_ReadTemperature(&AllSens.small_room) == HAL_BUSY)
Dallas_ReplaceLostedSensor(&AllSens.small_room);
if(Dallas_ReadTemperature(&AllSens.living_room) == HAL_BUSY)
Dallas_ReplaceLostedSensor(&AllSens.living_room);
if(Dallas_ReadTemperature(&AllSens.basement) == HAL_BUSY)
Dallas_ReplaceLostedSensor(&AllSens.basement);
}
void Dallas_FirstInit(void)
@@ -55,27 +73,54 @@ void Dallas_FirstInit(void)
OneWire_Init(&OW);
DS18B20_Search(&DS, &OW);
AllSens.outdoor.Init.ROM = 0x28C60C61060000DC;
AllSens.indoor.Init.ROM = 0x283E4861060000F9;
AllSens.bathroom.Init.ROM = 0x28876D60060000CD;
Dallas_SensorInitByROM(&OW, &AllSens.outdoor, 0x28C60C61060000DC);
Dallas_SensorInitByROM(&OW, &AllSens.indoor, 0x283E4861060000F9);
Dallas_SensorInitByROM(&OW, &AllSens.bathroom, 0x28876D60060000CD);
AllSens.outdoor.Init.SensInd = 0;
AllSens.indoor.Init.SensInd = 1;
AllSens.bathroom.Init.SensInd = 2;
AllSens.kitchen.Init.SensInd = 3;
AllSens.big_room.Init.SensInd = 4;
AllSens.small_room.Init.SensInd = 5;
AllSens.living_room.Init.SensInd = 6;
AllSens.basement.Init.SensInd = 7;
AllSens.outdoor.Init.UserBytes12 = 1;
AllSens.indoor.Init.UserBytes12 = 2;
AllSens.bathroom.Init.UserBytes12 = 3;
AllSens.kitchen.Init.UserBytes12 = 4;
AllSens.big_room.Init.UserBytes12 = 5;
AllSens.small_room.Init.UserBytes12 = 6;
AllSens.living_room.Init.UserBytes12 = 7;
AllSens.basement.Init.UserBytes12 = 8;
uint8_t mask = DALLAS_USER_BYTE_ALL;
// Dallas_SensorInitByUserBytes(&OW, &AllSens.outdoor, 1, NULL);
// Dallas_SensorInitByUserBytes(&OW, &AllSens.indoor, 2, NULL);
// Dallas_SensorInitByUserBytes(&OW, &AllSens.bathroom, 3, NULL);
AllSens.outdoor.Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
AllSens.indoor.Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
AllSens.bathroom.Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
AllSens.kitchen.Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
AllSens.big_room.Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
AllSens.small_room.Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
AllSens.living_room.Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
AllSens.basement.Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
Dallas_AddNewSensors(&OW, &AllSens.outdoor);
Dallas_AddNewSensors(&OW, &AllSens.indoor);
Dallas_AddNewSensors(&OW, &AllSens.bathroom);
//
// Dallas_SensorInitByInd(&OW, &AllSens.outdoor, 0);
// Dallas_SensorInitByInd(&OW, &AllSens.indoor, 1);
// Dallas_SensorInitByInd(&OW, &AllSens.bathroom, 2);
// Dallas_SensorInitByInd(&OW, &AllSens.indoor, 2);
// Dallas_SensorInitByInd(&OW, &AllSens.bathroom, 1);
// Dallas_SensorInitByInd(&OW, &AllSens.kitchen, 3);
// Dallas_SensorInitByInd(&OW, &AllSens.big_room, 4);
// Dallas_SensorInitByInd(&OW, &AllSens.small_room, 5);
// Dallas_SensorInitByInd(&OW, &AllSens.living_room, 6);
// Dallas_SensorInitByInd(&OW, &AllSens.basement, 7);
//
//
// uint8_t mask = DALLAS_USER_BYTE_ALL;
// Dallas_WriteUserBytes(&AllSens.outdoor, 1, NULL, mask);
// Dallas_WriteUserBytes(&AllSens.indoor, 2, NULL, mask);
// Dallas_WriteUserBytes(&AllSens.bathroom, 3, NULL, mask);
@@ -87,35 +132,93 @@ void Dallas_FirstInit(void)
}
/**
* @brief Èíèöèàëèçèðóåò ñòðóêòóðó äàò÷èêà ïî èíäåêó
* @param onewire Óêàçàòåëü íà ñòðóêòóðó OneWire
* @brief Ôóíêöèÿ äëÿ íàõîæäåíèÿ íîâîãî äàò÷èêà íà ìåñòî ïîòåðÿííîãî
* @param sensor Óêàçàòåëü íà ñòðóêòóðó äàò÷èêà
* @param ROM Óêàçàòåëü íà ROM äëÿ îïðåäåëåíèÿ íóæíîãî äàò÷èêà
* @retval HAL Status
*/
HAL_StatusTypeDef Dallas_SensorInitByROM(OneWire_t *onewire, DALLAS_HandleTypeDef *sensor, uint64_t intROM)
HAL_StatusTypeDef Dallas_ReplaceLostedSensor(DALLAS_HandleTypeDef *sensor)
{
HAL_StatusTypeDef result;
sensor->isInitialized = 0;
if(sensor == NULL)
return HAL_ERROR;
if(AllSens.outdoor.isLost)
{
if(DS18B20_Search(&DS, &OW) != HAL_OK)
return HAL_ERROR;
if(sensor->Init.init_func(sensor->onewire, sensor) != HAL_OK)
return HAL_ERROR;
}
else
{
/*unknown sensor*/
return HAL_ERROR;
}
return HAL_OK;
}
/**
* @brief Ôóíêöèÿ äëÿ äîáàâëåíèÿ íîâîãî äàò÷èêà â ñòðóêòóðó
* @param onewire Óêàçàòåëü íà ñòðóêòóðó OneWire
* @param sensor Óêàçàòåëü íà ñòðóêòóðó äàò÷èêà
* @retval HAL Status
*/
HAL_StatusTypeDef Dallas_AddNewSensors(OneWire_t *onewire, DALLAS_HandleTypeDef *sensor)
{
HAL_StatusTypeDef result;
if(onewire == NULL)
return HAL_ERROR;
if(sensor == NULL)
return HAL_ERROR;
sensor->onewire = onewire;
uint8_t ROM[8] = {0};
ROM[0] = (intROM >> (7*8)) & 0xFF;
ROM[1] = (intROM >> (6*8)) & 0xFF;
ROM[2] = (intROM >> (5*8)) & 0xFF;
ROM[3] = (intROM >> (4*8)) & 0xFF;
ROM[4] = (intROM >> (3*8)) & 0xFF;
ROM[5] = (intROM >> (2*8)) & 0xFF;
ROM[6] = (intROM >> (1*8)) & 0xFF;
ROM[7] = (intROM) & 0xFF;
result = sensor->Init.init_func(onewire, sensor);
return result;
}
/**
* @brief Èíèöèàëèçèðóåò ñòðóêòóðó äàò÷èêà ïî ROM
* @param onewire Óêàçàòåëü íà ñòðóêòóðó OneWire
* @param sensor Óêàçàòåëü íà ñòðóêòóðó äàò÷èêà
* @retval HAL Status
*/
HAL_StatusTypeDef Dallas_SensorInitByROM(OneWire_t *onewire, DALLAS_HandleTypeDef *sensor)
{
HAL_StatusTypeDef result;
if(onewire == NULL)
return HAL_ERROR;
if(sensor == NULL)
return HAL_ERROR;
uint8_t ROM[8] = {0};
ROM[0] = (sensor->Init.ROM >> (7*8)) & 0xFF;
ROM[1] = (sensor->Init.ROM >> (6*8)) & 0xFF;
ROM[2] = (sensor->Init.ROM >> (5*8)) & 0xFF;
ROM[3] = (sensor->Init.ROM >> (4*8)) & 0xFF;
ROM[4] = (sensor->Init.ROM >> (3*8)) & 0xFF;
ROM[5] = (sensor->Init.ROM >> (2*8)) & 0xFF;
ROM[6] = (sensor->Init.ROM >> (1*8)) & 0xFF;
ROM[7] = (sensor->Init.ROM) & 0xFF;
if(DS18B20_IsValidAddress(ROM) != HAL_OK)
return HAL_ERROR;
uint8_t comparebytes = DALLAS_ROM_SIZE;
int ROM_ind = 0;
for(int i = 0; i < DS18B20_DEVICE_AMOUNT; i++)
{
comparebytes = DALLAS_ROM_SIZE;
@@ -126,7 +229,7 @@ HAL_StatusTypeDef Dallas_SensorInitByROM(OneWire_t *onewire, DALLAS_HandleTypeDe
}
if(comparebytes == 0)
{
sensor->sensROM = &DS.DevAddr[i];
ROM_ind = i;
break;
}
}
@@ -134,12 +237,14 @@ HAL_StatusTypeDef Dallas_SensorInitByROM(OneWire_t *onewire, DALLAS_HandleTypeDe
if(comparebytes == 0)
{
result = Dallas_IsConnected(sensor);
if(result != HAL_OK)
// result = Dallas_IsConnected(sensor);
// if(result != HAL_OK)
// return result;
//
// sensor->isInitialized = 1;
// sensor->Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByROM;
result = Dallas_SensorInit(onewire, sensor, &DS.DevAddr[ROM_ind]);
return result;
sensor->isInitialized = 1;
return HAL_OK;
}
else
{
@@ -160,40 +265,39 @@ HAL_StatusTypeDef Dallas_SensorInitByROM(OneWire_t *onewire, DALLAS_HandleTypeDe
* @retval HAL Status
* @details ñòàðøèé áàéò - UserByte4/UserByte2, ìëàäøèé - UserByte3/UserByte1.
*/
HAL_StatusTypeDef Dallas_SensorInitByUserBytes(OneWire_t *onewire, DALLAS_HandleTypeDef *sensor, uint16_t UserBytes12, uint16_t UserBytes34)
HAL_StatusTypeDef Dallas_SensorInitByUserBytes(OneWire_t *onewire, DALLAS_HandleTypeDef *sensor)
{
HAL_StatusTypeDef result;
sensor->isInitialized = 0;
if(onewire == NULL)
return HAL_ERROR;
if(sensor == NULL)
return HAL_ERROR;
sensor->onewire = onewire;
uint8_t UserByte1 = UserBytes12 & 0xFF;
uint8_t UserByte2 = UserBytes12 >> 8;
uint8_t UserByte3 = UserBytes34 & 0xFF;
uint8_t UserByte4 = UserBytes34 >> 8;
uint8_t UserByte1 = sensor->Init.UserBytes12 & 0xFF;
uint8_t UserByte2 = sensor->Init.UserBytes12 >> 8;
uint8_t UserByte3 = sensor->Init.UserBytes34 & 0xFF;
uint8_t UserByte4 = sensor->Init.UserBytes34 >> 8;
uint8_t UserByte12Cmp = 0;
uint8_t UserByte34Cmp = 0;
DALLAS_ScratchpadTypeDef scratchpad;
for(int i = 0; i < DS18B20_DEVICE_AMOUNT; i++)
{
UserByte12Cmp = 0; UserByte34Cmp = 0;
sensor->sensROM = &DS.DevAddr[i];
for(int rom_ind = 0; rom_ind < DALLAS_ROM_SIZE; rom_ind++)
/* Ïðîâåðêà ïðèñóòñòâóåò ëè âûáðàííûé äàò÷èê íà ëèíèè */
result = Dallas_IsConnected(sensor);
result = DS18B20_ReadScratchpad(onewire, (uint8_t *)&DS.DevAddr[i], (uint8_t *)&scratchpad);
if (result != HAL_OK)
return result;
/* Ñðàâíåíèå UserByte1 è UserByte2, åñëè âûáðàíî */
if(UserBytes12 != NULL)
if(sensor->Init.UserBytes12 != NULL)
{
if( (sensor->scratchpad.tHighRegister == UserByte1) &&
(sensor->scratchpad.tLowRegister == UserByte2))
if( (scratchpad.tHighRegister == UserByte1) &&
(scratchpad.tLowRegister == UserByte2))
{
UserByte12Cmp = 1;
}
@@ -203,10 +307,10 @@ HAL_StatusTypeDef Dallas_SensorInitByUserBytes(OneWire_t *onewire, DALLAS_Handle
UserByte12Cmp = 1;
}
/* Ñðàâíåíèå UserByte3 è UserByte4, åñëè âûáðàíî */
if(UserBytes34 != NULL)
if(sensor->Init.UserBytes34 != NULL)
{
if( (sensor->scratchpad.UserByte3 == UserByte3) &&
(sensor->scratchpad.UserByte4 == UserByte4))
if( (scratchpad.UserByte3 == UserByte3) &&
(scratchpad.UserByte4 == UserByte4))
{
UserByte34Cmp = 1;
}
@@ -218,10 +322,13 @@ HAL_StatusTypeDef Dallas_SensorInitByUserBytes(OneWire_t *onewire, DALLAS_Handle
/* Åñëè íàøëè íóæíûé äàò÷èê - çàâåðøàåì ïîèñê */
if(UserByte12Cmp && UserByte34Cmp)
{
sensor->isInitialized = 1;
return HAL_OK;
// sensor->isInitialized = 1;
// sensor->Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
result = Dallas_SensorInit(onewire, sensor, &DS.DevAddr[i]);
return result;
}
}
Dallas_SensorDeInit(sensor);
/* Âîçâðàùàåì îøèáêó åñëè íå íàøëè */
return HAL_ERROR;
}
@@ -235,28 +342,94 @@ HAL_StatusTypeDef Dallas_SensorInitByUserBytes(OneWire_t *onewire, DALLAS_Handle
* @details Èíäåêñ - ýòî ïîðÿäêîâûé íîìåð äàò÷èêà â ñïèñêå íàéäåííûõ.
* Ò.å. êàêèì ïî ñ÷åòó ýòîò äàò÷èê áûë íàéäåí
*/
HAL_StatusTypeDef Dallas_SensorInitByInd(OneWire_t *onewire, DALLAS_HandleTypeDef *sensor, uint8_t sens_ind)
HAL_StatusTypeDef Dallas_SensorInitByInd(OneWire_t *onewire, DALLAS_HandleTypeDef *sensor)
{
HAL_StatusTypeDef result;
sensor->isInitialized = 0;
if(onewire == NULL)
return HAL_ERROR;
if(sensor == NULL)
return HAL_ERROR;
sensor->onewire = onewire;
sensor->sensROM = &DS.DevAddr[sens_ind];
// sensor->onewire = onewire;
// sensor->sensROM = &DS.DevAddr[sensor->Init.SensInd];
// sensor->Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByInd;
result = Dallas_SensorInit(onewire, sensor, &DS.DevAddr[sensor->Init.SensInd]);
return result;
}
/**
* @brief Èíèöèàëèçèðóåò äàò÷èê äëÿ ðàáîòû
* @param onewire Óêàçàòåëü íà ñòðóêòóðó OneWire
* @param sensor Óêàçàòåëü íà ñòðóêòóðó äàò÷èêà
* @param sens_ind Ïîðÿäêîâûé íîìåð äàò÷èêà â ñòðóêòóðå
* @retval HAL Status
* @details Èíäåêñ - ýòî ïîðÿäêîâûé íîìåð äàò÷èêà â ñïèñêå íàéäåííûõ.
* Ò.å. êàêèì ïî ñ÷åòó ýòîò äàò÷èê áûë íàéäåí
*/
HAL_StatusTypeDef Dallas_SensorInit(OneWire_t *onewire, DALLAS_HandleTypeDef *sensor, uint8_t (*ROM)[DALLAS_ROM_SIZE])
{
HAL_StatusTypeDef result;
if(sensor == NULL)
return HAL_ERROR;
if(onewire == 0)
return HAL_ERROR;
sensor->onewire = onewire;
for(int i = 0; i < DALLAS_ROM_SIZE; i++)
sensor->sensROM[i] = (*ROM)[i];
/* Ïðîâåðêà ïðèñóòñòâóåò ëè âûáðàííûé äàò÷èê íà ëèíèè */
result = Dallas_IsConnected(sensor);
if (result != HAL_OK)
return result;
result = DS18B20_ReadScratchpad(sensor->onewire, (uint8_t *)sensor->sensROM, (uint8_t *)&sensor->scratchpad);
if (result == HAL_OK)
{
/* Óñòàíîâêà ðàçðåøåíèÿ */
result = DS18B20_SetResolution(onewire, (uint8_t *)ROM, sensor->Init.Resolution);
if (result == HAL_OK)
{
sensor->isInitialized = 1;
return HAL_OK;
}
else
{
sensor->isInitialized = 0;
Dallas_SensorDeInit(sensor);
return result;
}
}
else
{
sensor->isInitialized = 0;
Dallas_SensorDeInit(sensor);
return result;
}
}
/**
* @brief Äåèíèöèàëèçèðóåò ïîëíîñòüþ ñòðóêòóðó äàò÷èêà
* @param onewire Óêàçàòåëü íà ñòðóêòóðó OneWire
* @param sensor Óêàçàòåëü íà ñòðóêòóðó äàò÷èêà
* @param sens_ind Ïîðÿäêîâûé íîìåð äàò÷èêà â ñòðóêòóðå
* @retval HAL Status
* @details Èíäåêñ - ýòî ïîðÿäêîâûé íîìåð äàò÷èêà â ñïèñêå íàéäåííûõ.
* Ò.å. êàêèì ïî ñ÷åòó ýòîò äàò÷èê áûë íàéäåí
*/
HAL_StatusTypeDef Dallas_SensorDeInit(DALLAS_HandleTypeDef *sensor)
{
if(sensor == NULL)
return HAL_ERROR;
DALLAS_InitStructTypeDef initbuff = sensor->Init;
memset(sensor, 0, sizeof(DALLAS_HandleTypeDef));
sensor->Init = initbuff;
return HAL_OK;
}
/**
* @brief Çàïóñêàåò èçìåðåíèå òåìïåðàòóðû íà âñåõ äàò÷èêàõ
@@ -268,6 +441,9 @@ HAL_StatusTypeDef Dallas_StartConvertTAll(OneWire_t *onewire, DALLAS_WaitConditi
HAL_StatusTypeDef result;
uint8_t rxDummyData;
if(onewire == NULL)
return HAL_ERROR;
// Îòïðàâêà êîìàíäû íà÷àëà ïðåîáðàçîâàíèÿ òåìïåðàòóðû
result = DS18B20_StartConvTAll(onewire);
if(result != HAL_OK)
@@ -326,6 +502,11 @@ HAL_StatusTypeDef Dallas_ConvertT(DALLAS_HandleTypeDef *sensor, DALLAS_WaitCondi
HAL_StatusTypeDef result;
uint8_t rxDummyData;
if(sensor == NULL)
return HAL_ERROR;
if(sensor->isInitialized == 0)
return HAL_ERROR;
/* Ïðîâåðêà ïðèñóòñòâóåò ëè âûáðàííûé äàò÷èê íà ëèíèè */
result = Dallas_IsConnected(sensor);
if (result != HAL_OK)
@@ -398,6 +579,11 @@ HAL_StatusTypeDef Dallas_ReadTemperature(DALLAS_HandleTypeDef *sensor)
{
HAL_StatusTypeDef result;
if(sensor == NULL)
return HAL_ERROR;
if(sensor->isInitialized == 0)
return HAL_ERROR;
/* Ïðîâåðêà ïðèñóòñòâóåò ëè âûáðàííûé äàò÷èê íà ëèíèè */
result = Dallas_IsConnected(sensor);
if (result != HAL_OK)
@@ -424,11 +610,15 @@ HAL_StatusTypeDef Dallas_IsConnected(DALLAS_HandleTypeDef *sensor)
{
HAL_StatusTypeDef result;
if(sensor->isInitialized == 0)
return HAL_ERROR;
result = DS18B20_ReadScratchpad(sensor->onewire, (uint8_t *)sensor->sensROM, (uint8_t *)&sensor->scratchpad);
if (result == HAL_OK)
{
sensor->isConnected = 1;
sensor->isLost = 0;
return HAL_OK;
}
else
@@ -436,6 +626,7 @@ HAL_StatusTypeDef Dallas_IsConnected(DALLAS_HandleTypeDef *sensor)
if(sensor->isConnected == 1)
{
sensor->f.disconnect_cnt++;
sensor->isLost = 1;
}
sensor->isConnected = 0;
return HAL_BUSY; // èñïîëüçóþ busy, ÷òîáû îòëè÷àòü ñèòóàöèþ îò HAL_ERROR
@@ -453,7 +644,17 @@ HAL_StatusTypeDef Dallas_IsConnected(DALLAS_HandleTypeDef *sensor)
*/
HAL_StatusTypeDef Dallas_WriteUserBytes(DALLAS_HandleTypeDef *sensor, uint16_t UserBytes12, uint16_t UserBytes34, uint8_t UserBytesMask)
{
HAL_StatusTypeDef result = DS18B20_WriteUserBytes(sensor->onewire, (uint8_t *)sensor->sensROM, UserBytes12, UserBytes34, UserBytesMask);
HAL_StatusTypeDef result;
if(sensor->isInitialized == 0)
return HAL_ERROR;
/* Ïðîâåðêà ïðèñóòñòâóåò ëè âûáðàííûé äàò÷èê íà ëèíèè */
result = Dallas_IsConnected(sensor);
if (result != HAL_OK)
return result;
result = DS18B20_WriteUserBytes(sensor->onewire, (uint8_t *)sensor->sensROM, UserBytes12, UserBytes34, UserBytesMask);
if (result != HAL_OK)
{
sensor->f.read_temperature_err_cnt++;

View File

@@ -85,21 +85,34 @@ typedef struct
}DALLAS_FlagsTypeDef;
typedef struct
{
uint64_t ROM;
uint16_t UserBytes12;
uint16_t UserBytes34;
uint8_t SensInd;
uint8_t Resolution;
HAL_StatusTypeDef (*init_func)();
}DALLAS_InitStructTypeDef;
typedef struct
{
uint8_t isConnected;
uint8_t isInitialized;
uint8_t isLost;
#ifdef ONEWIRE_UART_H
UART_HandleTypeDef *uart;
#else
OneWire_t *onewire;
#endif
uint8_t (*sensROM)[DALLAS_ROM_SIZE];
uint8_t sensROM[DALLAS_ROM_SIZE];
DALLAS_ScratchpadTypeDef scratchpad;
float temperature;
DALLAS_InitStructTypeDef Init;
DALLAS_FlagsTypeDef f;
}DALLAS_HandleTypeDef;
@@ -128,9 +141,13 @@ typedef enum
void Dallas_Init(DALLAS_HandleTypeDef *sensor, UART_HandleTypeDef *huart);
void Dallas_ReadAll(void);
void Dallas_FirstInit(void);
HAL_StatusTypeDef Dallas_SensorInitByROM(OneWire_t *onewire, DALLAS_HandleTypeDef *sensor, uint64_t intROM);
HAL_StatusTypeDef Dallas_SensorInitByUserBytes(OneWire_t *onewire, DALLAS_HandleTypeDef *sensor, uint16_t UserBytes12, uint16_t UserBytes34);
HAL_StatusTypeDef Dallas_SensorInitByInd(OneWire_t *onewire, DALLAS_HandleTypeDef *sensor, uint8_t sens_ind);
HAL_StatusTypeDef Dallas_ReplaceLostedSensor(DALLAS_HandleTypeDef *sensor);
HAL_StatusTypeDef Dallas_AddNewSensors(OneWire_t *onewire, DALLAS_HandleTypeDef *sensor);
HAL_StatusTypeDef Dallas_SensorInitByROM(OneWire_t *onewire, DALLAS_HandleTypeDef *sensor);
HAL_StatusTypeDef Dallas_SensorInitByUserBytes(OneWire_t *onewire, DALLAS_HandleTypeDef *sensor);
HAL_StatusTypeDef Dallas_SensorInitByInd(OneWire_t *onewire, DALLAS_HandleTypeDef *sensor);
HAL_StatusTypeDef Dallas_SensorInit(OneWire_t *onewire, DALLAS_HandleTypeDef *sensor, uint8_t (*ROM)[DALLAS_ROM_SIZE]);
HAL_StatusTypeDef Dallas_SensorDeInit(DALLAS_HandleTypeDef *sensor);
HAL_StatusTypeDef Dallas_StartConvertTAll(OneWire_t *onewire, DALLAS_WaitCondition waitCondition, uint8_t dallas_delay_ms);
HAL_StatusTypeDef Dallas_ConvertT(DALLAS_HandleTypeDef *sensor, DALLAS_WaitCondition waitCondition);
HAL_StatusTypeDef Dallas_ReadTemperature(DALLAS_HandleTypeDef *sensor);

View File

@@ -514,6 +514,7 @@ uint8_t DS18B20_AlarmSearch(DS18B20_Drv_t *DS, OneWire_t* OW)
*/
HAL_StatusTypeDef DS18B20_Search(DS18B20_Drv_t *DS, OneWire_t *OW)
{
OW->RomCnt = 0;
/* Search all OneWire devices ROM */
while(1)
{
@@ -523,14 +524,11 @@ HAL_StatusTypeDef DS18B20_Search(DS18B20_Drv_t *DS, OneWire_t *OW)
/* Get device ROM */
OneWire_GetDevRom(OW, DS->DevAddr[OW->RomCnt]);
/* Set ROM Resolution */
DS18B20_SetResolution(OW, &OW->RomCnt, DS->Resolution);
/* Reset Temperature Alarm */
DS18B20_SetTempAlarm(OW, &OW->RomCnt, 0, 0);
OW->RomCnt++;
}
return (OW->RomCnt != 0) ? 1 : 0;
if(OW->RomCnt > 0)
return HAL_OK;
else
return HAL_BUSY;
}

View File

@@ -103,6 +103,9 @@ HAL_StatusTypeDef DS18B20_WriteUserBytes(OneWire_t* OW, uint8_t *ROM, int16_t Us
int16_t UserBytes34, uint8_t UserBytesMask);
uint8_t DS18B20_AlarmSearch(DS18B20_Drv_t *DS, OneWire_t* OW);
HAL_StatusTypeDef DS18B20_SetResolution(OneWire_t* OW, uint8_t *ROM,
DS18B20_Res_t Resolution);
HAL_StatusTypeDef DS18B20_IsValidAddress(uint8_t *ROM);
#ifdef __cplusplus
}
#endif