1 /*
2 *  rotator.cpp
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 #include "phd.h"
36 
37 #include "gear_simulator.h"
38 #include "rotator_ascom.h"
39 
40 const float Rotator::POSITION_ERROR = -999.f;
41 const float Rotator::POSITION_UNKNOWN = -888.f;
42 
43 Rotator *pRotator;
44 
RotatorList()45 wxArrayString Rotator::RotatorList()
46 {
47     wxArrayString rotatorList;
48 
49     rotatorList.Add(_("None"));
50 #ifdef ROTATOR_ASCOM
51     wxArrayString ascomRotators = RotatorAscom::EnumAscomRotators();
52     for (unsigned int i = 0; i < ascomRotators.Count(); i++)
53         rotatorList.Add(ascomRotators[i]);
54 #endif
55 #ifdef ROTATOR_SIMULATOR
56     rotatorList.Add(_T("Simulator"));
57 #endif
58 
59     return rotatorList;
60 }
61 
Factory(const wxString & choice)62 Rotator *Rotator::Factory(const wxString& choice)
63 {
64     Rotator *rotator = 0;
65 
66     try
67     {
68         if (choice.IsEmpty())
69         {
70             throw ERROR_INFO("Rotator::Factory called with choice.IsEmpty()");
71         }
72 
73         Debug.AddLine(wxString::Format("RotatorFactory(%s)", choice));
74 
75         if (false) // so else ifs can follow
76         {
77         }
78 #ifdef ROTATOR_ASCOM
79         // do ascom first since it includes many choices, some of which match other choices below (like Simulator)
80         else if (choice.Find(_T("ASCOM")) != wxNOT_FOUND) {
81             rotator = new RotatorAscom(choice);
82         }
83 #endif
84         else if (choice.Find(_("None")) != wxNOT_FOUND) {
85         }
86 #ifdef ROTATOR_SIMULATOR
87         else if (choice.Find(_T("Simulator")) != wxNOT_FOUND) {
88             rotator = GearSimulator::MakeRotatorSimulator();
89         }
90 #endif
91         else {
92             throw ERROR_INFO("RotatorFactory: Unknown rotator choice");
93         }
94     }
95     catch (const wxString& msg)
96     {
97         POSSIBLY_UNUSED(msg);
98         if (rotator)
99         {
100             delete rotator;
101             rotator = 0;
102         }
103     }
104 
105     return rotator;
106 }
107 
Rotator()108 Rotator::Rotator()
109     : m_connected(false)
110 {
111     m_isReversed = pConfig->Profile.GetBoolean("/rotator/isReversed", false);
112     Debug.Write(wxString::Format("Rotator:ctor: isReversed = %d\n", m_isReversed));
113 }
114 
~Rotator()115 Rotator::~Rotator()
116 {
117 }
118 
Connect()119 bool Rotator::Connect()
120 {
121     m_connected = true;
122     return false;
123 }
124 
Disconnect()125 bool Rotator::Disconnect()
126 {
127     m_connected = false;
128     return false;
129 }
130 
IsConnected() const131 bool Rotator::IsConnected() const
132 {
133     return m_connected;
134 }
135 
ShowPropertyDialog()136 void Rotator::ShowPropertyDialog()
137 {
138 }
139 
SetReversed(bool val)140 void Rotator::SetReversed(bool val)
141 {
142     m_isReversed = val;
143     pConfig->Profile.SetBoolean("/rotator/isReversed", val);
144     Debug.Write(wxString::Format("Rotator:SetReversed: isReversed = %d\n", m_isReversed));
145 }
146 
RotatorConfigDialogPane(wxWindow * parent)147 RotatorConfigDialogPane::RotatorConfigDialogPane(wxWindow *parent)
148     : ConfigDialogPane(_("Rotator Settings"), parent)
149 {
150 
151 }
152 
LayoutControls(wxPanel * pParent,BrainCtrlIdMap & CtrlMap)153 void RotatorConfigDialogPane::LayoutControls(wxPanel *pParent, BrainCtrlIdMap& CtrlMap)
154 {
155     this->Add(GetSingleCtrl(CtrlMap, AD_cbRotatorReverse), wxSizerFlags(0).Border(wxALL, 10));
156     this->Layout();
157     Fit(m_pParent);
158 }
159 
GetConfigDialogPane(wxWindow * parent)160 ConfigDialogPane *Rotator::GetConfigDialogPane(wxWindow *parent)
161 {
162     return new RotatorConfigDialogPane(parent);
163 }
164 
GetConfigDlgCtrlSet(wxWindow * pParent,Rotator * pRotator,AdvancedDialog * pAdvancedDialog,BrainCtrlIdMap & CtrlMap)165 RotatorConfigDialogCtrlSet *Rotator::GetConfigDlgCtrlSet(wxWindow *pParent, Rotator *pRotator, AdvancedDialog *pAdvancedDialog, BrainCtrlIdMap& CtrlMap)
166 {
167     return new RotatorConfigDialogCtrlSet(pParent, pRotator, pAdvancedDialog, CtrlMap);
168 }
169 
RotatorConfigDialogCtrlSet(wxWindow * pParent,Rotator * pRotator,AdvancedDialog * pAdvancedDialog,BrainCtrlIdMap & CtrlMap)170 RotatorConfigDialogCtrlSet::RotatorConfigDialogCtrlSet(wxWindow *pParent, Rotator *pRotator, AdvancedDialog *pAdvancedDialog, BrainCtrlIdMap& CtrlMap)
171     : ConfigDialogCtrlSet(pParent, pAdvancedDialog, CtrlMap)
172 {
173     m_rotator = pRotator;
174     m_cbReverse = new wxCheckBox(GetParentWindow(AD_cbRotatorReverse), wxID_ANY, _("Reverse sign of angle"));
175     AddCtrl(CtrlMap, AD_cbRotatorReverse, m_cbReverse);
176 }
177 
LoadValues()178 void RotatorConfigDialogCtrlSet::LoadValues()
179 {
180     m_cbReverse->SetValue(m_rotator->IsReversed());
181 }
182 
UnloadValues()183 void RotatorConfigDialogCtrlSet::UnloadValues()
184 {
185     m_rotator->SetReversed(m_cbReverse->GetValue());
186 }
187