Index: trunk/MagicSoft/Cosy/gui/MGAccuracy.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGAccuracy.cc	(revision 2514)
+++ trunk/MagicSoft/Cosy/gui/MGAccuracy.cc	(revision 2518)
@@ -149,4 +149,15 @@
 }
 
+void MGAccuracy::InitBar()
+{
+    fBar = new TLine(0, 0, 0, 0);
+    fBar->SetLineColor(kBlack);
+    fBar->SetLineStyle(1);
+    fBar->SetLineWidth(5);
+    fBar->Draw();
+
+    fList->Add(fBar);
+}
+
 void MGAccuracy::InitCross()
 {
@@ -176,4 +187,5 @@
     InitText();
     InitCross();
+    InitBar();
 
     InitCanvas();
@@ -215,7 +227,8 @@
     double dist = acos(d);
 
-    dist *= 3600./d2r;
+    dist *= 3600./d2r; // [min]
 
     int rs = (int)floor(fmod(dist, 60.));
+
     dist /= 60.;
     int rm = (int)dist;//floor(fmod(dist, 60.));
@@ -225,4 +238,13 @@
 
     fTxt->SetText(fTxt->GetX(), fTxt->GetY(), txt);
+
+    fBar->SetX2(dist*60);
+    if (dist*16384<1*360*60)
+        fBar->SetLineColor(kGreen);
+    else
+        if (dist*16384<2*360*60)
+            fBar->SetLineColor(kYellow);
+        else
+            fBar->SetLineColor(kRed);
 }
 
Index: trunk/MagicSoft/Cosy/gui/MGAccuracy.h
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGAccuracy.h	(revision 2514)
+++ trunk/MagicSoft/Cosy/gui/MGAccuracy.h	(revision 2518)
@@ -24,8 +24,11 @@
     TText  *fTxt;
 
+    TLine  *fBar;
+
     void DrawCoordinateSystem();
 
     void InitText();
     void InitCross();
+    void InitBar();
 
     void UpdateText(Float_t zd, Float_t x, Float_t y);
Index: trunk/MagicSoft/Cosy/gui/MGCosy.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGCosy.cc	(revision 2514)
+++ trunk/MagicSoft/Cosy/gui/MGCosy.cc	(revision 2518)
@@ -53,4 +53,5 @@
     kPB_CALCALTAZ,
     kPB_TPOINT,
+    kPB_ENDSWITCH,
     kPB_START,
     kPB_DISPLAY1,
@@ -270,27 +271,15 @@
     fStopped->SetBackgroundColor(color);
 
-    fError   ->Move(10, 25);
-    fMoving  ->Move(10, 25+20);
-    fTracking->Move(10, 25+40);
-    fStopping->Move(10, 25+60);
-    fStopped ->Move(10, 25+80);
-    fAvailMac1->Move(10, 25+120);
-    fAvailMac2->Move(10, 25+140);
+    fError   ->MoveResize(10, 25, 60, 20);
+    fMoving  ->MoveResize(10, 25+20, 60, 20);
+    fTracking->MoveResize(10, 25+40, 60, 20);
+    fStopping->MoveResize(10, 25+60, 60, 20);
+    fStopped ->MoveResize(10, 25+80, 60, 20);
+    fAvailMac1->MoveResize(10, 25+120, 60, 20);
+    fAvailMac2->MoveResize(10, 25+140, 60, 20);
     //fAvailMac3->Move(10, 25+160);
-    fAvailSe1->Move(10, 25+180);
-    fAvailSe2->Move(10, 25+200);
-    fAvailSe3->Move(10, 25+220);
-
-    fError   ->Resize(60, 20);
-    fMoving  ->Resize(60, 20);
-    fTracking->Resize(60, 20);
-    fStopping->Resize(60, 20);
-    fStopped ->Resize(60, 20);
-    fAvailMac1->Resize(60, 20);
-    fAvailMac2->Resize(60, 20);
-    //fAvailMac3->Resize(60, 20);
-    fAvailSe1->Resize(60, 20);
-    fAvailSe2->Resize(60, 20);
-    fAvailSe3->Resize(60, 20);
+    fAvailSe1->MoveResize(10, 25+200, 60, 20);
+    fAvailSe2->MoveResize(10, 25+220, 60, 20);
+    fAvailSe3->MoveResize(10, 25+180, 60, 20);
 
     fList->Add(fError);
