Skip to content

Commit

Permalink
battery and sys info errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Oct 4, 2019
1 parent 115d79e commit c24a6f8
Show file tree
Hide file tree
Showing 7 changed files with 235 additions and 28 deletions.
164 changes: 144 additions & 20 deletions modular-psu-firmware.eez-project
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@
},
{
"name": "sys.info.fan.status",
"description": "0: invalid (error)\n1: valid\n2: unsupported\n3: not installed",
"description": "",
"type": "enum",
"enumItems": "[\n\"Invalid\",\n\"Valid\",\n\"Unsupported\",\n\"Testing\",\n\"Not installed\"\n]",
"defaultValue": "1"
Expand Down Expand Up @@ -1736,10 +1736,21 @@
"defaultValue": "1"
},
{
"name": "sys_info_sdcard",
"name": "sys.info.sdcard.status",
"type": "enum",
"enumItems": "[\"Unsupported\", \"Present\", \"Not present\", \"No FAT\", \"Failed\", \"Busy\"]",
"defaultValue": "1"
},
{
"name": "sys.info.hasError",
"type": "boolean",
"defaultValue": "0"
},
{
"name": "sys.info.battery.status",
"type": "enum",
"enumItems": "[\n\"Invalid\",\n\"Valid\",\n\"Not installed\"\n]",
"defaultValue": "1"
}
],
"actions": [
Expand Down Expand Up @@ -4286,21 +4297,56 @@
"text": "|"
},
{
"type": "Text",
"type": "Select",
"style": {
"inheritFrom": "status_bgnd",
"font": "Heydings14",
"alignVertical": "center"
"inheritFrom": "default"
},
"activeStyle": {
"inheritFrom": "default"
},
"data": "sys.info.hasError",
"action": "show_sys_info",
"left": 235,
"top": 0,
"width": 41,
"height": 32,
"text": "?"
"widgets": [
{
"type": "Text",
"style": {
"inheritFrom": "status_bgnd",
"font": "Heydings14",
"alignVertical": "center"
},
"activeStyle": {
"inheritFrom": "default"
},
"action": "",
"left": 0,
"top": 0,
"width": 41,
"height": 32,
"text": "?"
},
{
"type": "Text",
"style": {
"inheritFrom": "status_bgnd",
"font": "Heydings14",
"alignVertical": "center",
"color": "status_warning"
},
"activeStyle": {
"inheritFrom": "default"
},
"action": "",
"left": 0,
"top": 0,
"width": 41,
"height": 32,
"text": "?"
}
]
},
{
"type": "Text",
Expand Down Expand Up @@ -26729,25 +26775,76 @@
"text": "Battery:"
},
{
"type": "DisplayData",
"type": "Select",
"style": {
"inheritFrom": "value_S",
"padding": 0
"inheritFrom": "default"
},
"activeStyle": {
"inheritFrom": "default",
"padding": 0
"inheritFrom": "default"
},
"data": "battery",
"data": "sys.info.battery.status",
"left": 114,
"top": 0,
"width": 122,
"height": 28,
"focusStyle": {
"inheritFrom": "default",
"padding": 0
},
"displayOption": 0
"widgets": [
{
"type": "DisplayData",
"style": {
"inheritFrom": "event_error",
"padding": 0
},
"activeStyle": {
"inheritFrom": "default",
"padding": 0
},
"data": "battery",
"left": 0,
"top": 0,
"width": 122,
"height": 28,
"focusStyle": {
"inheritFrom": "default",
"padding": 0
},
"displayOption": 0
},
{
"type": "DisplayData",
"style": {
"inheritFrom": "value_S",
"padding": 0
},
"activeStyle": {
"inheritFrom": "default",
"padding": 0
},
"data": "battery",
"left": 0,
"top": 0,
"width": 122,
"height": 28,
"focusStyle": {
"inheritFrom": "default",
"padding": 0
},
"displayOption": 0
},
{
"type": "Text",
"style": {
"inheritFrom": "value_S"
},
"activeStyle": {
"inheritFrom": "default"
},
"left": 0,
"top": 0,
"width": 122,
"height": 28,
"text": "Not installed"
}
]
}
]
},
Expand Down Expand Up @@ -26828,7 +26925,7 @@
"activeStyle": {
"inheritFrom": "default"
},
"data": "sys_info_sdcard",
"data": "sys.info.sdcard.status",
"left": 350,
"top": 28,
"width": 122,
Expand Down Expand Up @@ -27036,7 +27133,7 @@
{
"type": "DisplayData",
"style": {
"inheritFrom": "value_S",
"inheritFrom": "event_error",
"padding": 0
},
"activeStyle": {
Expand Down Expand Up @@ -433878,6 +433975,24 @@
"name": "SYSTem:RESet",
"parameters": [],
"response": {}
},
{
"name": "SYSTem:MEASure[:SCALar][:VOLTage][:DC]?",
"parameters": [
{
"name": "choice",
"type": [
{
"type": "discrete",
"enumeration": "SystemMeasureVoltage"
}
]
}
],
"response": {
"type": "nr3",
"enumeration": "SystemMeasureVoltage"
}
}
]
},
Expand Down Expand Up @@ -435139,6 +435254,15 @@
"value": "3"
}
]
},
{
"name": "SystemMeasureVoltage",
"members": [
{
"name": "VBAT",
"value": "1"
}
]
}
]
},
Expand Down
43 changes: 36 additions & 7 deletions src/eez/apps/psu/gui/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2449,6 +2449,23 @@ void data_sys_temp_aux(data::DataOperationEnum operation, data::Cursor &cursor,
}
}

