@@ -58,42 +58,12 @@ extern "C" {
58
58
}
59
59
}
60
60
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
- }
74
61
extern void gl_dashboard_update_indicator (void * pDashboard, int indicator, int level) {
75
62
GLDashboardMgr* p = static_cast <GLDashboardMgr*>(pDashboard);
76
63
if (p) {
77
64
p->UpdateIndicator (indicator,level);
78
65
}
79
66
}
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
- }
97
67
};
98
68
99
69
GLDashboardMgr* GLDashboardMgr::g_pGLDashboardMgr = nullptr ;
@@ -107,11 +77,7 @@ GLDashboardMgr::GLDashboardMgr(int iType):m_iType(iType) {
107
77
g_pGLDashboardMgr = this ;
108
78
}
109
79
110
-
111
-
112
80
GLDashboardMgr::~GLDashboardMgr () {
113
- m_bQuit = true ;
114
- glutLeaveMainLoop ();
115
81
}
116
82
117
83
void GLDashboardMgr::Start () {
@@ -127,38 +93,18 @@ void GLDashboardMgr::Start() {
127
93
128
94
void GLDashboardMgr::UpdateMotor (int motor, int pos) {
129
95
if (motor>=0 && motor<DB_MOTOR_COUNT) {
130
- m_motors.at (motor)->SetCurrentPos (pos);
131
96
if (m_p3DVis) {
132
97
m_p3DVis->OnMotorStep (motor,pos);
133
- m_p3DVis->OnPosChanged (motor, m_motors.at (motor)->GetCurrentPos ());
134
98
}
135
99
} else {
136
100
std::cerr << " Error: Invalid motor index: " << std::to_string (motor) <<" !\n " ;
137
101
}
138
102
}
139
103
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
-
156
104
void GLDashboardMgr::UpdateIndicator (int iInd, int level) {
157
105
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;
159
107
if (iInd>=0 && iInd<DB_IND_COUNT) {
160
- m_indicators.at (iInd)->SetValue (gsl::narrow<uint8_t >(bIsDigital ? level*255U : level));
161
-
162
108
if (m_p3DVis) {
163
109
m_p3DVis->OnBoolChanged (iInd, bIsFan ? level : level>0 );
164
110
}
@@ -167,66 +113,11 @@ void GLDashboardMgr::UpdateIndicator(int iInd, int level) {
167
113
}
168
114
}
169
115
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
-
210
116
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 );
217
117
switch (m_iType) {
218
118
case DB_MINI_LITE:
219
119
case DB_MINI_FULL:
220
- case DB_MINI_DB:
221
120
{
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
-
230
121
}
231
122
break ;
232
123
default :
@@ -235,50 +126,7 @@ void GLDashboardMgr::SetupHardware() {
235
126
}
236
127
237
128
void * GLDashboardMgr::RunThread (void *p) {
238
- int argc = 0 ;
239
- char **argv = nullptr ;
240
-
241
129
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);
282
130
// Also set up the 3D visuals.
283
131
switch (m_iType) {
284
132
case DB_MINI_FULL:
@@ -296,22 +144,3 @@ void* GLDashboardMgr::RunThread(void *p) {
296
144
glutMainLoop ();
297
145
return p;
298
146
}
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
- }
0 commit comments