@@ -486,24 +475,20 @@
 
     but= new TGTextButton(tf2, "Ra -",  kPB_RAm);
-    but->Resize(50, 25);
-    but->Move(25, 210);
+    but->MoveResize(25, 210, 50, 25);
     but->SetToolTipText("Right ascension -= 1'");
     but->Associate(this);
     fList->Add(but);
     but= new TGTextButton(tf2, "RA +",  kPB_RAp);
-    but->Resize(50, 25);
-    but->Move(90, 210);
+    but->MoveResize(90, 210, 50, 25);
     but->SetToolTipText("Right ascension += 1'");
     but->Associate(this);
     fList->Add(but);
     but= new TGTextButton(tf2, "DEC +",  kPB_DECp);
-    but->Resize(50, 25);
-    but->Move(55, 185);
+    but->MoveResize(55, 185, 50, 25);
     but->SetToolTipText("Declination += 1'");
     but->Associate(this);
     fList->Add(but);
     but= new TGTextButton(tf2, "DEC -",  kPB_DECm);
-    but->Resize(50, 25);
-    but->Move(55, 235);
+    but->MoveResize(55, 235, 50, 25);
     but->SetToolTipText("Declination -= 1'");
     but->Associate(this);
@@ -511,6 +496,5 @@
 
     but = new TGTextButton(tf1, "Move'n'Track", kPB_TRACKPOS);
-    but->Resize(100, 25);
-    but->Move(25, 242);
+    but->MoveResize(25, 242, 100, 25);
     but->SetToolTipText("Move telescope to a Zd/Az position and start tracking.");
     but->Associate(this);
@@ -518,6 +502,5 @@
 
     but= new TGTextButton(tf2, "Calc Zd/Az",  kPB_CALCALTAZ);
-    but->Resize(80, 25);
-    but->Move(165, 197);
+    but->MoveResize(165, 197, 80, 25);
     but->SetToolTipText("Calculate Zd/Az corresponding to Ra/Dec.");
     but->Associate(this);
@@ -525,7 +508,12 @@
 
     but = new TGTextButton(tf4, "TPoint", kPB_TPOINT);
-    but->Resize(50, 25);
-    but->Move(176/*231*/, 213);
+    but->MoveResize(139, 213, 62, 25);
     but->SetToolTipText("Trigger writing a tpoint coordinate pair.");
+    but->Associate(this);
+    fList->Add(but);
+
+    but = new TGTextButton(tf4, "Endswitch", kPB_ENDSWITCH);
+    but->MoveResize(204, 213, 62, 25);
+    but->SetToolTipText("Print coordinates in 'Endswitch-Position' units.");
     but->Associate(this);
     fList->Add(but);
@@ -533,6 +521,5 @@
 #ifdef EXPERT
     but= new TGTextButton(tf1, "New Position",  kPB_SavePreDef);
-    but->Resize(80, 25);
-    but->Move(165, 197);
+    but->MoveResize(165, 197, 80, 25);
     but->SetToolTipText("Save new predefined position.");
     but->Associate(this);
@@ -540,6 +527,5 @@
 
     but= new TGTextButton(tf4, "New", kPB_SaveStar);
-    but->Resize(60, 23);
-    but->Move(211, 69);
+    but->MoveResize(211, 69, 60, 23);
     but->SetToolTipText("Save new Source position.");
     but->Associate(this);
@@ -547,6 +533,5 @@
 
     but = new TGTextButton(tf5, "Display", kPB_DISPLAY1);
-    but->Resize(80, 25);
-    but->Move(160, 197);
+    but->MoveResize(160, 197, 80, 25);
     but->SetToolTipText("Display Histogram.");
     but->Associate(this);
@@ -554,6 +539,5 @@
 
     but = new TGTextButton(tf6, "Display", kPB_DISPLAY2);
-    but->Resize(80, 25);
-    but->Move(160, 197);
+    but->MoveResize(160, 197, 80, 25);
     but->SetToolTipText("Display Histogram.");
     but->Associate(this);
@@ -561,6 +545,5 @@
 
     but = new TGTextButton(tf4, "Load", kPB_LoadBending);
-    but->Resize(50, 25);
-    but->Move(151, 185);
+    but->ResizeMove(151, 185, 50, 25);
     but->SetToolTipText("Load bending corrections from file 'bending.txt'");
     but->Associate(this);
