From 151f6332476deda5a0a57475f181edeb9849a7fa Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Thu, 26 Dec 2024 13:28:25 +0100 Subject: [PATCH] Marstek B2500: also display current battery change level in Wh, not only percentage --- CHANGELOG.md | 1 + .../marstek/SolarEquipmentStatusActivity.java | 4 +++- .../marstek/MarstekB2500DeviceSupport.java | 17 +++++++++-------- .../layout/dashboard_widget_generic_gauge.xml | 1 + 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b80d0bb9..c2daf5ca8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ #### Next * Marstek B2500: Fix wrong gauge display for panel 2 and output 2 +* Marstek B2500: also display current battery change level in Wh, not only percentage #### 0.83.0 * Add first start onboarding screen diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/marstek/SolarEquipmentStatusActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/marstek/SolarEquipmentStatusActivity.java index f7d00a32b..da859b3e3 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/marstek/SolarEquipmentStatusActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/marstek/SolarEquipmentStatusActivity.java @@ -48,6 +48,7 @@ import nodomain.freeyourgadget.gadgetbridge.util.GB; public class SolarEquipmentStatusActivity extends AbstractGBActivity { public static String ACTION_SEND_SOLAR_EQUIPMENT_STATUS = "send_solar_equipment_status"; public static String EXTRA_BATTERY_PCT = "battery_pct"; + public static String EXTRA_BATTERY_WH = "battery_wh"; public static String EXTRA_PANEL1_WATT = "panel1_watt"; public static String EXTRA_PANEL2_WATT = "panel2_watt"; public static String EXTRA_OUTPUT1_WATT = "output1_watt"; @@ -64,11 +65,12 @@ public class SolarEquipmentStatusActivity extends AbstractGBActivity { Bundle extras = intent.getExtras(); if (extras != null) { int battery_pct = extras.getInt(EXTRA_BATTERY_PCT); + int battery_wh = extras.getInt(EXTRA_BATTERY_WH); int panel1_watt = extras.getInt(EXTRA_PANEL1_WATT); int panel2_watt = extras.getInt(EXTRA_PANEL2_WATT); int output1_watt = extras.getInt(EXTRA_OUTPUT1_WATT); int output2_watt = extras.getInt(EXTRA_OUTPUT2_WATT); - updateWidget("battery", battery_pct + "%", (float) (battery_pct / 100.0)); + updateWidget("battery", battery_pct + "%\n" + battery_wh + "Wh", (float) (battery_pct / 100.0)); updateWidget("panel1", panel1_watt + "W", (float) (panel1_watt / 380.0)); updateWidget("panel2", panel2_watt + "W", (float) (panel2_watt / 380.0)); updateWidget("output1", output1_watt + "W", (float) (output1_watt / 400.0)); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/marstek/MarstekB2500DeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/marstek/MarstekB2500DeviceSupport.java index 8dac2d8a9..244f27188 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/marstek/MarstekB2500DeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/marstek/MarstekB2500DeviceSupport.java @@ -192,37 +192,38 @@ public class MarstekB2500DeviceSupport extends AbstractBTLEDeviceSupport { buf.position(buf.position() + 2); // unknown; firmwareVersion = buf.get() & 0xff; - boolean battery_allow_passthough = buf.get() != 0x01; + boolean battery_allow_passthrough = buf.get() != 0x01; boolean battery_manual_discharge_intervals = buf.get() != 0x01; buf.position(buf.position() + 3); // skip unknown byte battery_max_use_pct = buf.get(); int output_to_inverter_target = buf.getShort(); buf.position(buf.position() + 1); // skip unknown - int battery_charge_kwh = buf.getShort(); + int battery_wh = buf.getShort(); int output_to_inverter_1_watt = buf.getShort(); int output_to_inverter_2_watt = buf.getShort(); int battery_minimum_charge_pct = 100 - battery_max_use_pct; int output_to_inverter_sum_watt = output_to_inverter_1_watt + output_to_inverter_2_watt; - LOG.info("p1_active: {}, p2_active: {}, p1_watt: {}W, p2_watt: {}W, battery_charge_kwh: {}kWh, battery_minimum_charge_pct: {}%, battery_allow_passthrough: {}, battery_manual_discharge_intervals: {}, output_to_inverter_target: {}W, output_to_inverter: {}W+{}W={}W, firmwareVersion: V{}, ", - p1_active, p2_active, p1_watt, p2_watt, battery_charge_kwh, battery_minimum_charge_pct, battery_allow_passthough, battery_manual_discharge_intervals, output_to_inverter_target, output_to_inverter_1_watt, output_to_inverter_2_watt, output_to_inverter_sum_watt, firmwareVersion); + LOG.info("p1_active: {}, p2_active: {}, p1_watt: {}W, p2_watt: {}W, battery_wh: {}Wh, battery_minimum_charge_pct: {}%, battery_allow_passthrough: {}, battery_manual_discharge_intervals: {}, output_to_inverter_target: {}W, output_to_inverter: {}W+{}W={}W, firmwareVersion: V{}, ", + p1_active, p2_active, p1_watt, p2_watt, battery_wh, battery_minimum_charge_pct, battery_allow_passthrough, battery_manual_discharge_intervals, output_to_inverter_target, output_to_inverter_1_watt, output_to_inverter_2_watt, output_to_inverter_sum_watt, firmwareVersion); getDevice().setFirmwareVersion("V" + firmwareVersion); getDevice().sendDeviceUpdateIntent(getContext()); devicePrefsEdit.putString(PREF_BATTERY_MINIMUM_CHARGE, String.valueOf(battery_minimum_charge_pct)); devicePrefsEdit.putBoolean(PREF_BATTERY_DISCHARGE_MANAUAL, battery_manual_discharge_intervals); - devicePrefsEdit.putBoolean(PREF_BATTERY_ALLOW_PASS_THOUGH, battery_allow_passthough); + devicePrefsEdit.putBoolean(PREF_BATTERY_ALLOW_PASS_THOUGH, battery_allow_passthrough); devicePrefsEdit.apply(); devicePrefsEdit.commit(); - int battery_percentage = (int) Math.ceil((battery_charge_kwh / 2240.0f) * 100); - getDevice().setBatteryLevel(battery_percentage); + int battery_pct = (int) Math.ceil((battery_wh / 2240.0f) * 100); + getDevice().setBatteryLevel(battery_pct); getDevice().sendDeviceUpdateIntent(getContext()); Intent intent = new Intent(SolarEquipmentStatusActivity.ACTION_SEND_SOLAR_EQUIPMENT_STATUS); - intent.putExtra(SolarEquipmentStatusActivity.EXTRA_BATTERY_PCT, battery_percentage); + intent.putExtra(SolarEquipmentStatusActivity.EXTRA_BATTERY_WH, battery_wh); + intent.putExtra(SolarEquipmentStatusActivity.EXTRA_BATTERY_PCT, battery_pct); intent.putExtra(SolarEquipmentStatusActivity.EXTRA_PANEL1_WATT, p1_watt); intent.putExtra(SolarEquipmentStatusActivity.EXTRA_PANEL2_WATT, p2_watt); intent.putExtra(SolarEquipmentStatusActivity.EXTRA_OUTPUT1_WATT, output_to_inverter_1_watt); diff --git a/app/src/main/res/layout/dashboard_widget_generic_gauge.xml b/app/src/main/res/layout/dashboard_widget_generic_gauge.xml index d8039fa0a..e850add92 100644 --- a/app/src/main/res/layout/dashboard_widget_generic_gauge.xml +++ b/app/src/main/res/layout/dashboard_widget_generic_gauge.xml @@ -27,6 +27,7 @@ android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_marginTop="28dp" + android:gravity="center_horizontal" android:text="@string/stats_empty_value" android:textSize="30sp" />