Skip to content

Commit ba79cf3

Browse files
authored
Rework dashboard to native QEMU (#101)
* Rework dashboard to native QEMU. Needs cleanup. * Suppress default LPT/TTY ports. * Fix some memory leaks (Closes #81) * strip out deprecated GL dashboard code
1 parent fdcac08 commit ba79cf3

30 files changed

+855
-865
lines changed

hw/arm/prusa/meson.build

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ arm_ss.add(when: 'CONFIG_BUDDYBOARD', if_true: files(
2929
'parts/encoder_input.c',
3030
'parts/fan.c',
3131
'parts/gl_dashboard.c',
32+
'parts/2d-dashboard.c',
3233
'parts/heater.c',
3334
'parts/irsensor.c',
3435
'parts/p404_key_input.c',
@@ -45,6 +46,8 @@ arm_ss.add(when: 'CONFIG_BUDDYBOARD', if_true: files(
4546
'utility/p404_script_console.c',
4647
'utility/p404scriptable.c',
4748
'utility/p404_keyclient.c',
49+
'utility/p404_motor_if.c',
50+
'utility/text_helper.c',
4851
))
4952

5053
# Use CONFIG_PRUSA_STM32_HACKS when building our target to enable our specific workarounds

hw/arm/prusa/opengl/GLDashboardMgr.cpp

+1-172
Original file line numberDiff line numberDiff line change
@@ -58,42 +58,12 @@ extern "C" {
5858
}
5959
}
6060

61-
extern void gl_dashboard_update_motor_stall(void* pDashboard, int motor, int level) {
62-
GLDashboardMgr* p = static_cast<GLDashboardMgr*>(pDashboard);
63-
if (p) {
64-
p->UpdateMotorStall(motor,level);
65-
}
66-
}
67-
68-
extern void gl_dashboard_update_motor_enable(void* pDashboard, int motor, int level) {
69-
GLDashboardMgr* p = static_cast<GLDashboardMgr*>(pDashboard);
70-
if (p) {
71-
p->UpdateMotorEnable(motor,level);
72-
}
73-
}
7461
extern void gl_dashboard_update_indicator(void* pDashboard, int indicator, int level) {
7562
GLDashboardMgr* p = static_cast<GLDashboardMgr*>(pDashboard);
7663
if (p) {
7764
p->UpdateIndicator(indicator,level);
7865
}
7966
}
80-
81-
void GLAPIENTRY
82-
GLErrorCB( GLenum, //source,
83-
GLenum type,
84-
GLuint id,
85-
GLenum severity,
86-
GLsizei, // length
87-
const GLchar* message,
88-
const void*) // userparam )
89-
{
90-
std::cerr << "GL:";
91-
if (type == GL_DEBUG_TYPE_ERROR)
92-
{
93-
std::cerr << "** GL ERROR **";
94-
}
95-
std::cerr << "ID:" << id << " type = " << type << " sev = " << severity << " message = " << message << '\n';
96-
}
9767
};
9868

9969
GLDashboardMgr* GLDashboardMgr::g_pGLDashboardMgr = nullptr;
@@ -107,11 +77,7 @@ GLDashboardMgr::GLDashboardMgr(int iType):m_iType(iType) {
10777
g_pGLDashboardMgr = this;
10878
}
10979

110-
111-
11280
GLDashboardMgr::~GLDashboardMgr() {
113-
m_bQuit = true;
114-
glutLeaveMainLoop();
11581
}
11682

11783
void GLDashboardMgr::Start() {
@@ -127,38 +93,18 @@ void GLDashboardMgr::Start() {
12793

12894
void GLDashboardMgr::UpdateMotor(int motor, int pos) {
12995
if (motor>=0 && motor<DB_MOTOR_COUNT) {
130-
m_motors.at(motor)->SetCurrentPos(pos);
13196
if (m_p3DVis) {
13297
m_p3DVis->OnMotorStep(motor,pos);
133-
m_p3DVis->OnPosChanged(motor, m_motors.at(motor)->GetCurrentPos());
13498
}
13599
} else {
136100
std::cerr << "Error: Invalid motor index: "<< std::to_string(motor) <<"!\n";
137101
}
138102
}
139103

140-
void GLDashboardMgr::UpdateMotorEnable(int motor, int pos) {
141-
if (motor>=0 && motor<DB_MOTOR_COUNT) {
142-
m_motors.at(motor)->SetEnable(pos>0);
143-
} else {
144-
std::cerr << "Error: Invalid motor index: "<< std::to_string(motor) <<"!\n";
145-
}
146-
}
147-
148-
void GLDashboardMgr::UpdateMotorStall(int motor, int pos) {
149-
if (motor>=0 && motor<DB_MOTOR_COUNT) {
150-
m_motors.at(motor)->SetStall(pos>0);
151-
} else {
152-
std::cerr << "Error: Invalid motor index: "<< std::to_string(motor) <<"!\n";
153-
}
154-
}
155-
156104
void GLDashboardMgr::UpdateIndicator(int iInd, int level) {
157105
bool bIsFan = iInd == DB_IND_EFAN || iInd == DB_IND_PFAN;
158-
bool bIsDigital = iInd == DB_IND_FSENS || iInd == DB_IND_ZPROBE;
106+
// bool bIsDigital = iInd == DB_IND_FSENS || iInd == DB_IND_ZPROBE;
159107
if (iInd>=0 && iInd<DB_IND_COUNT) {
160-
m_indicators.at(iInd)->SetValue(gsl::narrow<uint8_t>(bIsDigital ? level*255U : level));
161-
162108
if (m_p3DVis) {
163109
m_p3DVis->OnBoolChanged(iInd, bIsFan ? level : level>0);
164110
}
@@ -167,66 +113,11 @@ void GLDashboardMgr::UpdateIndicator(int iInd, int level) {
167113
}
168114
}
169115

170-
void GLDashboardMgr::Draw() {
171-
if (m_bQuit) {
172-
return;
173-
}
174-
glClear((GL_COLOR_BUFFER_BIT) | (GL_DEPTH_BUFFER_BIT));
175-
glLoadIdentity();
176-
glScalef(500.f/350, -4, 1);
177-
for (auto motor : m_motors) {
178-
motor->Draw();
179-
glTranslatef(0,10,0);
180-
}
181-
for (auto ind : m_indicators) {
182-
ind->Draw();
183-
glTranslatef(20,0,0);
184-
}
185-
glutSwapBuffers();
186-
m_iFrCount++;
187-
m_iTic=glutGet(GLUT_ELAPSED_TIME);
188-
auto iDiff = m_iTic - m_iLast;
189-
if (iDiff > 1000) {
190-
int iFPS = m_iFrCount*1000.f/(iDiff);
191-
m_iLast = m_iTic;
192-
m_iFrCount = 0;
193-
std::string strFPS = "Mini404 GL Dashboard (" +std::to_string(iFPS) + " FPS)";
194-
glutSetWindowTitle(strFPS.c_str());
195-
}
196-
}
197-
198-
void GLDashboardMgr::TimerCB(int i) {
199-
if (m_bQuit) {
200-
return;
201-
}
202-
glutSetWindow(m_iWindow);
203-
glutTimerFunc(32, m_fcnTimer, i);
204-
glutPostRedisplay();
205-
if(m_p3DVis) {
206-
m_p3DVis->FlagForRedraw();
207-
}
208-
}
209-
210116
void GLDashboardMgr::SetupHardware() {
211-
m_EFan.SetColor(0xFF0000);
212-
m_PFan.SetColor(0xFF0000);
213-
m_ZProbe.SetColor(0xFFFF0000);
214-
m_FSens.SetColor(0xFF00);
215-
m_Htr.SetColor(0xFF000000);
216-
m_Bed.SetColor(0xFF000000);
217117
switch (m_iType) {
218118
case DB_MINI_LITE:
219119
case DB_MINI_FULL:
220-
case DB_MINI_DB:
221120
{
222-
m_X.SetStepsPerMM(100*16);
223-
m_X.SetMaxPos(100*16*182);
224-
m_Y.SetStepsPerMM(100*16);
225-
m_Y.SetMaxPos(100*16*183);
226-
m_Z.SetStepsPerMM(400*16);
227-
m_Z.SetMaxPos(400*16*185);
228-
m_E.SetStepsPerMM(320*16);
229-
230121
}
231122
break;
232123
default:
@@ -235,50 +126,7 @@ void GLDashboardMgr::SetupHardware() {
235126
}
236127

237128
void* GLDashboardMgr::RunThread(void *p) {
238-
int argc = 0;
239-
char **argv = nullptr;
240-
241129
SetupHardware();
242-
243-
glutInit(&argc, argv); /* initialize GLUT system */
244-
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);
245-
glutInitContextVersion(3,0);
246-
glutSetOption(GLUT_MULTISAMPLE,2);
247-
glutInitDisplayMode((GLUT_RGB) | (GLUT_DOUBLE) | (GLUT_MULTISAMPLE));
248-
glutInitWindowSize(m_iWinW, m_iWinH); /* width=400pixels height=500pixels */
249-
m_iWindow = glutCreateWindow("Mini404 GL Dashboard"); /* create window */
250-
251-
glewInit();
252-
std::cout << "GL_VERSION : " << glGetString(GL_VERSION) << '\n';
253-
std::cout << "GL_VENDOR : " << glGetString(GL_VENDOR) << '\n';
254-
std::cout << "GL_RENDERER : " << glGetString(GL_RENDERER) << '\n';
255-
std::cout << "GLEW_VERSION : " << glewGetString(GLEW_VERSION) << '\n';
256-
#if !defined(__APPLE__)
257-
glDebugMessageCallback( GLErrorCB, nullptr );
258-
if (true)
259-
{
260-
glDebugMessageControl(GL_DONT_CARE,
261-
GL_DONT_CARE,
262-
GL_DEBUG_SEVERITY_NOTIFICATION,
263-
0, nullptr, GL_FALSE);
264-
}
265-
glEnable(GL_DEBUG_OUTPUT);
266-
#endif
267-
// Set up projection matrix
268-
auto fcnDraw = []() { g_pGLDashboardMgr->Draw();};
269-
glutDisplayFunc(fcnDraw);
270-
auto fcnClose = []() { g_pGLDashboardMgr->OnGlutClose();};
271-
glutCloseFunc(fcnClose);
272-
m_fcnTimer = [](int i) { g_pGLDashboardMgr->TimerCB(i);};
273-
glutTimerFunc(1000, m_fcnTimer, 0);
274-
auto fcnResize = [](int w, int h) { g_pGLDashboardMgr->ResizeCB(w,h);};
275-
glutReshapeFunc(fcnResize);
276-
glEnable(GL_MULTISAMPLE);
277-
glShadeModel(GL_SMOOTH);
278-
glClearColor(0.0f, 0.f, 0.f, 1.0f);
279-
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
280-
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
281-
glEnable(GL_BLEND);
282130
// Also set up the 3D visuals.
283131
switch (m_iType) {
284132
case DB_MINI_FULL:
@@ -296,22 +144,3 @@ void* GLDashboardMgr::RunThread(void *p) {
296144
glutMainLoop();
297145
return p;
298146
}
299-
300-
void GLDashboardMgr::OnGlutClose() {
301-
m_bQuit = true;
302-
}
303-
304-
305-
void GLDashboardMgr::ResizeCB(int w, int h) {
306-
if (m_bQuit) {
307-
return;
308-
}
309-
glViewport(0, 0, w, h);
310-
glMatrixMode(GL_PROJECTION);
311-
glLoadIdentity();
312-
glOrtho(0, w, 0, h, -1, 10);
313-
glTranslatef(0, h, 0);
314-
//glScalef(fScale,-fScale,1);
315-
glMatrixMode(GL_MODELVIEW);
316-
glLoadIdentity();
317-
}

hw/arm/prusa/opengl/GLDashboardMgr.h

-37
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525

2626
#include <cstdint> // for uint32_t
2727
#include "../parts/dashboard_types.h"
28-
#include "GLMotor.h"
29-
#include "IPCIndicator.h"
30-
#include <array>
3128
#include <memory>
3229
#include <pthread.h>
3330
class MK3SGL;
@@ -45,52 +42,20 @@ class GLDashboardMgr
4542

4643
void UpdateIndicator(int iInd, int level);
4744

48-
void UpdateMotorStall(int motor, int level);
49-
50-
void UpdateMotorEnable(int motor, int level);
51-
5245
private:
5346

5447
void SetupHardware();
5548

56-
// Draws the visuals within the current GL transformation context.
57-
void Draw();
58-
59-
void SetWindow(int iWin) { m_iWindow = iWin;};
60-
61-
void ResizeCB(int w, int h);
62-
63-
void TimerCB(int i);
64-
65-
void OnGlutClose();
66-
6749
void* RunThread(void *p);
6850

69-
int m_iWindow = 0;
7051
pthread_t m_glThread;
7152
pthread_cond_t m_glReady;
7253
pthread_mutex_t m_glMtx;
7354

74-
void (*m_fcnTimer)(int i) = nullptr;
75-
76-
int m_iWinW = 500, m_iWinH = 200;
77-
7855
int m_iType = DB_NONE;
7956

80-
int m_iTic = 0, m_iLast = 0, m_iFrCount = 0;
81-
8257
static GLDashboardMgr* g_pGLDashboardMgr;
8358

84-
GLMotor m_X{'X'}, m_Y{'Y'}, m_Z{'Z'}, m_E{'E',true};
85-
86-
std::array<GLMotor*,4> m_motors = {&m_X, &m_Y, &m_Z, &m_E};
87-
88-
IPCIndicator m_EFan {'E'}, m_PFan{'P'}, m_FSens {'F'}, m_ZProbe{'Z'}, m_Bed{'B'}, m_Htr{'H'};
89-
90-
std::array<IPCIndicator*, 6> m_indicators = {&m_PFan, &m_EFan, &m_FSens, &m_ZProbe, &m_Bed, &m_Htr};
91-
92-
bool m_bQuit = false;
93-
9459
std::unique_ptr<MK3SGL> m_p3DVis {nullptr};
9560

9661
};
@@ -105,8 +70,6 @@ extern void gl_dashboard_reset(void* pDashboard);
10570
extern void gl_dashboard_run(void* pDashboard);
10671

10772
extern void gl_dashboard_update_motor(void* pDashboard, int motor, int pos);
108-
extern void gl_dashboard_update_motor_enable(void* pDashboard, int motor, int pos);
109-
extern void gl_dashboard_update_motor_stall(void* pDashboard, int motor, int pos);
11073

11174
extern void gl_dashboard_update_indicator(void *pDashboard, int indicator, int level);
11275

0 commit comments

Comments
 (0)