|
|
@@ -17,12 +17,14 @@ bool readRegArray(I2CSensor* i2c_sensor, uint8_t startReg, uint8_t len, uint8_t*
|
|
|
furi_hal_i2c_release(i2c_sensor->i2c);
|
|
|
return status;
|
|
|
}
|
|
|
-void writeReg(I2CSensor* i2c_sensor, uint8_t reg, uint8_t value) {
|
|
|
+bool writeReg(I2CSensor* i2c_sensor, uint8_t reg, uint8_t value) {
|
|
|
//Блокировка шины
|
|
|
furi_hal_i2c_acquire(i2c_sensor->i2c);
|
|
|
uint8_t buff[1] = {value};
|
|
|
- furi_hal_i2c_write_mem(i2c_sensor->i2c, i2c_sensor->currentI2CAdr << 1, reg, buff, 1, 0xFF);
|
|
|
+ bool status = furi_hal_i2c_write_mem(
|
|
|
+ i2c_sensor->i2c, i2c_sensor->currentI2CAdr << 1, reg, buff, 1, 0xFF);
|
|
|
furi_hal_i2c_release(i2c_sensor->i2c);
|
|
|
+ return status;
|
|
|
}
|
|
|
|
|
|
bool unitemp_I2C_sensorInit(void* s) {
|
|
|
@@ -53,23 +55,24 @@ UnitempStatus unitemp_I2C_updateData(void* sensor) {
|
|
|
}
|
|
|
|
|
|
bool unitemp_I2C_sensorAlloc(Sensor* sensor, SensorType st, uint16_t* anotherValues) {
|
|
|
+ bool status = false;
|
|
|
I2CSensor* instance = malloc(sizeof(I2CSensor));
|
|
|
instance->interface = I2C;
|
|
|
instance->i2c = &furi_hal_i2c_handle_external;
|
|
|
|
|
|
- instance->lastPollingTime = 0xFFFFFFFF;
|
|
|
-
|
|
|
- sensor->initializer = unitemp_I2C_sensorInit;
|
|
|
- sensor->deinitializer = unitemp_I2C_sensorDeInit;
|
|
|
- sensor->updater = unitemp_I2C_updateData;
|
|
|
+ sensor->lastPollingTime = 0xFFFFFFFF;
|
|
|
|
|
|
sensor->instance = instance;
|
|
|
sensor->type = st;
|
|
|
|
|
|
- //Настройки для BMP280
|
|
|
- if(st == BMP280) {
|
|
|
- instance->minI2CAdr = 0x76;
|
|
|
- instance->maxI2CAdr = 0x77;
|
|
|
+ // //Настройки для BMP280
|
|
|
+ // if(st == BMP280) {
|
|
|
+ // instance->minI2CAdr = 0x76;
|
|
|
+ // instance->maxI2CAdr = 0x77;
|
|
|
+ // }
|
|
|
+ if(st == LM75) {
|
|
|
+ //Указание функций инициализации, деинициализации и обновления данных, а так же адреса на шине I2C
|
|
|
+ status = unitemp_LM75_alloc(sensor);
|
|
|
}
|
|
|
|
|
|
if(anotherValues[0] >= instance->minI2CAdr && anotherValues[0] <= instance->maxI2CAdr) {
|
|
|
@@ -77,5 +80,5 @@ bool unitemp_I2C_sensorAlloc(Sensor* sensor, SensorType st, uint16_t* anotherVal
|
|
|
} else {
|
|
|
instance->currentI2CAdr = instance->minI2CAdr;
|
|
|
}
|
|
|
- return true;
|
|
|
+ return status;
|
|
|
}
|