174 lines
5.2 KiB
C
174 lines
5.2 KiB
C
/**
|
|
******************************************************************************
|
|
* @file pch_sensors.c
|
|
* @brief Ðàáîòà ñ äàò÷èêàìè òåìïåðàòóðû DS18B20 â Ï×
|
|
*****************************************************************************/
|
|
|
|
|
|
/* Includes ----------------------------------------------------------------*/
|
|
|
|
#include "pch_sensors.h"
|
|
|
|
|
|
/* Declarations and definitions --------------------------------------------*/
|
|
|
|
PCHSens_ModuleTypeDef module1;
|
|
/* Functions ---------------------------------------------------------------*/
|
|
|
|
HAL_StatusTypeDef PCHSens_InitNewSensor(OneWire_t *onewire, PCH_SensorTypeDef* sensor, uint64_t ROM, PCHSens_LocationTypeDef *location)
|
|
{
|
|
DALLAS_HandleTypeDef tempsens;
|
|
HAL_StatusTypeDef result;
|
|
if(onewire == NULL)
|
|
return HAL_ERROR;
|
|
if(sensor == NULL)
|
|
return HAL_ERROR;
|
|
if(location == NULL)
|
|
return HAL_ERROR;
|
|
|
|
PCHSens_LocationTypeDef initlocation = *location;
|
|
|
|
sensor->Location = (PCHSens_LocationTypeDef *)&sensor->sens.scratchpad.tHighRegister;
|
|
|
|
sensor->sens.Init.ROM = ROM;
|
|
|
|
sensor->sens.Init.UserBytes12 = initlocation.all;
|
|
|
|
sensor->sens.Init.init_func = &Dallas_SensorInitByROM;
|
|
|
|
result = Dallas_AddNewSensors(onewire, &sensor->sens);
|
|
if(result != HAL_OK)
|
|
return result;
|
|
|
|
result = Dallas_WriteUserBytes(&sensor->sens, initlocation.all, 0, DALLAS_USER_BYTE_12);
|
|
if(result != HAL_OK)
|
|
return result;
|
|
|
|
sensor->sens.Init.init_func = &Dallas_SensorInitByUserBytes;
|
|
|
|
return Dallas_AddNewSensors(onewire, &sensor->sens);
|
|
}
|
|
|
|
|
|
HAL_StatusTypeDef PCHSens_FindSensor(OneWire_t *onewire, PCH_SensorTypeDef* sensor, PCHSens_LocationTypeDef *location)
|
|
{
|
|
if(onewire == NULL)
|
|
return HAL_ERROR;
|
|
if(sensor == NULL)
|
|
return HAL_ERROR;
|
|
if(location == NULL)
|
|
return HAL_ERROR;
|
|
|
|
PCHSens_LocationTypeDef initlocation = *location;
|
|
|
|
sensor->Location = (PCHSens_LocationTypeDef *)&sensor->sens.scratchpad.tHighRegister;
|
|
|
|
sensor->sens.Init.UserBytes12 = initlocation.all;
|
|
|
|
sensor->sens.Init.init_func = &Dallas_SensorInitByUserBytes;
|
|
|
|
return Dallas_AddNewSensors(onewire, &sensor->sens);
|
|
}
|
|
|
|
HAL_StatusTypeDef PCHSens_FindModule(OneWire_t *onewire, PCHSens_ModuleTypeDef* module, PCHSens_LocationTypeDef *location, uint8_t init)
|
|
{
|
|
if(onewire == NULL)
|
|
return HAL_ERROR;
|
|
if(module == NULL)
|
|
return HAL_ERROR;
|
|
|
|
PCHSens_LocationTypeDef initlocation = *location;
|
|
|
|
module->onewire = onewire;
|
|
module->refLocation = initlocation;
|
|
|
|
if(init == 0)
|
|
{
|
|
initlocation.location.Location = 0;
|
|
PCHSens_FindSensor(onewire, &module->sens1, &initlocation);
|
|
|
|
initlocation.location.Location = 1;
|
|
PCHSens_FindSensor(onewire, &module->sens2, &initlocation);
|
|
|
|
initlocation.location.Location = 2;
|
|
PCHSens_FindSensor(onewire, &module->sens3, &initlocation);
|
|
|
|
initlocation.location.Location = 3;
|
|
PCHSens_FindSensor(onewire, &module->sens4, &initlocation);
|
|
}
|
|
else
|
|
{
|
|
uint64_t ROM = 0x28366a48f6563c8d;
|
|
initlocation.location.Location = 0;
|
|
PCHSens_InitNewSensor(onewire, &module->sens1, ROM, &initlocation);
|
|
|
|
ROM = 0x28CF5248F6BB3C2F;
|
|
initlocation.location.Location = 1;
|
|
PCHSens_InitNewSensor(onewire, &module->sens2, ROM, &initlocation);
|
|
|
|
ROM = 0x28876D60060000CD;
|
|
initlocation.location.Location = 2;
|
|
PCHSens_InitNewSensor(onewire, &module->sens3, ROM, &initlocation);
|
|
|
|
ROM = 0;
|
|
initlocation.location.Location = 3;
|
|
PCHSens_InitNewSensor(onewire, &module->sens4, ROM, &initlocation);
|
|
}
|
|
return HAL_OK;
|
|
}
|
|
|
|
|
|
HAL_StatusTypeDef PCHSens_ReadModuleTemperature(PCHSens_ModuleTypeDef *module)
|
|
{
|
|
HAL_StatusTypeDef result;
|
|
|
|
result = Dallas_StartConvertTAll(module->onewire, DALLAS_WAIT_BUS, 0);
|
|
|
|
result = Dallas_ReadTemperature(&module->sens1.sens);
|
|
result = Dallas_ReadTemperature(&module->sens2.sens);
|
|
result = Dallas_ReadTemperature(&module->sens3.sens);
|
|
result = Dallas_ReadTemperature(&module->sens4.sens);
|
|
|
|
return result;
|
|
}
|
|
|
|
void Dallas_FirstInit(void)
|
|
{
|
|
int init_find = 0;
|
|
OW.DataPin = DS_Pin;
|
|
OW.DataPort = DS_GPIO_Port;
|
|
DS.Resolution = DS18B20_RESOLUTION_9BITS;
|
|
|
|
OneWire_Init(&OW);
|
|
DS18B20_Search(&DS, &OW);
|
|
|
|
|
|
PCHSens_LocationTypeDef location;
|
|
location.all = REG_PCH_NUMB_11|REG_PCH_DIODE_NUMB_1;
|
|
PCHSens_FindModule(&OW, &module1, &location, init_find);
|
|
|
|
|
|
// 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);
|
|
}
|
|
|
|
|
|
|
|
|