Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

Spindle.cc File Reference

#include "Spindle.hh"

Include dependency graph for Spindle.cc:

Include dependency graph

Go to the source code of this file.

Defines

#define SPINDLE

Functions

Widget SpindleControl (Dimension x0, Dimension x1, Dimension y1, Dimension y2, Dimension boxMarginWidth, Dimension boxMarginHeight, Widget parent)
void buttonCB (Widget mw, XtPointer cd, XtPointer cb)
void unbuttonCB (Widget mw, XtPointer cd, XtPointer cb)
void change_spindle (int type)
void checkSpindleReversal ()
void stop_changing_spindle (int type)
double get_speed ()
void turnSpindleOn ()
void turnSpindleOff ()
void updateSpindleSpeed ()
void setSpindleSpeed (double speed)
void changeDirection ()
void showSpindle (void)
void hideSpindle (void)
void stopSpindle (void)


Define Documentation

#define SPINDLE
 

Definition at line 1 of file Spindle.cc.


Function Documentation

Widget SpindleControl Dimension    x0,
Dimension    x1,
Dimension    y1,
Dimension    y2,
Dimension    boxMarginWidth,
Dimension    boxMarginHeight,
Widget    parent
 

Definition at line 6 of file Spindle.cc.

00009 {
00010   arrowFrame =
00011     XtVaCreateManagedWidget ("arrowFrame", xmFrameWidgetClass, parent,
00012                              XmNfractionBase, 5,
00013                              XmNleftPosition, x0,
00014                              XmNrightPosition, x1,
00015                              XmNtopPosition, y1,
00016                              XmNbottomPosition, y2,
00017                              XmNmarginWidth, boxMarginWidth,
00018                              XmNmarginHeight, boxMarginHeight,
00019                              XmNtopAttachment, XmATTACH_POSITION,
00020                              XmNbottomAttachment, XmATTACH_POSITION,
00021                              XmNleftAttachment, XmATTACH_POSITION,
00022                              XmNrightAttachment, XmATTACH_POSITION,
00023                              XmNmarginWidth, 5,
00024                              XmNmarginHeight, 5,
00025                              XmNmappedWhenManaged, False,
00026                              XmNtraversalOn, False, NULL);
00027 
00028   arrowForm =
00029     XtVaCreateManagedWidget ("arrowForm", xmFormWidgetClass, arrowFrame,
00030                              XmNmarginWidth, 5, XmNmarginHeight, 5, NULL);
00031   Dimension width = 100;
00032   Dimension height = 50;
00033   XmPushButtonWidget pb;
00034 
00035   reverseButton = XtVaCreateManagedWidget (SPINDLE_REVERSE_STR,
00036                                            xmPushButtonWidgetClass, arrowForm,
00037                                            XmNtopAttachment, XmATTACH_FORM,
00038                                            XmNbottomAttachment, XmATTACH_NONE,
00039                                            XmNleftAttachment, XmATTACH_FORM,
00040                                            XmNrightAttachment, XmATTACH_NONE,
00041                                            XmNshadowThickness, 4,
00042                                            XmNwidth, width,
00043                                            XmNheight, height, NULL);
00044 
00045   pb = (XmPushButtonWidget) reverseButton;
00046   pb->pushbutton.armed = false;
00047 
00048   XtAddCallback (reverseButton, XmNarmCallback,
00049                  buttonCB, (XtPointer) SPINDLE_REVERSE);
00050 
00051   XmString SpindleLabel =
00052     XmStringCreateLtoR ((char *) SPINDLE_LABEL_STR, XmSTRING_DEFAULT_CHARSET);
00053 
00054   spindleButton =
00055     XtVaCreateManagedWidget ("button", xmPushButtonWidgetClass, arrowForm,
00056                              XmNtopAttachment, XmATTACH_FORM,
00057                              XmNbottomAttachment, XmATTACH_NONE,
00058                              XmNleftAttachment, XmATTACH_WIDGET,
00059                              XmNleftWidget, reverseButton,
00060                              XmNleftOffset, 50,
00061                              XmNrightAttachment, XmATTACH_NONE,
00062                              XmNshadowThickness, 4,
00063                              XmNwidth, width,
00064                              XmNheight, height,
00065                              XmNlabelString, SpindleLabel, NULL);
00066 
00067   XmStringFree (SpindleLabel);
00068 
00069   pb = (XmPushButtonWidget) spindleButton;
00070   pb->pushbutton.armed = false;
00071 
00072   XtAddCallback (spindleButton, XmNarmCallback,
00073                  buttonCB, (XtPointer) SPINDLE_ON_OFF);
00074 
00075   forwardButton = XtVaCreateManagedWidget (SPINDLE_FORWARD_STR,
00076                                            xmPushButtonWidgetClass, arrowForm,
00077                                            XmNtopAttachment, XmATTACH_FORM,
00078                                            XmNbottomAttachment, XmATTACH_NONE,
00079                                            XmNleftAttachment, XmATTACH_WIDGET,
00080                                            XmNleftWidget, spindleButton,
00081                                            XmNleftOffset, 50,
00082                                            XmNrightAttachment, XmATTACH_NONE,
00083                                            XmNshadowThickness, 4,
00084                                            XmNwidth, width,
00085                                            XmNheight, height, NULL);
00086 
00087   pb = (XmPushButtonWidget) forwardButton;
00088   pb->pushbutton.armed = false;
00089 
00090   XtAddCallback (forwardButton, XmNarmCallback,
00091                  buttonCB, (XtPointer) SPINDLE_FORWARD);
00092   // Save the original colors so we can go back to this state.
00093   XtVaGetValues (forwardButton, XmNtopShadowColor, &original_tsc,
00094                  XmNbottomShadowColor, &original_bsc,
00095                  XmNarmColor, &original_ac,
00096                  XmNbackground, &original_bg, NULL);
00097 
00098   if (get_speed () >= 0)
00099     {
00100       PRESS (forwardButton);
00101       UNPRESS (reverseButton);
00102     }
00103   else
00104     {
00105       PRESS (reverseButton);
00106       UNPRESS (forwardButton);
00107     }
00108 
00109 
00110   SEPARATOR ();
00111 
00112   CREATE_PIXMAP (r_arrow, r_pixmap);
00113   CREATE_PIXMAP (r_arrow_in, r_pixmap_in);
00114   CREATE_PIXMAP (l_arrow, l_pixmap);
00115   CREATE_PIXMAP (l_arrow_in, l_pixmap_in);
00116   CREATE_PIXMAP (right_arrows, rr_pixmap);
00117   CREATE_PIXMAP (right_arrows_in, rr_pixmap_in);
00118   CREATE_PIXMAP (left_arrows, ll_pixmap);
00119   CREATE_PIXMAP (left_arrows_in, ll_pixmap_in);
00120 
00121   SPINDLE_AXIS (arrowB1, XmATTACH_FORM, NULL, 0, ll_pixmap, ARROW_LEFT_FAST);
00122   SPINDLE_AXIS (arrowB2, XmATTACH_WIDGET, arrowB1, 5, l_pixmap, ARROW_LEFT);
00123 
00124   SPINDLE_AXIS (arrowB3, XmATTACH_WIDGET, arrowB2, 225, r_pixmap,
00125                 ARROW_RIGHT);
00126   SPINDLE_AXIS (arrowB4, XmATTACH_WIDGET, arrowB3, 5, rr_pixmap,
00127                 ARROW_RIGHT_FAST);
00128 
00129   double mySpeed = get_speed ();
00130   LABEL_SPEED (mySpeed);
00131 
00132   updateSpindleSpeed ();
00133 
00134   return arrowFrame;
00135 }

