Loading files
#include "gui.h"
#include "pushpull.h"
#include "Battery.h"
#include "Scope.h"
#include "scopescreen.h"
const uint16_t imagedata[1024] = {
0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,
0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,
0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,
0x0841,0x0841,0x0861,0x0861,0x0861,0x0861,0x0861,0x0861,0x0861,0x0861,0x0861,0x0861,0x0861,0x0861,0x0862,0x0862,0x0861,0x0861,0x0841,0x0841,0x0841,0x0841,0x0841,0x0841,0x0841,0x0841,0x0041,0x0021,0x0821,0x0821,0x0020,0x0021,
0x0861,0x1104,0x1925,0x1125,0x1125,0x1925,0x1925,0x1125,0x1125,0x1125,0x1125,0x1125,0x1145,0x1165,0x1166,0x1145,0x1165,0x1145,0x1125,0x1105,0x1104,0x10e4,0x1104,0x10e4,0x10e4,0x10e4,0x08c3,0x10c3,0x10c3,0x10c3,0x0861,0x0841,
0x0882,0x1945,0x1986,0x19a7,0x19a7,0x1987,0x1987,0x1966,0x1967,0x1966,0x1166,0x1966,0x1186,0x1187,0x11a7,0x1186,0x19a7,0x11a7,0x1166,0x1146,0x1146,0x1125,0x1146,0x1125,0x1125,0x1125,0x1145,0x1145,0x1125,0x1125,0x08a2,0x0841,
0x1082,0x1165,0x19c7,0x11c7,0x11c7,0x19c8,0x1987,0x1986,0x1187,0x1166,0x1146,0x1166,0x1186,0x11a6,0x11a7,0x0986,0x11a6,0x19a7,0x1166,0x1166,0x1146,0x1145,0x1126,0x1125,0x1125,0x1166,0x1145,0x0924,0x1166,0x1145,0x0882,0x0841,
0x1082,0x1986,0x11e7,0x3cd1,0x4d93,0x1207,0x19a7,0x1187,0x1187,0x1146,0x1146,0x1166,0x1186,0x1186,0x1248,0x4dd4,0x2bce,0x11a7,0x1186,0x1166,0x1166,0x1146,0x1146,0x1125,0x1145,0x0965,0x2b8c,0x4512,0x09c6,0x1166,0x08a2,0x0841,
0x1082,0x1145,0x234b,0x3d73,0x3d52,0x2bcd,0x1187,0x11a7,0x1187,0x1166,0x1166,0x11a7,0x11a7,0x0986,0x3490,0x2bed,0x3d12,0x1a89,0x11a7,0x1187,0x1167,0x1146,0x1146,0x1166,0x1146,0x1248,0x3d32,0x3d31,0x2bee,0x1165,0x08c3,0x0021,
0x10a2,0x1165,0x2c6f,0x1b2b,0x1269,0x2cb0,0x1186,0x1187,0x1187,0x1166,0x1166,0x11a7,0x1186,0x1a48,0x2c8f,0x0945,0x238c,0x23ad,0x1146,0x1187,0x1166,0x1146,0x1146,0x1166,0x1105,0x236c,0x23ac,0x09a6,0x2cb0,0x11a6,0x08a3,0x0020,
0x1082,0x19e7,0x2c90,0x1228,0x11c7,0x2c6f,0x1228,0x1166,0x1187,0x1166,0x1166,0x11a7,0x1146,0x234c,0x236c,0x1146,0x1a48,0x244f,0x1166,0x1187,0x1166,0x1125,0x1146,0x1166,0x0945,0x242e,0x1269,0x1125,0x1bed,0x1289,0x0882,0x0021,
0x0841,0x1aca,0x242e,0x11a7,0x1187,0x23ee,0x1b0b,0x1166,0x11a7,0x1166,0x1187,0x11c8,0x1186,0x2c0e,0x1a69,0x1186,0x11a7,0x246f,0x1228,0x1187,0x1186,0x1146,0x1166,0x1146,0x11e7,0x244f,0x11a7,0x1166,0x1b2b,0x1b8c,0x0862,0x0021,
0x0841,0x1bac,0x1b2b,0x1166,0x1166,0x1aea,0x1b8c,0x1145,0x1187,0x1166,0x1186,0x1187,0x11e7,0x240e,0x11a7,0x1186,0x1126,0x23ad,0x1aca,0x1146,0x1166,0x1125,0x1146,0x1125,0x1a89,0x1b6c,0x1125,0x1145,0x1228,0x1c0d,0x0882,0x0021,
0x1082,0x1c8f,0x1269,0x1186,0x1186,0x1229,0x240e,0x1186,0x11a7,0x1166,0x1187,0x1166,0x1aaa,0x23ad,0x1166,0x1166,0x1146,0x1aea,0x1b8c,0x1145,0x1186,0x1125,0x1166,0x1125,0x1b2b,0x1aaa,0x1125,0x1145,0x1186,0x1c2e,0x08e3,0x0020,
0x1103,0x148e,0x11e7,0x11a7,0x1187,0x11a7,0x242e,0x11e8,0x1187,0x1187,0x11a7,0x1167,0x1b4c,0x1aea,0x1166,0x1166,0x1166,0x1228,0x240d,0x1186,0x1186,0x1146,0x1166,0x1166,0x23cd,0x1208,0x1146,0x1166,0x1145,0x1c0d,0x1185,0x0000,
0x1247,0x142c,0x1146,0x1166,0x1166,0x1125,0x1b8c,0x1a69,0x1146,0x1166,0x1186,0x1166,0x1bcc,0x1207,0x1145,0x1125,0x1146,0x1166,0x1bac,0x11a6,0x1146,0x1125,0x1145,0x1186,0x1b8b,0x1145,0x1125,0x1125,0x1104,0x1b0a,0x1206,0x0000,
0x1267,0x12e9,0x1186,0x1186,0x1166,0x1146,0x1b0b,0x1b4b,0x1146,0x1187,0x1186,0x11e8,0x240d,0x1186,0x1166,0x1145,0x1166,0x1126,0x1b8c,0x1289,0x1146,0x1166,0x1145,0x1a69,0x1b6b,0x1125,0x1145,0x1125,0x1125,0x1248,0x12c8,0x0000,
0x1082,0x1145,0x11c7,0x1187,0x1186,0x1187,0x1a89,0x240e,0x1187,0x11c7,0x1186,0x1aca,0x23ad,0x1145,0x1187,0x1146,0x1166,0x1146,0x1b0b,0x1b6c,0x1146,0x1186,0x1145,0x234c,0x1aea,0x0925,0x1146,0x1145,0x1165,0x11c6,0x1267,0x0000,
0x0862,0x1125,0x11a7,0x1186,0x1166,0x1186,0x11c7,0x244e,0x11c7,0x11a7,0x1166,0x1b6c,0x1aea,0x0925,0x1166,0x1125,0x1146,0x1146,0x1228,0x1bed,0x1166,0x1186,0x1146,0x23cd,0x1207,0x1145,0x1125,0x1125,0x1145,0x1125,0x10e3,0x0041,
0x0861,0x1105,0x11a7,0x11a7,0x1166,0x1187,0x1166,0x244e,0x1aca,0x11c7,0x11a7,0x244f,0x1248,0x1146,0x1166,0x1125,0x1146,0x1166,0x1186,0x244f,0x11e7,0x1186,0x11e8,0x242e,0x1166,0x1166,0x1145,0x1125,0x1165,0x1105,0x10c2,0x0841,
0x0841,0x1104,0x11a7,0x11a7,0x1186,0x1187,0x1146,0x236c,0x23cd,0x11c6,0x1268,0x2c90,0x11a6,0x1166,0x1166,0x1125,0x1146,0x1186,0x1145,0x242e,0x1aea,0x0965,0x1b0a,0x23cd,0x0925,0x1166,0x1145,0x1145,0x1146,0x1125,0x0882,0x0841,
0x0841,0x10e4,0x1166,0x11a6,0x1166,0x1166,0x1145,0x1228,0x2caf,0x0986,0x1b6b,0x23ed,0x0925,0x1166,0x1146,0x1125,0x1125,0x1146,0x0905,0x1b2b,0x240e,0x0924,0x242e,0x1aa9,0x1104,0x1145,0x1125,0x1125,0x1125,0x1125,0x0882,0x0020,
0x0841,0x10e4,0x1166,0x11c7,0x1186,0x1186,0x1186,0x0986,0x34f1,0x1bac,0x3511,0x1aca,0x1146,0x1166,0x1146,0x1125,0x1145,0x1166,0x1166,0x1207,0x3d52,0x1b6b,0x3511,0x09a6,0x1146,0x1145,0x1145,0x1145,0x1145,0x1145,0x08a2,0x0020,
0x0841,0x10e4,0x1166,0x11a7,0x11a7,0x1187,0x1186,0x11a6,0x130a,0x66b7,0x3490,0x0986,0x1186,0x1146,0x1146,0x1125,0x1126,0x1146,0x1166,0x0965,0x2bed,0x66d8,0x1b4b,0x0966,0x1145,0x1145,0x1145,0x1145,0x1125,0x1125,0x0882,0x0020,
0x0841,0x10e4,0x1146,0x1186,0x11a6,0x1186,0x1166,0x11a6,0x11e7,0x1248,0x11c7,0x1186,0x1145,0x1125,0x1146,0x1125,0x1125,0x1146,0x1125,0x1166,0x11c7,0x1227,0x11c6,0x1166,0x1125,0x1145,0x1145,0x1125,0x1105,0x1104,0x0862,0x0020,
0x0841,0x10e4,0x1146,0x1186,0x11c7,0x11c7,0x1187,0x11a7,0x11e7,0x11a7,0x1186,0x1166,0x1145,0x1146,0x1146,0x1125,0x1146,0x1166,0x1146,0x1166,0x1187,0x11a6,0x11a7,0x1186,0x1145,0x1166,0x1166,0x1125,0x0905,0x0904,0x0861,0x0020,
0x0841,0x1104,0x1146,0x1166,0x11c7,0x1208,0x11c7,0x11c7,0x11c7,0x1187,0x1146,0x1166,0x1146,0x1146,0x1146,0x1125,0x1146,0x1167,0x1146,0x1166,0x1166,0x1186,0x11a7,0x11a7,0x1186,0x11a6,0x1186,0x1104,0x08e4,0x10e4,0x0861,0x0020,
0x0841,0x0882,0x08c3,0x10c3,0x1104,0x1144,0x1124,0x1124,0x1104,0x08e3,0x08c3,0x08c3,0x08a3,0x08a3,0x08c3,0x08c3,0x08c3,0x08c3,0x08c3,0x08c3,0x08c3,0x08c3,0x08e3,0x08e3,0x08e3,0x08e3,0x08c3,0x0882,0x0882,0x0862,0x0841,0x0021,
0x0021,0x0021,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0020,0x0021,0x0021,
0x0021,0x0021,0x0021,0x0021,0x0021,0x0041,0x0041,0x0021,0x0041,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0041,0x0041,0x0041,0x0041,0x0041,0x0021,0x0021,0x0021,0x0021,0x0021,
0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,
0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,0x0021,
};
static Image_t icon = { .width = 32, .height = 32, .data = imagedata };
/* Forward declaration of actual app task */
static void Scope(void *unused);
/* Creates the app task, called from desktop when user start the app */
static void Scope_Start(){
xTaskCreate(Scope, "Scope", 1000, NULL, 3, NULL);
}
/* Register this app */
void Scope_Init() {
App_Register("Scope", "Monitor current and voltage", Scope_Start, icon);
}
static TaskHandle_t handle;
//static void pushpullCallback(PushPull_State_t *state) {
// if (sampleCnt < SAMPLES) {
// vResponse[sampleCnt] = state->voltage;
// cResponse[sampleCnt] = state->current;
// sampleCnt++;
// } else {
// pushpull_SetCallback(NULL);
// BaseType_t yield;
// samplingDone = true;
// portYIELD_FROM_ISR(yield);
// }
//}
static int32_t currentScale;
static int32_t currentOffset;
static int32_t voltageScale;
static int32_t voltageOffset;
static int32_t timebase;
static bool running;
static Scopescreen *scope;
static constexpr uint16_t scopeWidth = 280;
static constexpr uint8_t scopeHorDivs = 8;
static void scopeChangeCurrent(Widget&) {
scope->ChangeLineSetting(0, currentScale, currentOffset);
}
static void scopeChangeVoltage(Widget&) {
scope->ChangeLineSetting(1, voltageScale, voltageOffset);
}
static void pushpullCallback(PushPull_State_t *state) {
static uint32_t lastUpdate = 0;
constexpr uint16_t updatePeriod = 20;
static int64_t avgCur = 0;
static uint64_t avgVol = 0;
static uint32_t sampleCnt = 0;
static constexpr int16_t horDivSize = scopeWidth / scopeHorDivs;
avgCur += state->current;
avgVol += state->voltage;
sampleCnt++;
uint32_t usPerPixel = timebase * 1000 / horDivSize;
static uint32_t usPassed = 0;
usPassed += 1000;
if (usPassed >= usPerPixel) {
int32_t cur = avgCur / sampleCnt;
int32_t vol = avgVol / sampleCnt;
avgCur = 0;
avgVol = 0;
sampleCnt = 0;
do {
scope->AddLineData(0, cur);
scope->AddLineData(1, vol);
usPassed -= usPerPixel;
} while (usPassed >= usPerPixel);
}
if (HAL_GetTick() - lastUpdate > updatePeriod) {
lastUpdate = HAL_GetTick();
scope->UpdateDisplay();
}
}
static void onOffChange(Widget&) {
if (running) {
pushpull_SetCallback(pushpullCallback);
} else {
pushpull_SetCallback(nullptr);
}
}
static void Scope(void *unused) {
handle = xTaskGetCurrentTaskHandle();
/* Create GUI elements */
Container *c= new Container(COORDS(280, 240));
c->setPosition(COORDS(40, 0));
currentScale = 1000000;
currentOffset = 0;
voltageScale = 3000000;
voltageOffset = 0;
timebase = 1000;
running = true;
const int32_t maxCurScale = 2000000;
const int32_t minCurScale = 1000;
const int32_t maxVolScale = 5000000;
const int32_t minVolScale = 1000;
const int32_t minTimebase = 10;
const int32_t maxTimebase = 60000;
const int32_t minCurOffset = -Limits.minCurrent;
const int32_t minVolOffset = -Limits.maxVoltage;
Label *lScale = new Label("Scale/Div:", Font_Medium);
Label *lOffset = new Label("Offset:", Font_Medium);
Label *lTimebase = new Label("Timebase:", Font_Medium);
Label *lRunning = new Label("Running:", Font_Medium);
Entry *eCurrentScale = new Entry(¤tScale, &maxCurScale, &minCurScale,
Font_Medium, 6, &Unit_Current, COLOR_RED);
Entry *eCurrentOffset = new Entry(¤tOffset, &Limits.maxCurrent, &minCurOffset,
Font_Medium, 6, &Unit_Current, COLOR_RED);
Entry *eVoltageScale = new Entry(&voltageScale, &maxVolScale, &minVolScale,
Font_Medium, 6, &Unit_Voltage, COLOR_DARKGREEN);
Entry *eVoltageOffset = new Entry(&voltageOffset, &Limits.maxVoltage, &minVolOffset,
Font_Medium, 6, &Unit_Voltage, COLOR_DARKGREEN);
Entry *eTimebase = new Entry(&timebase, &maxTimebase, &minTimebase,
Font_Medium, 6, &Unit_Time);
eCurrentScale->setCallback(scopeChangeCurrent);
eCurrentOffset->setCallback(scopeChangeCurrent);
eVoltageScale->setCallback(scopeChangeVoltage);
eVoltageOffset->setCallback(scopeChangeVoltage);
Checkbox *cOn = new Checkbox(&running, onOffChange, COORDS(11,11));
scope = new Scopescreen(COORDS(scopeWidth, 215), scopeHorDivs, 6);
scope->AddLine(COLOR_RED, currentScale, currentOffset);
scope->AddLine(COLOR_DARKGREEN, voltageScale, voltageOffset);
c->attach(scope, COORDS(0, 0));
c->attach(lScale, COORDS(0, 218));
c->attach(eCurrentScale, COORDS(65, 216));
c->attach(eVoltageScale, COORDS(115, 216));
c->attach(lOffset, COORDS(0, 230));
c->attach(eCurrentOffset, COORDS(65, 228));
c->attach(eVoltageOffset, COORDS(115, 228));
c->attach(lTimebase, COORDS(160, 230));
c->attach(eTimebase, COORDS(235, 228));
c->attach(lRunning, COORDS(160, 218));
c->attach(cOn, COORDS(235, 216));
/* Notify desktop of started app */
desktop_AppStarted(Scope_Start, c);
pushpull_SetCallback(pushpullCallback);
while(1) {
uint32_t signal;
if (App_Handler(&signal, 300)) {
/* Handle app signals */
}
}
}
fae49d278This file is pinned to the selected release. Download the original to open it in your design tool.