Просмотр исходного кода

Added the ability to edit the I2C address in the sensor editing menu

Victor 3 лет назад
Родитель
Сommit
336ebb4548
2 измененных файлов с 28 добавлено и 2 удалено
  1. 27 1
      views/SensorEdit_view.c
  2. 1 1
      views/SensorsList_view.c

+ 27 - 1
views/SensorEdit_view.c

@@ -3,6 +3,7 @@
 
 #include "../interfaces/SingleWireSensor.h"
 #include "../interfaces/OneWireSensor.h"
+#include "../interfaces/I2CSensor.h"
 
 //Текущий вид
 static View* view;
@@ -56,6 +57,19 @@ static void _gpio_change_callback(VariableItem* item) {
         variable_item_set_current_value_text(item, instance->bus->gpio->name);
     }
 }
+/**
+ * @brief Функция обработки изменения значения GPIO
+ * 
+ * @param item Указатель на элемент списка
+ */
+static void _i2caddr_change_callback(VariableItem* item) {
+    uint8_t index = variable_item_get_current_value_index(item);
+    ((I2CSensor*)editable_sensor->instance)->currentI2CAdr =
+        ((I2CSensor*)editable_sensor->instance)->minI2CAdr + index;
+    char buff[5];
+    snprintf(buff, 5, "0x%2X", ((I2CSensor*)editable_sensor->instance)->currentI2CAdr);
+    variable_item_set_current_value_text(item, buff);
+}
 
 /**
  * @brief Создание меню редактирования датчка
@@ -101,7 +115,19 @@ void unitemp_SensorEdit_switch(Sensor* sensor) {
         variable_item_set_current_value_text(
             item, unitemp_gpio_getAviablePort(sensor->type->interface, 0)->name);
     }
-
+    //Адрес устройства на шине I2C (для I2C)
+    if(sensor->type->interface == &I2C) {
+        item = variable_item_list_add(
+            variable_item_list,
+            "I2C address",
+            ((I2CSensor*)sensor->instance)->maxI2CAdr - ((I2CSensor*)sensor->instance)->minI2CAdr +
+                1,
+            _i2caddr_change_callback,
+            app);
+        char buff[5];
+        snprintf(buff, 5, "0x%2X", ((I2CSensor*)sensor->instance)->currentI2CAdr);
+        variable_item_set_current_value_text(item, buff);
+    }
     //Сохранение
     variable_item_list_add(variable_item_list, "Save", 1, NULL, NULL);
 

+ 1 - 1
views/SensorsList_view.c

@@ -37,7 +37,7 @@ static void _enter_callback(void* context, uint32_t index) {
     //Выбор первого доступного порта для датчиков single wire и one wire
     if(st->interface == &SINGLE_WIRE || st->interface == &ONE_WIRE) {
         anotherValues[0] = unitemp_GPIO_toInt(unitemp_gpio_getAviablePort(st->interface, 0)->pin);
-    };
+    }
     //Для I2C адрес выберится автоматически
 
     unitemp_SensorEdit_switch(unitemp_sensor_alloc(sensor_name, st, anotherValues));