void buttonCB Widget    mw,
XtPointer    cd,
XtPointer    cb
[static]
 

Definition at line 138 of file Spindle.cc.

Referenced by jogDone().

00139 {
00140   switch ((int) cd)
00141     {
00142     case ARROW_LEFT_FAST:
00143       XtVaSetValues (mw, XmNarmPixmap, ll_pixmap_in, NULL);
00144       break;
00145     case ARROW_LEFT:
00146       XtVaSetValues (mw, XmNarmPixmap, l_pixmap_in, NULL);
00147       break;
00148     case ARROW_RIGHT:
00149       XtVaSetValues (mw, XmNarmPixmap, r_pixmap_in, NULL);
00150       break;
00151     case ARROW_RIGHT_FAST:
00152       XtVaSetValues (mw, XmNarmPixmap, rr_pixmap_in, NULL);
00153       break;
00154     case SPINDLE_FORWARD:
00155       LOCK (forwardButton);
00156       UNLOCK (reverseButton);
00157       break;
00158     case SPINDLE_REVERSE:
00159       LOCK (reverseButton);
00160       UNLOCK (forwardButton);
00161       break;
00162     case SPINDLE_ON_OFF:
00163       isSpindleOn = !isSpindleOn;
00164       if (isSpindleOn)
00165         {
00166           PRESS (spindleButton);
00167           turnSpindleOn ();
00168         }
00169       else
00170         {
00171           UNPRESS (spindleButton);
00172           turnSpindleOff ();
00173         }
00174       updateSpindleSpeed ();
00175       return;
00176     default:
00177       return;
00178     }
00179 
00180   // We separate our change call since it involves our emc interface
00181   change_spindle ((int) cd);
00182 
00183   // If our spindle changes from positive to negative or vice versa
00184   checkSpindleReversal ();
00185 
00186   updateSpindleSpeed ();
00187 
00188 }

void changeDirection void   
 

Definition at line 335 of file Spindle.cc.

Referenced by change_spindle().

00336 {
00337   // Dummy: for now, assume instant reversal of spindle with same speed
00338   theSpeed = -(theSpeed);
00339 }

void change_spindle int    type [static]
 

Definition at line 209 of file Spindle.cc.

Referenced by buttonCB().

