1 /*
2 * rotator.h
3 * PHD Guiding
4 *
5 * Created by Andy Galasso
6 * Copyright (c) 2015 Andy Galasso
7 * All rights reserved.
8 *
9 * This source code is distributed under the following "BSD" license
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 * Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * Neither the name of Craig Stark, Stark Labs nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 *
33 */
34
35 #ifndef ROTATOR_INCLUDED
36 #define ROTATOR_INCLUDED
37
38 class Rotator;
39
40 class RotatorConfigDialogCtrlSet : ConfigDialogCtrlSet
41 {
42 Rotator *m_rotator;
43 wxCheckBox *m_cbReverse;
44
45 public:
46 RotatorConfigDialogCtrlSet(wxWindow *pParent, Rotator *pRotator, AdvancedDialog *pAdvancedDialog, BrainCtrlIdMap& CtrlMap);
~RotatorConfigDialogCtrlSet()47 virtual ~RotatorConfigDialogCtrlSet() {};
48 virtual void LoadValues();
49 virtual void UnloadValues();
50 };
51
52 class RotatorConfigDialogPane : public ConfigDialogPane
53 {
54 public:
55 RotatorConfigDialogPane(wxWindow *parent);
~RotatorConfigDialogPane()56 ~RotatorConfigDialogPane() {};
57
LoadValues()58 void LoadValues() {};
UnloadValues()59 void UnloadValues() {};
60 virtual void LayoutControls(wxPanel *pParent, BrainCtrlIdMap& CtrlMap);
61 };
62
63 class Rotator
64 {
65 bool m_connected;
66 bool m_isReversed;
67
68 public:
69
70 static const float POSITION_UNKNOWN;
71 static const float POSITION_ERROR;
72
73 static wxArrayString RotatorList();
74 static Rotator *Factory(const wxString& choice);
75
76 static double RotatorPosition();
77
78 Rotator();
79 virtual ~Rotator();
80
81 virtual bool Connect();
82 virtual bool Disconnect();
83 virtual bool IsConnected() const;
84
85 virtual ConfigDialogPane *GetConfigDialogPane(wxWindow *pParent);
86 RotatorConfigDialogCtrlSet *GetConfigDlgCtrlSet(wxWindow *pParent, Rotator *pRotator, AdvancedDialog *pAdvancedDialog, BrainCtrlIdMap& CtrlMap);
87 virtual void ShowPropertyDialog();
88
89 // get the display name of the rotator device
90 virtual wxString Name() const = 0;
91
92 // get the rotator position in degrees, or POSITION_ERROR in case of error
93 virtual float Position() const = 0;
94
95 bool IsReversed() const;
96 void SetReversed(bool val);
97 };
98
99 extern Rotator *pRotator;
100
RotatorPosition()101 inline double Rotator::RotatorPosition()
102 {
103 if (!pRotator || !pRotator->IsConnected())
104 return POSITION_UNKNOWN;
105 double pos = pRotator->Position();
106 return pRotator->IsReversed() ? -pos : pos;
107 }
108
IsReversed()109 inline bool Rotator::IsReversed() const
110 {
111 return m_isReversed;
112 }
113
114 #endif
115