Add Clang-Format file and apply it
The format tries to maintain the previously used Libre Solar firmware coding style as much as possible. Applying the format fixed some issues and re-ordered some parts of the code.
This commit is contained in:
committed by
Martin Jäger
parent
2359a96bbe
commit
5bdbecf19d
+31
-32
@@ -9,36 +9,34 @@
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <device.h>
|
||||
#include <drivers/gpio.h>
|
||||
#include <zephyr.h>
|
||||
|
||||
#include "oled_ssd1306.h"
|
||||
|
||||
#include "setup.h"
|
||||
#include "half_bridge.h"
|
||||
#include "setup.h"
|
||||
|
||||
#if DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), uext_en))
|
||||
#define UEXT_EN_GPIO DT_CHILD(DT_PATH(outputs), uext_en)
|
||||
#endif
|
||||
|
||||
const unsigned char bmp_load [] = {
|
||||
const unsigned char bmp_load[] = {
|
||||
0x20, 0x22, 0x04, 0x70, 0x88, 0x8B, 0x88, 0x70, 0x04, 0x22, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x01, 0x00, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
0x00, 0x01, 0x00, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
const unsigned char bmp_arrow_right [] = {
|
||||
0x41, 0x63, 0x36, 0x1C
|
||||
};
|
||||
const unsigned char bmp_arrow_right[] = { 0x41, 0x63, 0x36, 0x1C };
|
||||
|
||||
const unsigned char bmp_pv_panel [] = {
|
||||
const unsigned char bmp_pv_panel[] = {
|
||||
0x60, 0x98, 0x86, 0xC9, 0x31, 0x19, 0x96, 0x62, 0x32, 0x2C, 0xC4, 0x64, 0x98, 0x08, 0xC8, 0x30,
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x02, 0x02, 0x03, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x02, 0x02, 0x03, 0x04, 0x04, 0x04, 0x03, 0x00, 0x00,
|
||||
};
|
||||
|
||||
const unsigned char bmp_disconnected [] = {
|
||||
const unsigned char bmp_disconnected[] = {
|
||||
0x08, 0x08, 0x08, 0x08, 0x00, 0x41, 0x63, 0x36, 0x1C, 0x1C, 0x36, 0x63, 0x41, 0x00, 0x08, 0x08,
|
||||
0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
OledSSD1306 oled(DT_LABEL(DT_ALIAS(i2c_uext)));
|
||||
@@ -73,23 +71,23 @@ void oled_update()
|
||||
oled.drawBitmap(81, 3, bmp_disconnected, 17, 7, 1);
|
||||
}
|
||||
|
||||
oled.drawRect(52, 2, 18, 9, 1); // battery shape
|
||||
oled.drawRect(69, 3, 3, 7, 1); // battery terminal
|
||||
oled.drawRect(52, 2, 18, 9, 1); // battery shape
|
||||
oled.drawRect(69, 3, 3, 7, 1); // battery terminal
|
||||
|
||||
if (charger.soc >= 20) {
|
||||
oled.drawRect(54, 4, 2, 5, 1); // bar 1
|
||||
oled.drawRect(54, 4, 2, 5, 1); // bar 1
|
||||
}
|
||||
if (charger.soc >= 40) {
|
||||
oled.drawRect(57, 4, 2, 5, 1); // bar 2
|
||||
oled.drawRect(57, 4, 2, 5, 1); // bar 2
|
||||
}
|
||||
if (charger.soc >= 60) {
|
||||
oled.drawRect(60, 4, 2, 5, 1); // bar 3
|
||||
oled.drawRect(60, 4, 2, 5, 1); // bar 3
|
||||
}
|
||||
if (charger.soc >= 80) {
|
||||
oled.drawRect(63, 4, 2, 5, 1); // bar 4
|
||||
oled.drawRect(63, 4, 2, 5, 1); // bar 4
|
||||
}
|
||||
if (charger.soc >= 95) {
|
||||
oled.drawRect(66, 4, 2, 5, 1); // bar 5
|
||||
oled.drawRect(66, 4, 2, 5, 1); // bar 5
|
||||
}
|
||||
|
||||
// solar panel data
|
||||
@@ -100,7 +98,8 @@ void oled_update()
|
||||
#endif
|
||||
oled.setTextCursor(0, 18);
|
||||
len = snprintf(buf, sizeof(buf), "%4.0fW",
|
||||
(abs(in_terminal.power) < 1) ? 0 : -in_terminal.power); // remove negative zeros
|
||||
(abs(in_terminal.power) < 1) ? 0
|
||||
: -in_terminal.power); // remove negative zeros
|
||||
oled.writeString(buf, len);
|
||||
}
|
||||
else {
|
||||
@@ -119,8 +118,9 @@ void oled_update()
|
||||
|
||||
// battery data
|
||||
oled.setTextCursor(42, 18);
|
||||
len = snprintf(buf, sizeof(buf), "%5.1fW",
|
||||
(abs(bat_terminal.power) < 0.1) ? 0 : bat_terminal.power); // remove negative zeros
|
||||
len =
|
||||
snprintf(buf, sizeof(buf), "%5.1fW",
|
||||
(abs(bat_terminal.power) < 0.1) ? 0 : bat_terminal.power); // remove negative zeros
|
||||
oled.writeString(buf, len);
|
||||
oled.setTextCursor(42, 26);
|
||||
len = snprintf(buf, sizeof(buf), "%5.1fV", bat_terminal.bus->voltage);
|
||||
@@ -129,19 +129,18 @@ void oled_update()
|
||||
// load data
|
||||
oled.setTextCursor(90, 18);
|
||||
len = snprintf(buf, sizeof(buf), "%5.1fW",
|
||||
(abs(load.power) < 0.1) ? 0 : load.power); // remove negative zeros
|
||||
(abs(load.power) < 0.1) ? 0 : load.power); // remove negative zeros
|
||||
oled.writeString(buf, len);
|
||||
oled.setTextCursor(90, 26);
|
||||
len = snprintf(buf, sizeof(buf), "%5.1fA\n",
|
||||
(abs(load.current) < 0.1) ? 0 : load.current);
|
||||
len = snprintf(buf, sizeof(buf), "%5.1fA\n", (abs(load.current) < 0.1) ? 0 : load.current);
|
||||
oled.writeString(buf, len);
|
||||
|
||||
oled.setTextCursor(0, 36);
|
||||
len = snprintf(buf, sizeof(buf), "Day +%5.0fWh -%5.0fWh",
|
||||
in_terminal.neg_energy_Wh, fabs(load.pos_energy_Wh));
|
||||
len = snprintf(buf, sizeof(buf), "Day +%5.0fWh -%5.0fWh", in_terminal.neg_energy_Wh,
|
||||
fabs(load.pos_energy_Wh));
|
||||
oled.writeString(buf, len);
|
||||
len = snprintf(buf, sizeof(buf), "Tot +%4.1fkWh -%4.1fkWh",
|
||||
dev_stat.solar_in_total_Wh / 1000.0, fabs(dev_stat.load_out_total_Wh) / 1000.0);
|
||||
len = snprintf(buf, sizeof(buf), "Tot +%4.1fkWh -%4.1fkWh", dev_stat.solar_in_total_Wh / 1000.0,
|
||||
fabs(dev_stat.load_out_total_Wh) / 1000.0);
|
||||
oled.writeString(buf, len);
|
||||
|
||||
oled.setTextCursor(0, 56);
|
||||
@@ -154,12 +153,12 @@ void oled_update()
|
||||
float duty_cycle = half_bridge_get_duty_cycle();
|
||||
#endif
|
||||
|
||||
float temp = charger.ext_temp_sensor ? charger.bat_temperature:dev_stat.internal_temp;
|
||||
float temp = charger.ext_temp_sensor ? charger.bat_temperature : dev_stat.internal_temp;
|
||||
char tC = charger.ext_temp_sensor ? 'T' : 't';
|
||||
|
||||
if (pwm_enabled == true) {
|
||||
len = snprintf(buf, sizeof(buf), "%c %.0fC PWM %.0f%% SOC %d%%",
|
||||
tC, temp, duty_cycle * 100.0, charger.soc);
|
||||
len = snprintf(buf, sizeof(buf), "%c %.0fC PWM %.0f%% SOC %d%%", tC, temp,
|
||||
duty_cycle * 100.0, charger.soc);
|
||||
oled.writeString(buf, len);
|
||||
}
|
||||
else {
|
||||
@@ -175,7 +174,7 @@ void oled_thread()
|
||||
#if DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), uext_en))
|
||||
const struct device *dev_uext_en = device_get_binding(DT_GPIO_LABEL(UEXT_EN_GPIO, gpios));
|
||||
gpio_pin_configure(dev_uext_en, DT_GPIO_PIN(UEXT_EN_GPIO, gpios),
|
||||
DT_GPIO_FLAGS(UEXT_EN_GPIO, gpios) | GPIO_OUTPUT_ACTIVE);
|
||||
DT_GPIO_FLAGS(UEXT_EN_GPIO, gpios) | GPIO_OUTPUT_ACTIVE);
|
||||
#endif
|
||||
|
||||
oled.init(CONFIG_UEXT_OLED_BRIGHTNESS);
|
||||
|
||||
Reference in New Issue
Block a user