00210 {
00211 
00212 // TODO: call the emc spindle interface code here to change speed.
00213 // Note: call updateSpeed () to periodically update the GUI.
00214 
00215 #ifdef DEBUG
00216   char *whichWay[6] =
00217     { "Left fast", "Left", "Right", "Right fast", "Forward", "Reverse" };
00218   cout << "Start " << whichWay[type] << " change of spindle" << endl;
00219 #endif
00220 
00221   // Dummy: showing a synthetic change in speed
00222   switch (type)
00223     {
00224     case ARROW_LEFT_FAST:
00225       theSpeed -= FAST_CHANGE;
00226       break;
00227     case ARROW_LEFT:
00228       theSpeed -= SLOW_CHANGE;
00229       break;
00230     case ARROW_RIGHT:
00231       theSpeed += SLOW_CHANGE;
00232       break;
00233     case ARROW_RIGHT_FAST:
00234       theSpeed += FAST_CHANGE;
00235       break;
00236     case SPINDLE_FORWARD:
00237     case SPINDLE_REVERSE:
00238       changeDirection ();
00239       break;
00240     }
00241   // End of dummy code
00242 
00243   updateSpindleSpeed ();
00244 }

void checkSpindleReversal   [static]
 

Definition at line 247 of file Spindle.cc.

Referenced by buttonCB().

00248 {
00249   if (wasForward && get_speed () < 0 || !wasForward && get_speed () >= 0)
00250 
00251     {
00252       wasForward = !wasForward;
00253 
00254       TOGGLE (forwardButton);
00255       TOGGLE (reverseButton);
00256     }
00257 }

double get_speed   [static]
 

Definition at line 272 of file Spindle.cc.

Referenced by SpindleControl(), checkSpindleReversal(), and updateSpindleSpeed().

00273 {
00274 // TODO: call the emc spindle interface code here to get the actual speed
00275 //
00276 // set the global "theSpeed" to the actual speed.
00277 
00278   return theSpeed;
00279 }

void hideSpindle void   
 

Definition at line 349 of file Spindle.cc.

Referenced by buttonsCB(), and call_run().

00350 {
00351   if (arrowFrame)
00352     XtVaSetValues (arrowFrame, XmNmappedWhenManaged, False, NULL);
00353 }

void setSpindleSpeed double    speed
 

Definition at line 327 of file Spindle.cc.

00328 {
00329   theSpeed = speed;
00330   LABEL_SPEED_UPDATE (speed);
00331 }

void showSpindle void   
 

Definition at line 342 of file Spindle.cc.

Referenced by buttonsCB().

00343 {
00344   if (arrowFrame)
00345     XtVaSetValues (arrowFrame, XmNmappedWhenManaged, True, NULL);
00346 }

void stopSpindle void   
 

Definition at line 356 of file Spindle.cc.

Referenced by buttonsCB(), and call_run().

00357 {
00358   isSpindleOn = False;
00359   UNPRESS (spindleButton);
00360   turnSpindleOff ();
00361 }

void stop_changing_spindle int    type [static]
 

Definition at line 259 of file Spindle.cc.

Referenced by unbuttonCB().

00260 {
00261 
00262 // TODO: call the emc spindle interface code here to stop changing speed
00263 
00264 #ifdef DEBUG
00265   char *whichWay[4] = { "Left fast", "Left", "Right", "Right fast" };
00266   cout << "Stop " << whichWay[type] << " change of spindle" << endl;
00267 #endif
00268 
00269 }

void turnSpindleOff   [static]
 

Definition at line 290 of file Spindle.cc.

Referenced by buttonCB(), and stopSpindle().

00291 {
00292 #ifdef DEBUG
00293   cout << "Spindle is now Off" << endl;
00294 #endif
00295 }

void turnSpindleOn   [static]
 

Definition at line 282 of file Spindle.cc.

Referenced by buttonCB().

00283 {
00284 #ifdef DEBUG
00285   cout << "Spindle is now On" << endl;
00286 #endif
00287 }

void unbuttonCB Widget    mw,
XtPointer    cd,
XtPointer    cb
[static]
 

Definition at line 191 of file Spindle.cc.

00192 {
00193   switch ((int) cd)
00194     {
00195     case ARROW_LEFT_FAST:
00196     case ARROW_LEFT:
00197     case ARROW_RIGHT:
00198     case ARROW_RIGHT_FAST:
00199       stop_changing_spindle ((int) cd);
00200       break;
00201     default:
00202       return;
00203     }
00204 
00205   updateSpindleSpeed ();
00206 }

void updateSpindleSpeed  
 

Definition at line 299 of file Spindle.cc.

Referenced by SpindleControl(), buttonCB(), change_spindle(), and unbuttonCB().

00300 {
00301   double newSpeed = get_speed ();
00302   LABEL_SPEED_UPDATE (newSpeed);
00303 
00304   // Don't let them change spindle direction while moving
00305   if (isSpindleOn)
00306     {
00307       LOCK (forwardButton);
00308       LOCK (reverseButton);
00309     }
00310   else
00311     {
00312       if (wasForward)
00313         {
00314           LOCK (forwardButton);
00315           UNLOCK (reverseButton);
00316         }
00317       else
00318         {
00319           LOCK (reverseButton);
00320           UNLOCK (forwardButton);
00321         }
00322     }
00323 }


Generated on Sun Dec 2 15:28:27 2001 for EMC by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001