Skip to content

Commit

Permalink
#92
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Jan 29, 2021
1 parent bfe90b1 commit 0176fc3
Show file tree
Hide file tree
Showing 37 changed files with 312 additions and 320 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.10)

project(modular-psu-firmware)

set (CMAKE_CXX_STANDARD 11)
set (CMAKE_CXX_STANDARD 14)

if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /wd4100 /wd4214 /wd4200 /wd4244 /wd4456 /wd4457 /wd4458 /wd4459 /wd4245 /wd4389 /wd4706 /wd4611 /wd4310")
Expand Down Expand Up @@ -30,7 +30,7 @@ else()
endif()

if (UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive -pedantic -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive -pedantic")
endif (UNIX)

add_definitions(-DDEBUG)
Expand Down
14 changes: 7 additions & 7 deletions src/eez/gui/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,31 @@ bool compare_INT_value(const Value &a, const Value &b) {
}

void INT_value_to_text(const Value &value, char *text, int count) {
strcatInt(text, value.getInt());
strcatInt(text, count, value.getInt());
}

bool compare_UINT8_value(const Value &a, const Value &b) {
return a.getUInt8() == b.getUInt8();
}

void UINT8_value_to_text(const Value &value, char *text, int count) {
strcatUInt32(text, value.getUInt8());
strcatUInt32(text, count, value.getUInt8());
}

bool compare_UINT16_value(const Value &a, const Value &b) {
return a.getUInt16() == b.getUInt16();
}

void UINT16_value_to_text(const Value &value, char *text, int count) {
strcatUInt32(text, value.getUInt16());
strcatUInt32(text, count, value.getUInt16());
}

bool compare_UINT32_value(const Value &a, const Value &b) {
return a.getUInt32() == b.getUInt32();
}

void UINT32_value_to_text(const Value &value, char *text, int count) {
strcatUInt32(text, value.getUInt32());
strcatUInt32(text, count, value.getUInt32());
}

bool compare_FLOAT_value(const Value &a, const Value &b) {
Expand Down Expand Up @@ -176,12 +176,12 @@ void FLOAT_value_to_text(const Value &value, char *text, int count) {
}

if (fixedDecimals) {
strcatFloat(text, floatValue, FLOAT_OPTIONS_GET_NUM_FIXED_DECIMALS(options));
strcatFloat(text, count, floatValue, FLOAT_OPTIONS_GET_NUM_FIXED_DECIMALS(options));
} else {
if (unit == UNIT_WATT || unit == UNIT_MILLI_WATT) {
strcatFloat(text, floatValue, 2);
strcatFloat(text, count, floatValue, 2);
} else {
strcatFloat(text, floatValue);
strcatFloat(text, count, floatValue);
}

int n = strlen(text);
Expand Down
18 changes: 11 additions & 7 deletions src/eez/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,18 @@ void Module::resetProfileToDefaults(uint8_t *buffer) {
void Module::getProfileParameters(uint8_t *buffer) {
auto parameters = (ProfileParameters *)buffer;

strcpy(parameters->label, label);
strncpy(parameters->label, label, sizeof(parameters->label));
parameters->label[sizeof(parameters->label) - 1] = 0;

parameters->color = color;
}

void Module::setProfileParameters(uint8_t *buffer, bool mismatch, int recallOptions) {
auto parameters = (ProfileParameters *)buffer;

strcpy(label, parameters->label);
strncpy(label, parameters->label, sizeof(label));
label[sizeof(label) - 1] = 0;

color = parameters->color;
}

Expand Down Expand Up @@ -247,7 +251,7 @@ void Module::setLabel(const char *value, int length) {
length = SLOT_LABEL_MAX_LENGTH;
}
strncpy(label, value, length);
label[length] = 0;
label[length - 1] = 0;
}

uint8_t Module::getColor() {
Expand Down Expand Up @@ -888,11 +892,11 @@ Module *getModule(uint16_t moduleType) {
void getModuleSerialInfo(uint8_t slotIndex, char *serialStr) {
auto &module = *g_slots[slotIndex];
if (module.idw0 != 0 || module.idw1 != 0 || module.idw2 != 0) {
sprintf(serialStr, "%08X", (unsigned int)module.idw0);
sprintf(serialStr + 8, "%08X", (unsigned int)module.idw1);
sprintf(serialStr + 16, "%08X", (unsigned int)module.idw2);
snprintf(serialStr, 9, "%08X", (unsigned int)module.idw0);
snprintf(serialStr + 8, 9, "%08X", (unsigned int)module.idw1);
snprintf(serialStr + 16, 9, "%08X", (unsigned int)module.idw2);
} else {
strcpy(serialStr, "N/A");
strncpy(serialStr, "N/A", 8);
}
}

Expand Down
38 changes: 12 additions & 26 deletions src/eez/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ namespace gui {

void data_usb_keyboard_state(DataOperationEnum operation, Cursor cursor, Value &value) {
if (operation == DATA_OPERATION_GET) {
static char g_keyboardInfoStr[2][256] = { 0 };
static const size_t KEYBOARD_INFO_STRING_SIZE = 256;
static char g_keyboardInfoStr[2][KEYBOARD_INFO_STRING_SIZE] = { 0 };
static KeyboardInfo g_latestKeyboardInfo;
static MouseInfo g_latestMouseInfo;
static int g_keyboardInfoStrIndex = 0;
Expand All @@ -303,7 +304,7 @@ void data_usb_keyboard_state(DataOperationEnum operation, Cursor cursor, Value &
str[0] = 0;

if (g_keyboardInfo.state != 0) {
sprintf(str, "State=0x%02X", g_keyboardInfo.state);
snprintf(str, KEYBOARD_INFO_STRING_SIZE, "State=0x%02X", g_keyboardInfo.state);
}

if (g_keyboardInfo.lctrl) {
Expand Down Expand Up @@ -338,36 +339,21 @@ void data_usb_keyboard_state(DataOperationEnum operation, Cursor cursor, Value &
strcat(str, " RGUI");
}

if (g_keyboardInfo.keys[0]) {
sprintf(str + strlen(str), " 0x%02X", g_keyboardInfo.keys[0]);
}

if (g_keyboardInfo.keys[1]) {
sprintf(str + strlen(str), " 0x%02X", g_keyboardInfo.keys[1]);
}

if (g_keyboardInfo.keys[2]) {
sprintf(str + strlen(str), " 0x%02X", g_keyboardInfo.keys[2]);
}

if (g_keyboardInfo.keys[3]) {
sprintf(str + strlen(str), " 0x%02X", g_keyboardInfo.keys[3]);
}

if (g_keyboardInfo.keys[4]) {
sprintf(str + strlen(str), " 0x%02X", g_keyboardInfo.keys[4]);
}

if (g_keyboardInfo.keys[5]) {
sprintf(str + strlen(str), " 0x%02X", g_keyboardInfo.keys[5]);
for (int i = 0; i < 6; i++) {
if (g_keyboardInfo.keys[0]) {
auto n = strlen(str);
snprintf(str + n, KEYBOARD_INFO_STRING_SIZE - n, " 0x%02X", g_keyboardInfo.keys[0]);
}
}

if (g_mouseInfo.x != 0) {
sprintf(str + strlen(str), " / X=%d", (int8_t)g_mouseInfo.x);
auto n = strlen(str);
snprintf(str + n, KEYBOARD_INFO_STRING_SIZE - n, " / X=%d", (int8_t)g_mouseInfo.x);
}

if (g_mouseInfo.y != 0) {
sprintf(str + strlen(str), " Y=%d", (int8_t)g_mouseInfo.y);
auto n = strlen(str);
snprintf(str + n, KEYBOARD_INFO_STRING_SIZE - n, " Y=%d", (int8_t)g_mouseInfo.y);
}

if (g_mouseInfo.button1) {
Expand Down
2 changes: 1 addition & 1 deletion src/eez/libs/sd_fat/stm32/sd_fat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ bool File::sync() {

void File::print(float value, int numDecimalDigits) {
char buffer[32];
sprintf(buffer, "%.*f", numDecimalDigits, value);
snprintf(buffer, sizeof(buffer), "%.*f", numDecimalDigits, value);
write((uint8_t *)buffer, strlen(buffer));
}

Expand Down
4 changes: 2 additions & 2 deletions src/eez/modules/bp3c/eeprom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ bool read(uint8_t slotIndex, uint8_t *buffer, uint16_t bufferSize, uint16_t addr

#if defined(EEZ_PLATFORM_SIMULATOR)
char fileName[20];
sprintf(fileName, "EEPROM_SLOT%d.state", slotIndex + 1);
snprintf(fileName, sizeof(fileName), "EEPROM_SLOT%d.state", slotIndex + 1);
char *filePath = getConfFilePath(fileName);
FILE *fp = fopen(filePath, "r+b");
if (fp == NULL) {
Expand Down Expand Up @@ -178,7 +178,7 @@ bool write(uint8_t slotIndex, const uint8_t *buffer, uint16_t bufferSize, uint16

#if defined(EEZ_PLATFORM_SIMULATOR)
char fileName[20];
sprintf(fileName, "EEPROM_SLOT%d.state", slotIndex + 1);
snprintf(fileName, sizeof(fileName), "EEPROM_SLOT%d.state", slotIndex + 1);
char *filePath = getConfFilePath(fileName);
FILE *fp = fopen(filePath, "r+b");
if (fp == NULL) {
Expand Down
Loading

0 comments on commit 0176fc3

Please sign in to comment.