102 ESP_ERROR_CHECK(ina219_get_current(&ina219_b_dev, ¤t)); |
106 ESP_ERROR_CHECK(ina219_get_current(&ina219_b_dev, ¤t)); |
103 ESP_ERROR_CHECK(ina219_get_power(&ina219_b_dev, &power)); |
107 ESP_ERROR_CHECK(ina219_get_power(&ina219_b_dev, &power)); |
104 ESP_LOGI(TAG, "Battery VBUS: %.04f V, VSHUNT: %.04f mV, IBUS: %.04f mA, PBUS: %.04f mW", |
108 ESP_LOGI(TAG, "Battery VBUS: %.04f V, VSHUNT: %.04f mV, IBUS: %.04f mA, PBUS: %.04f mW", |
105 bus_voltage, shunt_voltage * 1000, current * 1000, power * 1000); |
109 bus_voltage, shunt_voltage * 1000, current * 1000, power * 1000); |
106 } |
110 } |
|
111 if (xSemaphoreTake(xSemaphoreINA219, 25) == pdTRUE) { |
|
112 if (ina219_state->Battery.fake) { |
|
113 ina219_state->Battery.volts = 13.21; |
|
114 if (ready_WiFi()) { |
|
115 ina219_state->Battery.shunt = 0.00785; |
|
116 ina219_state->Battery.current = 78.5; |
|
117 } else { |
|
118 ina219_state->Battery.shunt = 0.00182; |
|
119 ina219_state->Battery.current = 18.2; |
|
120 } |
|
121 } else { |
|
122 ina219_state->Battery.volts = bus_voltage; |
|
123 ina219_state->Battery.shunt = shunt_voltage; |
|
124 ina219_state->Battery.current = current; |
|
125 } |
|
126 ina219_state->Battery.valid = true; |
|
127 xSemaphoreGive(xSemaphoreINA219); |
|
128 } |
|
129 |
107 if (! ina219_state->Solar.fake) { |
130 if (! ina219_state->Solar.fake) { |
108 ESP_ERROR_CHECK(ina219_get_bus_voltage(&ina219_s_dev, &bus_voltage)); |
131 ESP_ERROR_CHECK(ina219_get_bus_voltage(&ina219_s_dev, &bus_voltage)); |
109 ESP_ERROR_CHECK(ina219_get_shunt_voltage(&ina219_s_dev, &shunt_voltage)); |
132 ESP_ERROR_CHECK(ina219_get_shunt_voltage(&ina219_s_dev, &shunt_voltage)); |
110 ESP_ERROR_CHECK(ina219_get_current(&ina219_s_dev, ¤t)); |
133 ESP_ERROR_CHECK(ina219_get_current(&ina219_s_dev, ¤t)); |
111 ESP_ERROR_CHECK(ina219_get_power(&ina219_s_dev, &power)); |
134 ESP_ERROR_CHECK(ina219_get_power(&ina219_s_dev, &power)); |
112 ESP_LOGI(TAG, " Solar VBUS: %.04f V, VSHUNT: %.04f mV, IBUS: %.04f mA, PBUS: %.04f mW", |
135 ESP_LOGI(TAG, " Solar VBUS: %.04f V, VSHUNT: %.04f mV, IBUS: %.04f mA, PBUS: %.04f mW", |
113 bus_voltage, shunt_voltage * 1000, current * 1000, power * 1000); |
136 bus_voltage, shunt_voltage * 1000, current * 1000, power * 1000); |
114 } |
137 } |
115 |
138 if (xSemaphoreTake(xSemaphoreINA219, 25) == pdTRUE) { |
116 /* |
139 if (! ina219_state->Solar.fake && ! ina219_state->Battery.fake) { |
117 error = ina219_read_float(&ina219_dev, &temperature, &pressure, &humidity); |
140 ina219_state->Solar.volts = bus_voltage; |
118 if (xSemaphoreTake(xSemaphoreINA219, 25) == pdTRUE) { |
141 ina219_state->Solar.shunt = shunt_voltage; |
119 if (error == ESP_OK) { |
142 ina219_state->Solar.current = current; |
120 ina219_state->error = INA219_ERR_NONE; |
143 } else if (ina219_state->Solar.fake && ! ina219_state->Battery.fake) { |
121 ina219_state->valid = true; |
144 ina219_state->Solar.volts = ina219_state->Battery.volts + 0.78; |
122 ina219_state->temperature = temperature; |
145 ina219_state->Solar.shunt = 0.02341; |
123 ina219_state->pressure = pressure; |
146 ina219_state->Solar.current = 234.1; |
124 ina219_state->humidity = humidity; |
147 } else { |
125 } else { |
148 ina219_state->Solar.volts = 13.98; |
126 ina219_state->error = INA219_ERR_READ; |
149 ina219_state->Solar.shunt = 0.02341; |
127 ina219_state->valid = false; |
150 ina219_state->Solar.current = 234.1; |
128 ina219_state->temperature = 0; |
|
129 ina219_state->pressure = 0; |
|
130 ina219_state->humidity = 0; |
|
131 } |
|
132 xSemaphoreGive(xSemaphoreINA219); |
|
133 } |
151 } |
134 } else { |
152 ina219_state->Solar.valid = true; |
135 if (xSemaphoreTake(xSemaphoreINA219, 25) == pdTRUE) { |
153 xSemaphoreGive(xSemaphoreINA219); |
136 ina219_state->error = INA219_ERR_NONE; |
|
137 ina219_state->valid = true; |
|
138 ina219_state->temperature = 21.23; |
|
139 ina219_state->pressure = 101360; |
|
140 ina219_state->humidity = 0; |
|
141 xSemaphoreGive(xSemaphoreINA219); |
|
142 } |
|
143 } |
154 } |
144 |
155 |
145 */ |
|
146 xEventGroupClearBits(xEventGroupINA219, TASK_INA219_REQUEST_POWER); |
156 xEventGroupClearBits(xEventGroupINA219, TASK_INA219_REQUEST_POWER); |
147 xEventGroupSetBits(xEventGroupINA219, TASK_INA219_REQUEST_DONE); |
157 xEventGroupSetBits(xEventGroupINA219, TASK_INA219_REQUEST_DONE); |
148 #if 0 |
|
149 ESP_LOGI(TAG, " TB: %.3f C, %.1f hPa, error: %d", ina219_state->temperature, ina219_state->pressure / 100, ina219_state->error); |
|
150 #endif |
|
151 } |
158 } |
152 } |
159 } |
153 } |
160 } |