...
 
Commits (3)
......@@ -24,13 +24,6 @@
#------------Modified by Sydney Speckle, Nanotec Electronic GmbH & Co KG----------------
#
#
######################################################
###################USER###############################
PROJECT_NAME =emros
......@@ -80,7 +73,7 @@ BUILD_PATH := $(PROJECT_NAME)/$(BUILD_DIR)
INC := $(foreach sdir,$(MODULE_PATH),$(addprefix -I,$(sdir)/$(INC_FOLDER))) -I$(NANOTEC_BASE_PATH)/$(NANOTEC_INC_DIR)
C_SRC := $(foreach sdir,$(MODULE_PATH),$(wildcard $(sdir)/$(SRC_FOLDER)/*.c))
CXX_SRC := $(foreach sdir,$(MODULE_PATH),$(wildcard $(sdir)/$(SRC_FOLDER)/*.cpp)) $(PROJECT_NAME)/main.cpp $(NANOTEC_BASE_PATH)/$(NANOTEC_SRC_DIR)/gui.cpp $(NANOTEC_BASE_PATH)/$(NANOTEC_SRC_DIR)/tools.cpp
CXX_SRC := $(foreach sdir,$(MODULE_PATH),$(wildcard $(sdir)/$(SRC_FOLDER)/*.cpp)) $(PROJECT_NAME)/main.cpp $(NANOTEC_BASE_PATH)/$(NANOTEC_SRC_DIR)/gui.cpp
C_OBJ_ := $(patsubst %.c,%.o,$(C_SRC))
CXX_OBJ_ := $(patsubst %.cpp,%.o,$(CXX_SRC))
C_OBJ := $(addprefix $(BUILD_PATH)/obj/,$(notdir $(C_OBJ_)))
......@@ -95,7 +88,6 @@ MAKEFLAGS += --no-print-directory
MORE_WARNINGS = -Wall -Warray-bounds=2 -Wc++11-compat -Wc++14-compat -Wcast-align -Wcast-qual -Wchkp -Wcomments -Wconditionally-supported -Wconversion -Wdate-time -Wdelete-incomplete -Wdisabled-optimization -Wdouble-promotion -Wextra -Wfloat-conversion -Wformat-signedness -Winline -Winvalid-memory-model -Winvalid-pch -Wlogical-op -Wmissing-declarations -Wmissing-format-attribute -Wnormalized -Woverlength-strings -Wpointer-arith -Wredundant-decls -Wshadow -Wshift-count-negative -Wshift-count-overflow -Wsized-deallocation -Wsizeof-array-argument -Wstack-protector -Wstrict-aliasing -Wstrict-overflow=5 -Wsuggest-attribute=pure -Wsuggest-attribute=const -Wsuggest-attribute=format -Wsuggest-final-methods -Wsuggest-final-types -Wsuggest-override -Wswitch-bool -Wsync-nand -Wtrampolines -Wunsafe-loop-optimizations -Wunused -Wunused-but-set-variable -Wunused-local-typedefs -Wunused-macros -Wuseless-cast -Wvarargs -Wvariadic-macros -Wvector-operation-performance -Wvla -Wwrite-strings -Wzero-as-null-pointer-constant
#-Wsign-conversion -Wpacked -Wpacked-bitfield-compat -Wsuggest-attribute=noreturn
#GCC_PATH = /Your_Compiler_Path/gcc-arm-none-eabi-5_4-2016q3
CCPREFIX = arm-none-eabi-
......@@ -107,15 +99,12 @@ endif
WNORMAL = -Wall -Wno-reorder
PARANOID = -Wall -Wextra -Wunused-parameter -Wconversion -Wsign-compare -Wshadow -Wzero-as-null-pointer-constant -pedantic -Wno-reorder -Wcast-qual -Wuseless-cast
#AFLAGS = -D FREETYPE_ENABLED -D MTKERNEL -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -ffunction-sections -fdata-sections -O0 -ggdb -flto -fno-rtti -fno-exceptions $(INC) -Wl,-Map=$(BUILD_PATH)/bin/out.map,--gc-sections -specs=nano.specs -u _printf_float -static
#arm-none-eabi-g++ -std=c++11 -D FREETYPE_ENABLED -mcpu=cortex-m7 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -ffunction-sections -fstack-check -fdata-sections -O0 -ggdb -flto -fno-rtti -fno-exceptions -I../../inc -Iinc -Wl,-Map=output/out.map,--gc-sections -specs=nano.specs -static -T ../../tools\emp.ld *.cpp ../../src/*.cpp -L./../../lib -lnanotec_em -lfreetype -o output/a.out
AFLAGS = -D FREETYPE_ENABLED -D _GLIBCXX_USE_C99 -D MTKERNEL $(USER_DEFINES) $(PARANOID) $(MORE_WARNINGS) -mcpu=cortex-m7 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -ffunction-sections -fdata-sections -fstack-check $(OPTIMIZATION) -ggdb -fno-rtti -fno-exceptions $(LIB_PATHS) $(LIBS)
#AFLAGS = -D FREETYPE_ENABLED -D MTKERNEL -Wall -Wno-reorder -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -ffunction-sections -fdata-sections -fdump-class-hierarchy -O0 -ggdb -fno-rtti -fno-exceptions $(INC) -Wl,-Map=$(BUILD_PATH)/bin/out.map,--gc-sections -static -u _printf_float
CFLAGS = -c -std=c++11
LDFLAGS= $(LIB_PATHS) -std=c++11 -Wl,-Map=$(BUILD_PATH)/bin/out.map,--gc-sections --specs=nano.specs -u _printf_float -static -lc $(LIBS) -lc
#-specs=nosys.specs -specs=nano.specs -u _printf_float --specs=rdimon.specs -T nanotec/tools/emp.ld -flto-report
all:
@echo "[\033[94mrunning $(CORES) jobs...\033[0m] "
......
......@@ -18,7 +18,7 @@
#include "../../basecontroller/inc/basecontroller.h"
#include "../../devices/inc/service.h"
#include <cstring>
#include "../../../nanotec/inc/tools.h"
#include "gui_helper.h"
#include "../../system/inc/msg.h"
#include "../../utility_ofc/include/utility_ofc/singleton.h"
#include "../../emros_common/include/emros_common/emros_commands.h"
......
#ifndef NANOTEC_INC_GUI_HELPER_H_
#define NANOTEC_INC_GUI_HELPER_H_
#include "../../../nanotec/inc/nanoj.h"
#include <stdint.h>
#include <cstring>
#include <cstdio>
#include <cmath>
void DrawTacho(int32_t speed, uint16_t pos_x, uint16_t pos_y, uint16_t len, uint8_t no);
void DrawStringBugfix(uint16_t, uint16_t, fonthandle_t, const char*);
void DrawSystemLoad(rectangle_t);
#endif /* NANOTEC_INC_GUI_HELPER_H_ */
#include "../inc/gui_helper.h"
#include "../../../nanotec/inc/nanoj.h"
extern SYSTEMIF_Type *ptSysIf;
namespace {
const int32_t scaling_of_speed = 10;
const int32_t max_tacho_value = 100;
const int32_t non_zero_value = 255;
const float PI = 3.14159265358979323846f;
const float angle_of_tacho_null_position_radians = 156.0f / 180.0f * PI;
const float factor_radians_per_tacho_value = 2.27f / 180.0f * PI;
const uint16_t radius_tacho_center = 8;
const uint16_t overhang_of_needle_clearing = 5;
const uint8_t system_info_text_size_in_bytes = 100;
}
float ConvertSpeedToTachoValue(int32_t speed);
float CalculateTachoAngleInRadians(float tacho_value);
void EraseTachoNeedle(uint16_t pos_center_x, uint16_t pos_center_y, uint16_t needle_length);
void DrawTachoNeedle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
uint16_t CalculateCoordinateHorizontal(uint16_t pos_center_x,float angle_in_radians, uint16_t radius);
uint16_t CalculateCoordinateVertical(uint16_t pos_center_y,float tacho_angle_radians, uint16_t needle_length);
void LimitCoordinateToPosibleRange(uint16_t& coordinate, uint16_t center, uint16_t radius);
void LimitWidthToPosibleRange(uint16_t& width, uint16_t maximum);
void DrawTacho(int32_t speed, uint16_t pos_x, uint16_t pos_y,
uint16_t needle_length, uint8_t number_of_tacho) {
if (number_of_tacho == 1) {
static int32_t last_speed_tacho_1 = non_zero_value;
if (last_speed_tacho_1 == speed) {
return; // avoid unnecessary updates
}
last_speed_tacho_1 = speed;
} else if (number_of_tacho == 2) {
static int32_t last_speed_tacho_2 = non_zero_value;
if (last_speed_tacho_2 == speed) {
return; // avoid unnecessary updates
}
last_speed_tacho_2 = speed;
} else {
return; // given tacho number is not implemented
}
float tacho_value = ConvertSpeedToTachoValue(speed);
float angle_in_radians = CalculateTachoAngleInRadians(tacho_value);
uint16_t x1 = CalculateCoordinateHorizontal(pos_x, angle_in_radians, needle_length);
uint16_t y1 = CalculateCoordinateVertical(pos_y,angle_in_radians, needle_length);
uint16_t x2 = CalculateCoordinateHorizontal(pos_x, angle_in_radians, radius_tacho_center);
uint16_t y2 = CalculateCoordinateVertical(pos_y,angle_in_radians, radius_tacho_center);
EraseTachoNeedle(pos_x, pos_y, needle_length);
DrawTachoNeedle(x1, y1, x2, y2);
}
void DrawStringBugfix(uint16_t xPos, uint16_t yPos, fonthandle_t font,
const char* string) {
fonthandle_t default_font = Graphics::GetDefaultFont();
Graphics::SelectFont(font);
uint32_t len = std::strlen(string);
char* inStr = new char[len];
if (!inStr) {
DBGBRK(true);
//TODO: error
return;
}
std::strcpy(inStr, string);
uint16_t len_sub_string;
char* pResult;
uint16_t row = 0;
uint16_t offset = 0;
if (inStr[len - 1] == '\n') {
inStr[len - 1] = 0;
}
char* tempStr = new char[len];
while ((pResult = std::strchr(inStr + offset, '\n'))) {
std::memset(tempStr, 0, len);
len_sub_string = uint16_t(pResult - inStr - offset);
if (len_sub_string > 0) {
std::strncpy(tempStr, inStr + offset, len_sub_string);
Graphics::DrawString(xPos,
uint16_t(yPos + row * font->DefaultLineSpacing),
string_t(tempStr), len_sub_string);
offset = uint16_t(offset + len_sub_string + 1);
row++;
}
}
len_sub_string = uint16_t(len - offset);
if (len_sub_string > 0) {
std::memset(tempStr, 0, std::strlen(tempStr));
std::strncpy(tempStr, inStr + offset, len_sub_string);
Graphics::DrawString(xPos,
uint16_t(yPos + row * font->DefaultLineSpacing),
string_t(tempStr), len_sub_string);
}
Graphics::WaitUntilPreviousOpFinished();
Graphics::SelectFont(default_font);
delete[] tempStr;
delete[] inStr;
}
void DrawSystemLoad(rectangle_t box) {
fonthandle_t font = SYSFONT8;
uint16_t offset = 2;
float _mem_load = (float(ptSysIf->DynamicMemUsed)
/ float(ptSysIf->DynamicMemSize));
char system_info_text[system_info_text_size_in_bytes] = { };
Graphics::SelectColor(COLOR_DARKGRAY);
Graphics::DrawFilledRectangle(box);
Graphics::SelectColor(COLOR_WHITE);
std::sprintf(system_info_text, "System Info:\nMemory Load:\nSize: %u b\n(%.3f%%)",
(unsigned int) (ptSysIf->DynamicMemUsed), double(_mem_load));
DrawStringBugfix(uint16_t(box.left + offset), uint16_t(box.top + offset),
font, system_info_text);
std::memset(system_info_text, 0, system_info_text_size_in_bytes);
std::sprintf(system_info_text, "CPU Load:\n%u%%", (unsigned int) (ptSysIf->CpuLoad));
DrawStringBugfix(uint16_t(box.left + offset),
uint16_t(box.top + 5 * font->DefaultLineSpacing + offset), font,
system_info_text);
rectangle_t mem;
rectangle_t cpu;
mem.top = int16_t((box.top + offset) + 4 * font->DefaultLineSpacing);
mem.left = int16_t(box.left + offset);
mem.height = uint16_t(font->DefaultLineSpacing - 1);
mem.width = uint16_t(box.width - offset * 2);
cpu.top = int16_t((box.top + offset) + 7 * font->DefaultLineSpacing);
cpu.left = int16_t(box.left + offset);
cpu.height = uint16_t(font->DefaultLineSpacing - 1);
cpu.width = uint16_t(box.width - offset * 2);
Graphics::SelectColor(COLOR_GREEN);
Graphics::DrawFilledRectangle(mem);
Graphics::DrawFilledRectangle(cpu);
Graphics::SelectColor(COLOR_RED);
mem.width = uint16_t(mem.width * _mem_load / 1000);
LimitWidthToPosibleRange(mem.width, box.width);
cpu.width = uint16_t(cpu.width * ptSysIf->CpuLoad / 100);
LimitWidthToPosibleRange(cpu.width, box.width);
Graphics::DrawFilledRectangle(mem);
Graphics::DrawFilledRectangle(cpu);
}
// Helper functions - tacho //////////////////////////////////////////////////////
float ConvertSpeedToTachoValue(int32_t speed) {
float tacho_value = 0;
tacho_value = float(std::abs(int(speed))) / scaling_of_speed;
if (tacho_value > max_tacho_value) {
tacho_value = max_tacho_value;
}
return tacho_value;
}
float CalculateTachoAngleInRadians(float tacho_value) {
float tacho_angle_radians = (tacho_value * factor_radians_per_tacho_value)
+ angle_of_tacho_null_position_radians;
return tacho_angle_radians;
}
uint16_t CalculateCoordinateHorizontal(uint16_t pos_center_x,float angle_in_radians, uint16_t radius)
{
uint16_t x_coordinate = (uint16_t) (std::cos(angle_in_radians) * radius + pos_center_x);
LimitCoordinateToPosibleRange(x_coordinate, pos_center_x, radius);
return x_coordinate;
}
uint16_t CalculateCoordinateVertical(uint16_t pos_center_y,float angle_in_radians, uint16_t radius)
{
uint16_t y_coordinate = (uint16_t) (std::sin(angle_in_radians) * radius + pos_center_y);
LimitCoordinateToPosibleRange(y_coordinate, pos_center_y, radius);
return y_coordinate;
}
void LimitCoordinateToPosibleRange(uint16_t& coordinate, uint16_t center, uint16_t radius)
{
uint16_t minimum = 0;
if (center > radius)
{
minimum = uint16_t(center - radius);
}else{
minimum = 0;
}
uint16_t maximum = uint16_t(center + radius);
if(coordinate > maximum)
{
coordinate = maximum;
}
if(coordinate < minimum)
{
coordinate = minimum;
}
}
void EraseTachoNeedle(uint16_t pos_center_x, uint16_t pos_center_y, uint16_t needle_length) {
Graphics::SelectLayer(LAYER_TOP);
Graphics::SelectColor(COLOR_BLACK);
Graphics::DrawFilledRectangle(
uint16_t(pos_center_x - needle_length - overhang_of_needle_clearing),
uint16_t(pos_center_y - needle_length - overhang_of_needle_clearing),
uint16_t(2 * (needle_length + overhang_of_needle_clearing)),
uint16_t(2 * (needle_length + overhang_of_needle_clearing)));
Graphics::WaitUntilPreviousOpFinished();
}
void DrawTachoNeedle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) {
Graphics::SelectColor(COLOR_BLUE);
Graphics::DrawLine(x1, y1, x2, y2);
Graphics::DrawLine(uint16_t(x1 + 1), uint16_t(y1 + 0), uint16_t(x2 + 1),
uint16_t(y2 + 0));
Graphics::DrawLine(uint16_t(x1 + 0), uint16_t(y1 + 1), uint16_t(x2 + 0),
uint16_t(y2 + 1));
}
// Helper functions - system load //////////////////////////////////////////////////////
void LimitWidthToPosibleRange(uint16_t& width, uint16_t maximum)
{
if (width > 2 * maximum)
{
width = 0; //assume underflow happened
}
if(width > maximum)
{
width = maximum;
}
}
Mar 19 2018 16:54:25
\ No newline at end of file
Subproject commit c18cc7fe55b32f9b7064a7bdb5b1a3eab2a69a2e
Subproject commit d89cdf0ed9a3c9fa896a5735c8aacbbbfd2b9def