@@ -568,6 +551,5 @@
 
     but = new TGTextButton(tf4, "Reset", kPB_ResetBending);
-    but->Resize(50, 25);
-    but->Move(206, 185);
+    but->MoveResize(206, 185, 50, 25);
     but->SetToolTipText("Reset bending correction (coefficients=0)");
     but->Associate(this);
@@ -575,24 +557,20 @@
 
     but= new TGTextButton(tf4, "Zd -",  kPB_ZDm);
-    but->Resize(50, 25);
-    but->Move(25, 210);
+    but->MoveResize(25, 210, 50, 25);
     but->SetToolTipText("Zenith Distance -= 1SE");
     but->Associate(this);
     fList->Add(but);
     but= new TGTextButton(tf4, "Zd +",  kPB_ZDp);
-    but->Resize(50, 25);
-    but->Move(90, 210);
+    but->MoveResize(90, 210, 50, 25);
     but->SetToolTipText("Zenith Distance += 1SE");
     but->Associate(this);
     fList->Add(but);
     but= new TGTextButton(tf4, "Az +",  kPB_AZp);
-    but->Resize(50, 25);
-    but->Move(55, 185);
+    but->MoveResize(55, 185, 50, 25);
     but->SetToolTipText("Azimuth += 1SE");
     but->Associate(this);
     fList->Add(but);
     but= new TGTextButton(tf4, "Az -",  kPB_AZm);
-    but->Resize(50, 25);
-    but->Move(55, 235);
+    but->MoveResize(55, 235, 50, 25);
     but->SetToolTipText("Azimuth -= 1SE");
     but->Associate(this);
@@ -605,6 +583,5 @@
     gClient->GetColorByName("Green", color);
     but->SetBackgroundColor(color);
-    but->Move(147, 295);
-    but->Resize(62, 25);
+    but->MoveResize(147, 295, 62, 25);
     but->SetToolTipText("Start a telescope movement.");
     fList->Add(but);
@@ -614,6 +591,5 @@
     gClient->GetColorByName("Red", color);
     but->SetBackgroundColor(color);
-    but->Move(212, 295);
-    but->Resize(62, 25);
+    but->MoveResize(212, 295, 62, 25);
     but->SetToolTipText("Stop any movement of telescope.");
     fList->Add(but);
