|
@@ -66,9 +66,14 @@ const Interface ONE_WIRE = {
|
|
|
.allocator = unitemp_onewire_sensor_alloc,
|
|
.allocator = unitemp_onewire_sensor_alloc,
|
|
|
.mem_releaser = unitemp_onewire_sensor_free,
|
|
.mem_releaser = unitemp_onewire_sensor_free,
|
|
|
.updater = unitemp_onewire_sensor_update};
|
|
.updater = unitemp_onewire_sensor_update};
|
|
|
|
|
+const Interface SPI = {
|
|
|
|
|
+ .name = "SPI",
|
|
|
|
|
+ .allocator = unitemp_spi_sensor_alloc,
|
|
|
|
|
+ .mem_releaser = unitemp_spi_sensor_free,
|
|
|
|
|
+ .updater = unitemp_spi_sensor_update};
|
|
|
|
|
|
|
|
//Перечень интерфейсов подключения
|
|
//Перечень интерфейсов подключения
|
|
|
-//static const Interface* interfaces[] = {&SINGLE_WIRE, &I2C, &ONE_WIRE};
|
|
|
|
|
|
|
+//static const Interface* interfaces[] = {&SINGLE_WIRE, &I2C, &ONE_WIRE, &SPI};
|
|
|
//Перечень датчиков
|
|
//Перечень датчиков
|
|
|
static const SensorType* sensorTypes[] = {
|
|
static const SensorType* sensorTypes[] = {
|
|
|
&DHT11,
|
|
&DHT11,
|
|
@@ -87,7 +92,8 @@ static const SensorType* sensorTypes[] = {
|
|
|
&HDC1080,
|
|
&HDC1080,
|
|
|
&BMP180,
|
|
&BMP180,
|
|
|
&BMP280,
|
|
&BMP280,
|
|
|
- &BME280};
|
|
|
|
|
|
|
+ &BME280,
|
|
|
|
|
+ &MAX31855};
|
|
|
|
|
|
|
|
const SensorType* unitemp_sensors_getTypeFromInt(uint8_t index) {
|
|
const SensorType* unitemp_sensors_getTypeFromInt(uint8_t index) {
|
|
|
if(index > SENSOR_TYPES_COUNT) return NULL;
|
|
if(index > SENSOR_TYPES_COUNT) return NULL;
|
|
@@ -166,7 +172,7 @@ uint8_t unitemp_gpio_getAviablePortsCount(const Interface* interface, const GPIO
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//Проверка для single wire
|
|
//Проверка для single wire
|
|
|
- if(interface == &SINGLE_WIRE) {
|
|
|
|
|
|
|
+ if(interface == &SINGLE_WIRE || interface == &SPI) {
|
|
|
if(gpio_interfaces_list[i] == NULL || (unitemp_gpio_getFromIndex(i) == extraport)) {
|
|
if(gpio_interfaces_list[i] == NULL || (unitemp_gpio_getFromIndex(i) == extraport)) {
|
|
|
aviable_ports_count++;
|
|
aviable_ports_count++;
|
|
|
}
|
|
}
|
|
@@ -205,6 +211,13 @@ const GPIO*
|
|
|
return NULL;
|
|
return NULL;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ if(interface == &SPI) {
|
|
|
|
|
+ if(!((gpio_interfaces_list[0] == NULL || gpio_interfaces_list[0] == &SPI) &&
|
|
|
|
|
+ (gpio_interfaces_list[1] == NULL || gpio_interfaces_list[1] == &SPI) &&
|
|
|
|
|
+ (gpio_interfaces_list[3] == NULL || gpio_interfaces_list[3] == &SPI))) {
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
uint8_t aviable_index = 0;
|
|
uint8_t aviable_index = 0;
|
|
|
for(uint8_t i = 0; i < GPIO_ITEMS; i++) {
|
|
for(uint8_t i = 0; i < GPIO_ITEMS; i++) {
|
|
@@ -222,7 +235,7 @@ const GPIO*
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
//Проверка для single wire
|
|
//Проверка для single wire
|
|
|
- if(interface == &SINGLE_WIRE) {
|
|
|
|
|
|
|
+ if(interface == &SINGLE_WIRE || interface == &SPI) {
|
|
|
if(gpio_interfaces_list[i] == NULL || unitemp_gpio_getFromIndex(i) == extraport) {
|
|
if(gpio_interfaces_list[i] == NULL || unitemp_gpio_getFromIndex(i) == extraport) {
|
|
|
if(aviable_index == index) {
|
|
if(aviable_index == index) {
|
|
|
return unitemp_gpio_getFromIndex(i);
|
|
return unitemp_gpio_getFromIndex(i);
|
|
@@ -435,6 +448,11 @@ bool unitemp_sensors_save(void) {
|
|
|
stream_write_format(
|
|
stream_write_format(
|
|
|
app->file_stream, "%d\n", unitemp_singlewire_sensorGetGPIO(sensor)->num);
|
|
app->file_stream, "%d\n", unitemp_singlewire_sensorGetGPIO(sensor)->num);
|
|
|
}
|
|
}
|
|
|
|
|
+ if(sensor->type->interface == &SPI) {
|
|
|
|
|
+ uint8_t gpio_num = ((SPISensor*)sensor->instance)->CS_pin->num;
|
|
|
|
|
+ stream_write_format(app->file_stream, "%d\n", gpio_num);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if(sensor->type->interface == &I2C) {
|
|
if(sensor->type->interface == &I2C) {
|
|
|
stream_write_format(
|
|
stream_write_format(
|
|
|
app->file_stream, "%X\n", ((I2CSensor*)sensor->instance)->currentI2CAdr);
|
|
app->file_stream, "%X\n", ((I2CSensor*)sensor->instance)->currentI2CAdr);
|