Skip to content

Commit

Permalink
ytgraph improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Jul 11, 2019
1 parent 07dc2bc commit 7160761
Show file tree
Hide file tree
Showing 12 changed files with 20,838 additions and 20,683 deletions.
20 changes: 7 additions & 13 deletions src/eez/apps/psu/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,11 +797,12 @@ void Channel::tick(uint32_t tick_usec) {
}
#endif

// update history values
auto uMonLast = roundPrec(u.mon_last, getPrecisionFromNumSignificantDecimalDigits(VOLTAGE_NUM_SIGNIFICANT_DECIMAL_DIGITS));
auto iMonLast = roundPrec(i.mon_last, getPrecisionFromNumSignificantDecimalDigits(CURRENT_NUM_SIGNIFICANT_DECIMAL_DIGITS));
if (historyPosition == -1) {
uHistory[0] = roundPrec(u.mon_last, getPrecisionFromNumSignificantDecimalDigits(
VOLTAGE_NUM_SIGNIFICANT_DECIMAL_DIGITS));
iHistory[0] = roundPrec(i.mon_last, getPrecisionFromNumSignificantDecimalDigits(
CURRENT_NUM_SIGNIFICANT_DECIMAL_DIGITS));
uHistory[0] = uMonLast;
iHistory[0] = iMonLast;
for (int i = 1; i < CHANNEL_HISTORY_SIZE; ++i) {
uHistory[i] = 0;
iHistory[i] = 0;
Expand All @@ -811,19 +812,12 @@ void Channel::tick(uint32_t tick_usec) {
historyLastTick = tick_usec;
} else {
uint32_t ytViewRateMicroseconds = (int)round(ytViewRate * 1000000L);

while (tick_usec - historyLastTick >= ytViewRateMicroseconds) {
uHistory[historyPosition] =
roundPrec(u.mon_last, getPrecisionFromNumSignificantDecimalDigits(
VOLTAGE_NUM_SIGNIFICANT_DECIMAL_DIGITS));
iHistory[historyPosition] =
roundPrec(i.mon_last, getPrecisionFromNumSignificantDecimalDigits(
CURRENT_NUM_SIGNIFICANT_DECIMAL_DIGITS));

uHistory[historyPosition] = uMonLast;
iHistory[historyPosition] = iMonLast;
if (++historyPosition == CHANNEL_HISTORY_SIZE) {
historyPosition = 0;
}

historyLastTick += ytViewRateMicroseconds;
}
}
Expand Down
19 changes: 3 additions & 16 deletions src/eez/gui/dialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,15 @@ void hideAsyncOperationInProgress() {
////////////////////////////////////////////////////////////////////////////////

void showProgressPage(const char *message, void (*abortCallback)()) {
data::set(data::Cursor(), DATA_ID_ALERT_MESSAGE, data::Value(message), 0);
g_appContext->m_dialogCancelCallback = abortCallback;
pushPage(PAGE_ID_PROGRESS);
psu::gui::g_psuAppContext.showProgressPage(message, abortCallback);
}

bool updateProgressPage(size_t processedSoFar, size_t totalSize) {
if (getActivePageId() == PAGE_ID_PROGRESS) {
if (totalSize > 0) {
g_progress = data::Value((int)round((processedSoFar * 1.0f / totalSize) * 100.0f),
VALUE_TYPE_PERCENTAGE);
} else {
g_progress = data::Value((uint32_t)processedSoFar, VALUE_TYPE_SIZE);
}
return true;
}
return false;
return psu::gui::g_psuAppContext.updateProgressPage(processedSoFar, totalSize);
}

void hideProgressPage() {
if (getActivePageId() == PAGE_ID_PROGRESS) {
popPage();
}
psu::gui::g_psuAppContext.hideProgressPage();
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
24,333 changes: 12,175 additions & 12,158 deletions src/eez/gui/document_simulator.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/eez/gui/document_simulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -1069,4 +1069,4 @@ enum PagesEnum {
PAGE_ID_MINIMIZED_APP_VIEW = 85
};

extern const uint8_t assets[201563];
extern const uint8_t assets[201839];
16,874 changes: 8,441 additions & 8,433 deletions src/eez/gui/document_stm32.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/eez/gui/document_stm32.h
Original file line number Diff line number Diff line change
Expand Up @@ -1051,4 +1051,4 @@ enum PagesEnum {
PAGE_ID_MINIMIZED_APP_VIEW = 83
};

extern const uint8_t assets[137781];
extern const uint8_t assets[137906];
2 changes: 1 addition & 1 deletion src/eez/gui/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ void drawBitmap(void *bitmapPixels, int bpp, int bitmapWidth, int bitmapHeight,
if (x_offset <= right && y_offset + height <= y2)
display::fillRect(x_offset, y_offset + height, right, y2);

// draw bitmap
// draw bitmap
uint8_t savedOpacity = display::getOpacity();

if (active) {
Expand Down
215 changes: 158 additions & 57 deletions src/eez/gui/widgets/yt_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,86 @@ void drawYTGraph(const WidgetCursor &widgetCursor, const Widget *widget, int sta
}
}

void drawYTGraphWithScrolling(const WidgetCursor &widgetCursor, const Widget *widget,
int previousHistoryValuePosition, int currentHistoryValuePosition, int numPositions,
int xGraphOffset, int graphWidth, uint16_t data1, float min1, float max1,
uint16_t data1Color, uint16_t data2, float min2, float max2, uint16_t data2Color,
uint16_t color, uint16_t backgroundColor) {

uint16_t color16 = display::getColor16FromIndex(color);
uint16_t data1Color16 = display::getColor16FromIndex(data1Color);
uint16_t data2Color16 = display::getColor16FromIndex(data2Color);

int numPointsToDraw = currentHistoryValuePosition - previousHistoryValuePosition;
if (numPointsToDraw < 0) {
numPointsToDraw += numPositions;
}

if (numPointsToDraw < numPositions) {
display::bitBlt(
widgetCursor.x + xGraphOffset + numPointsToDraw,
widgetCursor.y,
widgetCursor.x + xGraphOffset + numPositions - 1,
widgetCursor.y + widgetCursor.widget->h - 1,
widgetCursor.x + xGraphOffset,
widgetCursor.y);
}

int endX = widgetCursor.x + xGraphOffset + numPositions;
int startX = endX - numPointsToDraw;

int valuePositionLoop = (previousHistoryValuePosition + 1) % numPositions;
int previousValuePositionLoop = valuePositionLoop;
for (int x = startX; x < endX; x++) {
display::setColor16(color16);
display::drawVLine(x, widgetCursor.y, widget->h - 1);

int y1 = getYValue(widgetCursor, widget, data1, min1, max1, valuePositionLoop);
int y1Prev = getYValue(widgetCursor, widget, data1, min1, max1, previousValuePositionLoop);

int y2 = getYValue(widgetCursor, widget, data2, min2, max2, valuePositionLoop);
int y2Prev = getYValue(widgetCursor, widget, data2, min2, max2, previousValuePositionLoop);

if (abs(y1Prev - y1) <= 1 && abs(y2Prev - y2) <= 1) {
if (y1 == y2) {
display::setColor16(valuePositionLoop % 2 ? data2Color16 : data1Color16);
display::drawPixel(x, widgetCursor.y + y1);
} else {
display::setColor16(data1Color16);
display::drawPixel(x, widgetCursor.y + y1);

display::setColor16(data2Color16);
display::drawPixel(x, widgetCursor.y + y2);
}
} else {
display::setColor16(data1Color16);
if (abs(y1Prev - y1) <= 1) {
display::drawPixel(x, widgetCursor.y + y1);
} else {
if (y1Prev < y1) {
display::drawVLine(x, widgetCursor.y + y1Prev + 1, y1 - y1Prev - 1);
} else {
display::drawVLine(x, widgetCursor.y + y1, y1Prev - y1 - 1);
}
}

display::setColor16(data2Color16);
if (abs(y2Prev - y2) <= 1) {
display::drawPixel(x, widgetCursor.y + y2);
} else {
if (y2Prev < y2) {
display::drawVLine(x, widgetCursor.y + y2Prev + 1, y2 - y2Prev - 1);
} else {
display::drawVLine(x, widgetCursor.y + y2, y2Prev - y2 - 1);
}
}
}

previousValuePositionLoop = valuePositionLoop;
valuePositionLoop = (valuePositionLoop + 1) % numPositions;
}
}

void YTGraphWidget_draw(const WidgetCursor &widgetCursor) {
const Widget *widget = widgetCursor.widget;
YTGraphWidget *ytGraphWidget = (YTGraphWidget *)widget->specific;
Expand All @@ -119,16 +199,19 @@ void YTGraphWidget_draw(const WidgetCursor &widgetCursor) {
((YTGraphWidgetState *)widgetCursor.currentState)->y2Data =
data::get(widgetCursor.cursor, ytGraphWidget->y2Data);

bool refresh = !widgetCursor.previousState || widgetCursor.previousState->flags.active !=
widgetCursor.currentState->flags.active;
bool refresh = !widgetCursor.previousState ||
widgetCursor.previousState->flags.active != widgetCursor.currentState->flags.active;

if (refresh) {
// draw background
uint16_t color =
widgetCursor.currentState->flags.active ? style->color : style->background_color;
display::setColor(color);
display::fillRect(widgetCursor.x, widgetCursor.y, widgetCursor.x + (int)widget->w - 1,
widgetCursor.y + (int)widget->h - 1);
display::fillRect(
widgetCursor.x,
widgetCursor.y,
widgetCursor.x + (int)widget->w - 1,
widgetCursor.y + (int)widget->h - 1);
}

int textWidth = 62; // TODO this is hardcoded value
Expand Down Expand Up @@ -161,12 +244,11 @@ void YTGraphWidget_draw(const WidgetCursor &widgetCursor) {

// draw graph
int graphWidth = widget->w - textWidth;

int numHistoryValues = g_appContext->getNumHistoryValues(widget->data);
int currentHistoryValuePosition =
g_appContext->getCurrentHistoryValuePosition(widgetCursor.cursor, widget->data);
g_appContext->getCurrentHistoryValuePosition(widgetCursor.cursor, widget->data);

static int lastPosition[10]; // TODO 10 is hardcoded
((YTGraphWidgetState *)widgetCursor.currentState)->position = currentHistoryValuePosition;

float min1 = data::getMin(widgetCursor.cursor, widget->data).getFloat();
float max1 = data::getLimit(widgetCursor.cursor, widget->data).getFloat();
Expand All @@ -176,63 +258,82 @@ void YTGraphWidget_draw(const WidgetCursor &widgetCursor) {

int iChannel = widgetCursor.cursor.i >= 0 ? widgetCursor.cursor.i : 0;

int startPosition;
int endPosition;
if (refresh || iChannel >= 10) {
startPosition = 0;
endPosition = numHistoryValues;
} else {
startPosition = lastPosition[iChannel];
if (startPosition == currentHistoryValuePosition) {
return;
int previousHistoryValuePosition = widgetCursor.previousState ?
((YTGraphWidgetState *)widgetCursor.previousState)->position :
currentHistoryValuePosition + 1;

if (previousHistoryValuePosition != currentHistoryValuePosition) {
if (1) {
// a new way of drawing yt graph using scrolling
drawYTGraphWithScrolling(
widgetCursor, widget, previousHistoryValuePosition, currentHistoryValuePosition, numHistoryValues,
textWidth, graphWidth, widget->data, min1, max1, y1Style->color,
ytGraphWidget->y2Data, min2, max2, y2Style->color,
widgetCursor.currentState->flags.active ? style->color : style->background_color,
widgetCursor.currentState->flags.active ? style->background_color : style->color);
}
endPosition = currentHistoryValuePosition;
}
else {
// an old way of drawing yt graph which draws graph from left to right in a loop with moving vertical line

int startPosition;
int endPosition;
if (refresh || iChannel >= 10) {
startPosition = 0;
endPosition = numHistoryValues;
}
else {
startPosition = previousHistoryValuePosition;
if (startPosition == currentHistoryValuePosition) {
return;
}
endPosition = currentHistoryValuePosition;
}

if (startPosition < endPosition) {
drawYTGraph(
widgetCursor, widget, startPosition, endPosition, currentHistoryValuePosition,
numHistoryValues, textWidth, graphWidth, widget->data, min1, max1, y1Style->color,
ytGraphWidget->y2Data, min2, max2, y2Style->color,
widgetCursor.currentState->flags.active ? style->color : style->background_color,
widgetCursor.currentState->flags.active ? style->background_color : style->color);
} else {
drawYTGraph(
widgetCursor, widget, startPosition, numHistoryValues, currentHistoryValuePosition,
numHistoryValues, textWidth, graphWidth, widget->data, min1, max1, y1Style->color,
ytGraphWidget->y2Data, min2, max2, y2Style->color,
widgetCursor.currentState->flags.active ? style->color : style->background_color,
widgetCursor.currentState->flags.active ? style->background_color : style->color);

drawYTGraph(
widgetCursor, widget, 0, endPosition, currentHistoryValuePosition, numHistoryValues,
textWidth, graphWidth, widget->data, min1, max1, y1Style->color, ytGraphWidget->y2Data,
min2, max2, y2Style->color,
widgetCursor.currentState->flags.active ? style->color : style->background_color,
widgetCursor.currentState->flags.active ? style->background_color : style->color);
}
if (startPosition < endPosition) {
drawYTGraph(
widgetCursor, widget, startPosition, endPosition, currentHistoryValuePosition,
numHistoryValues, textWidth, graphWidth, widget->data, min1, max1, y1Style->color,
ytGraphWidget->y2Data, min2, max2, y2Style->color,
widgetCursor.currentState->flags.active ? style->color : style->background_color,
widgetCursor.currentState->flags.active ? style->background_color : style->color);
}
else {
drawYTGraph(
widgetCursor, widget, startPosition, numHistoryValues, currentHistoryValuePosition,
numHistoryValues, textWidth, graphWidth, widget->data, min1, max1, y1Style->color,
ytGraphWidget->y2Data, min2, max2, y2Style->color,
widgetCursor.currentState->flags.active ? style->color : style->background_color,
widgetCursor.currentState->flags.active ? style->background_color : style->color);

drawYTGraph(
widgetCursor, widget, 0, endPosition, currentHistoryValuePosition, numHistoryValues,
textWidth, graphWidth, widget->data, min1, max1, y1Style->color, ytGraphWidget->y2Data,
min2, max2, y2Style->color,
widgetCursor.currentState->flags.active ? style->color : style->background_color,
widgetCursor.currentState->flags.active ? style->background_color : style->color);
}

int x = widgetCursor.x + textWidth;
int x = widgetCursor.x + textWidth;

// draw cursor
display::setColor(style->color);
display::drawVLine(x + currentHistoryValuePosition, widgetCursor.y, (int)widget->h - 1);
// draw cursor
display::setColor(style->color);
display::drawVLine(x + currentHistoryValuePosition, widgetCursor.y, (int)widget->h - 1);

// draw blank lines
int x1 = x + (currentHistoryValuePosition + 1) % numHistoryValues;
int x2 = x + (currentHistoryValuePosition + CONF_GUI_YT_GRAPH_BLANK_PIXELS_AFTER_CURSOR) %
numHistoryValues;
// draw blank lines
int x1 = x + (currentHistoryValuePosition + 1) % numHistoryValues;
int x2 = x + (currentHistoryValuePosition + CONF_GUI_YT_GRAPH_BLANK_PIXELS_AFTER_CURSOR) %
numHistoryValues;

display::setColor(style->background_color);
if (x1 < x2) {
display::fillRect(x1, widgetCursor.y, x2, widgetCursor.y + (int)widget->h - 1);
} else {
display::fillRect(x1, widgetCursor.y, x + graphWidth - 1,
widgetCursor.y + (int)widget->h - 1);
display::fillRect(x, widgetCursor.y, x2, widgetCursor.y + (int)widget->h - 1);
display::setColor(style->background_color);
if (x1 < x2) {
display::fillRect(x1, widgetCursor.y, x2, widgetCursor.y + (int)widget->h - 1);
}
else {
display::fillRect(x1, widgetCursor.y, x + graphWidth - 1, widgetCursor.y + (int)widget->h - 1);
display::fillRect(x, widgetCursor.y, x2, widgetCursor.y + (int)widget->h - 1);
}
}
}

lastPosition[iChannel] = currentHistoryValuePosition;
}

} // namespace gui
Expand Down
1 change: 1 addition & 0 deletions src/eez/gui/widgets/yt_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct YTGraphWidget {
struct YTGraphWidgetState {
WidgetState genericState;
data::Value y2Data;
uint16_t position;
};

void YTGraphWidget_draw(const WidgetCursor &widgetCursor);
Expand Down
1 change: 1 addition & 0 deletions src/eez/modules/mcu/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ void drawRect(int x1, int y1, int x2, int y2);
void fillRect(int x1, int y1, int x2, int y2, int radius = 0);
void drawHLine(int x, int y, int l);
void drawVLine(int x, int y, int l);
void bitBlt(int x1, int y1, int x2, int y2, int x, int y);
void drawBitmap(int x, int y, int sx, int sy, void *data, int bpp);
void drawStr(const char *text, int textLength, int x, int y, int clip_x1, int clip_y1, int clip_x2,
int clip_y2, gui::font::Font &font);
Expand Down
15 changes: 15 additions & 0 deletions src/eez/modules/mcu/simulator/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,21 @@ void drawVLine(int x, int y, int l) {
g_painted = true;
}

void bitBlt(int x1, int y1, int x2, int y2, int dstx, int dsty) {
uint32_t *frontPanelBuffer = g_frontPanelBuffer == g_frontPanelBuffer1 ? g_frontPanelBuffer2 : g_frontPanelBuffer1;

setXY(dstx, dsty, dstx + x2 - x1, dsty + y2 - y1);
for (int y = y1; y <= y2; y++) {
for (int x = x1; x <= x2; x++) {
uint8_t *src = (uint8_t *)(g_frontPanelBuffer + y * g_frontPanelWidth + x);
uint16_t color = RGB_TO_COLOR(src[2], src[1], src[0]);
setPixel(color);
}
}

g_painted = true;
}

void drawBitmap(int x, int y, int sx, int sy, void *data, int bpp) {
if (bpp == 32) {
setXY(x, y, x + sx - 1, y + sy - 1);
Expand Down
Loading

0 comments on commit 7160761

Please sign in to comment.