@@ -989,6 +965,4 @@
 void MGCosy::UpdateZdAz(ZdAz &soll)
 {
-    soll *= kRad2Deg;
-
     static Int_t zd=~0;
     static Int_t az=~0;
@@ -996,10 +970,16 @@
     char text[21];
 
-    ZdAz test = soll*600;
-
+    UShort_t z, a;
+    Double_t zm, am;
+    Char_t   sz, sa;
+
+    Slalib::Rad2Dm(soll.Zd(), sz, z, zm);
+    Slalib::Rad2Dm(soll.Az(), sa, a, am);
+
+    const ZdAz test = soll*kRad2Deg*600;
     if (zd!=(int)test.Zd())
     {
         zd = (int)test.Zd();
-        sprintf(text, "%c%dd %.1fm", soll.Zd()<0?'-':'+', abs((int)soll.Zd()), 0.1*(abs((int)test.Zd())%600));
+        sprintf(text, "%c%dd %.1fm", sz, z, zm);
         fZdSoll->SetText(new TGString(text));
     }
@@ -1007,5 +987,5 @@
     {
         az = (int)test.Az();
-        sprintf(text, "%c%dd %.1fm", soll.Az()<0?'-':'+' , abs((int)soll.Az()), 0.1*(abs((int)test.Az())%600));
+        sprintf(text, "%c%dd %.1fm", sa, a, am);
         fAzSoll->SetText(new TGString(text));
     }
@@ -1113,5 +1093,5 @@
     // TGMainFrame::CloseWindow();
     cout << "Closing window - waiting until all nodes are stopped." << endl;
-    fQueue->PostMsg(WM_QUIT, 0, 0);
+    fQueue->PostMsg(WM_QUIT);
     cout << "Closing window - done." << endl;
     // gApplication->Terminate(0);
@@ -1376,9 +1356,9 @@
                 StopDemo();
 #endif
-                fQueue->PostMsg(WM_STOP, 0, 0);
+                fQueue->PostMsg(WM_STOP);
                 if (fTab->GetCurrent()==3)
-                    fQueue->Proc(WM_TESTSE, NULL);
+                    fQueue->Proc(WM_TESTSE);
                 if (fTab->GetCurrent()==4)
-                    fQueue->Proc(WM_GEAR, NULL);
+                    fQueue->Proc(WM_GEAR);
                 cout << "PostMsg (WM_Stop) returned." << endl;
                 return kTRUE;
@@ -1458,4 +1438,8 @@
                 StartTPoint();
                 return kTRUE;
+
+            case kPB_ENDSWITCH:
+                fQueue->Proc(WM_ENDSWITCH);
+                return kTRUE;
                 /*
             case kPB_CALIBSE:
@@ -1464,8 +1448,8 @@
                 */
             case kPB_LoadBending:
-                fQueue->Proc(WM_LOADBENDING, NULL);
+                fQueue->Proc(WM_LOADBENDING);
                 return kTRUE;
             case kPB_ResetBending:
-                fQueue->Proc(WM_RESETBENDING, NULL);
+                fQueue->Proc(WM_RESETBENDING);
                 return kTRUE;
                 /*
@@ -1479,5 +1463,5 @@
             case kPB_DISPLAY1:
             case kPB_DISPLAY2:
-                fQueue->PostMsg(WM_DISPLAY, 0, 0);
+                fQueue->PostMsg(WM_DISPLAY);
                 return kTRUE;
 
@@ -1493,5 +1477,5 @@
             case IDM_EXIT:
                 cout << "IDM_EXIT: Posting WM_QUIT." << endl;
-                fQueue->PostMsg(WM_QUIT, 0, 0);
+                fQueue->PostMsg(WM_QUIT);
                 cout << "IDM_EXIT: WM_QUIT done." << endl;
                 //cout << "Idm_Exit." << endl;
Index: trunk/MagicSoft/Cosy/gui/MGImage.cc
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGImage.cc	(revision 2514)
+++ trunk/MagicSoft/Cosy/gui/MGImage.cc	(revision 2518)
@@ -9,15 +9,12 @@
 #include "MGImage.h"
 
-#include <iostream.h>
-#include <pthread.h>
-
-#include <X11/Xlib.h>
-
-#include <TTimer.h>
-#include <TSystem.h>
-#include <TVirtualX.h>
+#include <iostream>
+
 #include <TGX11.h>
+#include <TMutex.h>
 
 ClassImp(MGImage);
+
+using namespace std;
 /*
 class MyX11 : public TGX11
@@ -41,6 +38,5 @@
     // Creat drawing semaphore
     //
-    fMuxPixmap = new pthread_mutex_t;
-    pthread_mutex_init((pthread_mutex_t*)fMuxPixmap, NULL);
+    fMuxPixmap = new TMutex;
 
     Resize(w, h);
@@ -58,5 +54,5 @@
 MGImage::~MGImage()
 {
-    pthread_mutex_lock((pthread_mutex_t*)fMuxPixmap);
+    fMuxPixmap->Lock();
 
     cout << "Deleting MGImage..." << endl;
@@ -66,5 +62,5 @@
     gVirtualX->DeleteImage((Drawable_t)fImage);
 
-    pthread_mutex_destroy((pthread_mutex_t*)fMuxPixmap);
+    delete fMuxPixmap;
 
     cout << "MGImage destroyed." << endl;
@@ -73,5 +69,5 @@
 void MGImage::DoRedraw()
 {
-    pthread_mutex_lock((pthread_mutex_t*)fMuxPixmap);
+    fMuxPixmap->Lock();
 
     if (TestBit(kNeedRedraw))
@@ -81,5 +77,5 @@
     }
 
-    pthread_mutex_unlock((pthread_mutex_t*)fMuxPixmap);
+    fMuxPixmap->UnLock();
 }
 
@@ -91,4 +87,5 @@
     while (s<e)
     {
+        //      11111100    11111000      11111100
         *d++ = (*s&0xfc) | (*s&0xf8)<<5 | (*s&0xfc)<<11;
         s++;
@@ -107,4 +104,52 @@
         *d++ = *s++;
         d++;
+    }
+}
+
+void MGImage::DrawImg(const byte *buffer)
+{
+    if (fMuxPixmap->TryLock()==13)
+        return;
+
+    switch (gVirtualX->GetDepth())
+    {
+    case 8:
+        memcpy(fImage->data, buffer, fWidth*fHeight);
+        break;
+    case 16:
+        DrawImg16((unsigned short*)fImage->data, (char*)buffer, (char*)(buffer+fWidth*fHeight));
+        break;
+    case 24:
+        DrawImg24(fImage->data, (char*)buffer, (char*)(buffer+fWidth*fHeight));
+        break;
+    default:
+        cout << "Sorry, " << gVirtualX->GetDepth() << "bit color depth not yet implemented." << endl;
+    }
+
+    SetBit(kNeedRedraw);
+
+    fMuxPixmap->UnLock();
+}
+
+void MGImage::DrawColImg16(unsigned short *d, char *s1, char *s2, char *e)
+{
+    // d=destination, s1=source1, s2=source2, e=end
+    // d:  rrrrrggg gggbbbbb
+    // s2:          00rrggbb
+    //
+    while (s1<e)
+    {
+        if (*s2)
+        {    
+            //      00000011   00001100        00110000
+            *d++ = (*s2&0x3) | (*s2&0xb)<<3 | (*s2&0x30)<<7;
+            s1++;
+        }
+        else
+        {
+            //      11111100     11111000        11111100
+            *d++ = (*s1&0xfc) | (*s1&0xf8)<<5 | (*s1&0xfc)<<11;
+            s2++;
+        }
     }
 }
@@ -134,32 +179,7 @@
 }
 
-void MGImage::DrawImg(const byte *buffer)
-{
-    if (pthread_mutex_trylock((pthread_mutex_t*)fMuxPixmap))
-        return;
-
-    switch (gVirtualX->GetDepth())
-    {
-    case 8:
-        memcpy(fImage->data, buffer, fWidth*fHeight);
-        break;
-    case 16:
-        DrawImg16((unsigned short*)fImage->data, (char*)buffer, (char*)(buffer+fWidth*fHeight));
-        break;
-    case 24:
-        DrawImg24(fImage->data, (char*)buffer, (char*)(buffer+fWidth*fHeight));
-        break;
-    default:
-        cout << "Sorry, " << gVirtualX->GetDepth() << "bit color depth not yet implemented." << endl;
-    }
-
-    SetBit(kNeedRedraw);
-
-    pthread_mutex_unlock((pthread_mutex_t*)fMuxPixmap);
-}
-
 void MGImage::DrawColImg(const byte *gbuf, const byte *cbuf)
 {
-    if (pthread_mutex_trylock((pthread_mutex_t*)fMuxPixmap))
+    if (fMuxPixmap->TryLock()==13)
         return;
 
@@ -179,6 +199,9 @@
     switch (gVirtualX->GetDepth())
     {
+    case 16:
+        DrawColImg16((unsigned short*)fImage->data, (char*)gbuf, (char*)cbuf, (char*)(gbuf+fWidth*fHeight));
+        break;
     case 24:
-        DrawColImg32(fImage->data, (char*)gbuf, (char*)cbuf, (char*)(gbuf+fWidth*fHeight));
+        DrawColImg24(fImage->data, (char*)gbuf, (char*)cbuf, (char*)(gbuf+fWidth*fHeight));
         break;
     default:
@@ -188,4 +211,4 @@
     SetBit(kNeedRedraw);
 
-    pthread_mutex_unlock((pthread_mutex_t*)fMuxPixmap);
-}
+    fMuxPixmap->UnLock();
+}
Index: trunk/MagicSoft/Cosy/gui/MGImage.h
===================================================================
--- trunk/MagicSoft/Cosy/gui/MGImage.h	(revision 2514)
+++ trunk/MagicSoft/Cosy/gui/MGImage.h	(revision 2518)
@@ -15,5 +15,5 @@
 #endif
 
-class TTimer;
+class TMutex;
 
 typedef unsigned char byte;
@@ -29,7 +29,5 @@
     UInt_t fHeight;
 
-    void *fMuxPixmap; //! test
-
-    TTimer *fTimer;
+    TMutex *fMuxPixmap; //! test
 
     enum { kNeedRedraw = BIT(17) };
@@ -37,4 +35,5 @@
     void DrawImg16(unsigned short *d, char *s, char *e);
     void DrawImg24(char *d, char *s, char *e);
+    void DrawColImg16(unsigned short *d, char *s1, char *s2, char *e);
     void DrawColImg24(char *d, char *s1, char *s2, char *e);
 