void data_sys_info_has_error(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
if (operation == data::DATA_OPERATION_GET) {
temperature::TempSensorTemperature &tempSensor = temperature::sensors[temp_sensor::AUX];
int err;
value = (
// AUX temp.
(tempSensor.isInstalled() && !tempSensor.isTestOK()) ||
// FAN
(aux_ps::fan::g_testResult == TEST_FAILED || aux_ps::fan::g_testResult == TEST_WARNING) ||
// Battery
mcu::battery::g_testResult == TEST_FAILED ||
// SD card
!eez::psu::sd_card::isMounted(&err)
) ? 1 : 0;
}
}

void data_sys_info_firmware_ver(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
if (operation == data::DATA_OPERATION_GET) {
value = data::Value(FIRMWARE);
Expand All @@ -2473,7 +2490,25 @@ void data_sys_info_cpu(data::DataOperationEnum operation, data::Cursor &cursor,
}
}

void data_sys_info_sdcard(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
void data_sys_info_battery_status(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
if (operation == data::DATA_OPERATION_GET) {
if (mcu::battery::g_testResult == TEST_FAILED) {
value = 0;
} else if (mcu::battery::g_testResult == TEST_OK) {
value = 1;
} else {
value = 2;
}
}
}

void data_battery(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
if (operation == data::DATA_OPERATION_GET) {
value = MakeValue(mcu::battery::g_battery, UNIT_VOLT);
}
}

void data_sys_info_sdcard_status(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
if (operation == data::DATA_OPERATION_GET) {
#if OPTION_SD_CARD
int err;
Expand Down Expand Up @@ -3704,12 +3739,6 @@ void data_simulator_load2(data::DataOperationEnum operation, data::Cursor &curso

#endif

void data_battery(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
if (operation == data::DATA_OPERATION_GET) {
value = MakeValue(mcu::battery::g_battery, UNIT_VOLT);
}
}

} // namespace gui
} // namespace eez

Expand Down
2 changes: 2 additions & 0 deletions src/eez/apps/psu/psu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ static bool testMaster() {

result &= temperature::test();

result &= mcu::battery::test();

// test BP3c
result &= bp3c::relays::test();

Expand Down
24 changes: 24 additions & 0 deletions src/eez/apps/psu/scpi/syst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include <eez/apps/psu/io_pins.h>
#include <eez/apps/psu/ontime.h>

#include <eez/modules/mcu/battery.h>

namespace eez {
namespace psu {
namespace scpi {
Expand Down Expand Up @@ -1497,6 +1499,28 @@ scpi_result_t scpi_cmd_systemReset(scpi_t *context) {
#endif
}

static scpi_choice_def_t systemMeasureVoltageChoice[] = {
{ "VBAT", 1 },
SCPI_CHOICE_LIST_END
};

scpi_result_t scpi_cmd_systemMeasureScalarVoltageDcQ(scpi_t *context) {
#if defined(EEZ_PLATFORM_STM32)
// TODO migrate to generic firmware
int32_t choice;
if (!SCPI_ParamChoice(context, systemMeasureVoltageChoice, &choice, true)) {
return SCPI_RES_ERR;
}

// only choice for now is VBAT
return result_float(context, 0, mcu::battery::g_battery, UNIT_VOLT);
#else
SCPI_ErrorPush(context, SCPI_ERROR_HARDWARE_MISSING);
return SCPI_RES_ERR;
#endif
}


} // namespace scpi
} // namespace psu
} // namespace eez
23 changes: 23 additions & 0 deletions src/eez/modules/mcu/battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ using namespace eez::mcu::battery;
#define VBAT_DIV 4
#define MAX_CONVERTED_VALUE 4095
#define VREF 3.3f
#define CONF_CONVERSION_DURATION 5 // 5ms

// If battery voltage is less than this value then battery should be replaced
#define CONF_MIN_ALLOWED_BATTERY_VOLTAGE 2.7f

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc) {
uint32_t convertedValue = HAL_ADC_GetValue(hadc);
Expand All @@ -41,6 +45,7 @@ namespace eez {
namespace mcu {
namespace battery {

TestResult g_testResult;
float g_battery;

#if defined(EEZ_PLATFORM_STM32)
Expand All @@ -60,10 +65,28 @@ void init() {
#endif
}

#if defined(EEZ_PLATFORM_STM32)
void checkBattery() {
g_testResult = g_battery >= CONF_MIN_ALLOWED_BATTERY_VOLTAGE ? TEST_OK : TEST_FAILED;
}
#endif

bool test() {
#if defined(EEZ_PLATFORM_STM32)
adcStart();
delay(CONF_CONVERSION_DURATION);
checkBattery();
#else
g_testResult = TEST_SKIPPED;
#endif
return g_testResult != TEST_FAILED;
}

void tick(uint32_t tickCount) {
#if defined(EEZ_PLATFORM_STM32)
int32_t diff = tickCount - g_lastTickCount;
if (diff >= 1000000) {
checkBattery();
adcStart();
g_lastTickCount = tickCount;
}
Expand Down
Loading

0 comments on commit c24a6f8

Please sign in to comment.