Сделана заготовка структуры и функций для измерения датчиков с модуля пч

This commit is contained in:
2025-02-12 14:54:35 +03:00
parent 59606978b2
commit ed1ff35913
7 changed files with 380 additions and 209 deletions

View File

@@ -19,123 +19,7 @@
/* Declarations and definitions --------------------------------------------*/
struct
{
DALLAS_HandleTypeDef outdoor;
DALLAS_HandleTypeDef indoor;
DALLAS_HandleTypeDef bathroom;
DALLAS_HandleTypeDef kitchen;
DALLAS_HandleTypeDef big_room;
DALLAS_HandleTypeDef small_room;
DALLAS_HandleTypeDef living_room;
DALLAS_HandleTypeDef basement;
}AllSens;
/* Functions ---------------------------------------------------------------*/
void Dallas_ReadAll(void)
{
HAL_StatusTypeDef result;
result = Dallas_StartConvertTAll(&OW, DALLAS_WAIT_BUS, 0);
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)
{
OW.DataPin = DS_Pin;
OW.DataPort = DS_GPIO_Port;
DS.Resolution = DS18B20_RESOLUTION_9BITS;
OneWire_Init(&OW);
DS18B20_Search(&DS, &OW);
AllSens.outdoor.Init.ROM = 0x28C60C61060000DC;
AllSens.indoor.Init.ROM = 0x283E4861060000F9;
AllSens.bathroom.Init.ROM = 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;
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, 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);
// Dallas_WriteUserBytes(&AllSens.kitchen, 4, NULL, mask);
// Dallas_WriteUserBytes(&AllSens.big_room, 5, NULL, mask);
// Dallas_WriteUserBytes(&AllSens.small_room, 6, NULL, mask);
// Dallas_WriteUserBytes(&AllSens.living_room, 7, NULL, mask);
// Dallas_WriteUserBytes(&AllSens.basement, 8, NULL, mask);
}
/**
* @brief Ôóíêöèÿ äëÿ íàõîæäåíèÿ íîâîãî äàò÷èêà íà ìåñòî ïîòåðÿííîãî
* @param sensor Óêàçàòåëü íà ñòðóêòóðó äàò÷èêà
@@ -276,52 +160,47 @@ HAL_StatusTypeDef Dallas_SensorInitByUserBytes(OneWire_t *onewire, DALLAS_Handle
DALLAS_ScratchpadTypeDef scratchpad;
for(int i = 0; i < onewire->RomCnt; i++)
{
{
/* Проверка присутствует ли выбранный датчик на линии */
result = DS18B20_ReadScratchpad(onewire, (uint8_t *)&DS.DevAddr[i], (uint8_t *)&scratchpad);
if (result != HAL_OK)
return result;
for(int rom_ind = 0; rom_ind < DALLAS_ROM_SIZE; rom_ind++)
/* Сравнение UserByte1 и UserByte2, если они не равны нулю */
if(sensor->Init.UserBytes12 != NULL)
{
/* Ïðîâåðêà ïðèñóòñòâóåò ëè âûáðàííûé äàò÷èê íà ëèíèè */
result = DS18B20_ReadScratchpad(onewire, (uint8_t *)&DS.DevAddr[i], (uint8_t *)&scratchpad);
if (result != HAL_OK)
return result;
/* Ñðàâíåíèå UserByte1 è UserByte2, åñëè îíè íå ðàâíû íóëþ */
if(sensor->Init.UserBytes12 != NULL)
{
if( (scratchpad.tHighRegister == UserByte1) &&
(scratchpad.tLowRegister == UserByte2))
{
UserByte12Cmp = 1;
}
}/* Åñëè ñðàâíåíèå UserByte1 è UserByte2 íå âûáðàíî, òî ñ÷èòàåì ÷òî îíè ñîâïàäàþò */
else
if( (scratchpad.tHighRegister == UserByte1) &&
(scratchpad.tLowRegister == UserByte2))
{
UserByte12Cmp = 1;
}
/* Ñðàâíåíèå UserByte3 è UserByte4, åñëè îíè íå ðàâíû íóëþ */
if(sensor->Init.UserBytes34 != NULL)
{
if( (scratchpad.UserByte3 == UserByte3) &&
(scratchpad.UserByte4 == UserByte4))
{
UserByte34Cmp = 1;
}
}/* Åñëè ñðàâíåíèå UserByte3 è UserByte4 íå âûáðàíî, òî ñ÷èòàåì ÷òî îíè îäèíàêîâûå */
else
}/* Если сравнение UserByte1 и UserByte2 не выбрано, то считаем что они совпадают */
else
{
UserByte12Cmp = 1;
}
/* Сравнение UserByte3 и UserByte4, если они не равны нулю */
if(sensor->Init.UserBytes34 != NULL)
{
if( (scratchpad.UserByte3 == UserByte3) &&
(scratchpad.UserByte4 == UserByte4))
{
UserByte34Cmp = 1;
}
/* Åñëè íàøëè íóæíûé äàò÷èê - çàâåðøàåì ïîèñê */
if(UserByte12Cmp && UserByte34Cmp)
{
// sensor->isInitialized = 1;
// sensor->Init.init_func = (HAL_StatusTypeDef (*)())Dallas_SensorInitByUserBytes;
result = Dallas_SensorInit(onewire, sensor, &DS.DevAddr[i]);
return result;
}
}/* Если сравнение UserByte3 и UserByte4 не выбрано, то считаем что они одинаковые */
else
{
UserByte34Cmp = 1;
}
/* Если нашли нужный датчик - завершаем поиск */
if(UserByte12Cmp && UserByte34Cmp)
{
// 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;
}
@@ -368,8 +247,6 @@ HAL_StatusTypeDef Dallas_SensorInit(OneWire_t *onewire, DALLAS_HandleTypeDef *se
if(onewire == 0)
return HAL_ERROR;
sensor->onewire = onewire;
for(int i = 0; i < DALLAS_ROM_SIZE; i++)
@@ -389,14 +266,12 @@ HAL_StatusTypeDef Dallas_SensorInit(OneWire_t *onewire, DALLAS_HandleTypeDef *se
else
{
sensor->isInitialized = 0;
Dallas_SensorDeInit(sensor);
return result;
}
}
else
{
sensor->isInitialized = 0;
Dallas_SensorDeInit(sensor);
return result;
}
}
@@ -414,12 +289,10 @@ HAL_StatusTypeDef Dallas_SensorDeInit(DALLAS_HandleTypeDef *sensor)
return HAL_ERROR;
DALLAS_InitStructTypeDef initbuff = sensor->Init;
DALLAS_ControlTypeDef ctrlbuff = sensor->Control;
memset(sensor, 0, sizeof(DALLAS_HandleTypeDef));
sensor->Init = initbuff;
sensor->Control = ctrlbuff;
return HAL_OK;
}