forked from indilib/indi
/
lx200_OnStep.cpp
4700 lines (4213 loc) · 161 KB
/
lx200_OnStep.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
LX200 LX200_OnStep
Based on LX200 classic, (alain@zwingelstein.org)
Contributors:
James Lan https://github.com/james-lan
Ray Wells https://github.com/blueshawk
Copyright (C) 2003 Jasem Mutlaq (mutlaqja@ikarustech.com)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
//#define DEBUG_TRACKSTATE
#include "lx200_OnStep.h"
#include <mutex>
#define LIBRARY_TAB "Library"
#define FIRMWARE_TAB "Firmware data"
#define STATUS_TAB "ONStep Status"
#define PEC_TAB "PEC"
#define ALIGN_TAB "Align"
#define OUTPUT_TAB "Outputs"
#define ENVIRONMENT_TAB "Weather"
#define ROTATOR_TAB "Rotator"
#define ONSTEP_TIMEOUT 1
#define ONSTEP_TIMEOUT_SECONDS 0
#define ONSTEP_TIMEOUT_MICROSECONDS 100000
#define RA_AXIS 0
#define DEC_AXIS 1
extern std::mutex lx200CommsLock;
LX200_OnStep::LX200_OnStep() : LX200Generic(), WI(this), RotatorInterface(this)
{
currentCatalog = LX200_STAR_C;
currentSubCatalog = 0;
setVersion(1, 12); // don't forget to update libindi/drivers.xml
setLX200Capability(LX200_HAS_TRACKING_FREQ | LX200_HAS_SITES | LX200_HAS_ALIGNMENT_TYPE | LX200_HAS_PULSE_GUIDING |
LX200_HAS_PRECISE_TRACKING_FREQ);
SetTelescopeCapability(GetTelescopeCapability() | TELESCOPE_CAN_CONTROL_TRACK |
TELESCOPE_HAS_TRACK_RATE, 10 );
//CAN_ABORT, CAN_GOTO ,CAN_PARK ,CAN_SYNC ,HAS_LOCATION ,HAS_TIME ,HAS_TRACK_MODE Already inherited from lx200generic,
// 4 stands for the number of Slewrate Buttons as defined in Inditelescope.cpp
//setLX200Capability(LX200_HAS_FOCUS | LX200_HAS_TRACKING_FREQ | LX200_HAS_ALIGNMENT_TYPE | LX200_HAS_SITES | LX200_HAS_PULSE_GUIDING);
//
// Get generic capabilities but discard the followng:
// LX200_HAS_FOCUS
FI::SetCapability(FOCUSER_CAN_ABS_MOVE | FOCUSER_CAN_REL_MOVE | FOCUSER_CAN_ABORT);
// Unused option: FOCUSER_HAS_VARIABLE_SPEED
RI::SetCapability(ROTATOR_CAN_ABORT | ROTATOR_CAN_HOME | ROTATOR_HAS_BACKLASH);
// /*{
// ROTATOR_CAN_ABORT = 1 << 0, /*!< Can the Rotator abort motion once started? */
// ROTATOR_CAN_HOME = 1 << 1, /*!< Can the Rotator go to home position? */
// ROTATOR_CAN_SYNC = 1 << 2, /*!< Can the Rotator sync to specific tick? */ /*Not supported */
// ROTATOR_CAN_REVERSE = 1 << 3, /*!< Can the Rotator reverse direction? */ //It CAN reverse, but there's no way to query the direction
// ROTATOR_HAS_BACKLASH = 1 << 4 /*!< Can the Rotatorer compensate for backlash? */
// //}*/
}
const char *LX200_OnStep::getDefaultName()
{
return "LX200 OnStep";
}
bool LX200_OnStep::initProperties()
{
LX200Generic::initProperties();
FI::initProperties(FOCUS_TAB);
WI::initProperties(ENVIRONMENT_TAB, ENVIRONMENT_TAB);
RI::initProperties(ROTATOR_TAB);
SetParkDataType(PARK_RA_DEC);
//FocuserInterface
//Initial, these will be updated later.
FocusRelPosN[0].min = 0.;
FocusRelPosN[0].max = 30000.;
FocusRelPosN[0].value = 0;
FocusRelPosN[0].step = 10;
FocusAbsPosN[0].min = 0.;
FocusAbsPosN[0].max = 60000.;
FocusAbsPosN[0].value = 0;
FocusAbsPosN[0].step = 10;
// ============== MAIN_CONTROL_TAB
IUFillSwitch(&ReticS[0], "PLUS", "Light", ISS_OFF);
IUFillSwitch(&ReticS[1], "MOINS", "Dark", ISS_OFF);
IUFillSwitchVector(&ReticSP, ReticS, 2, getDeviceName(), "RETICULE_BRIGHTNESS", "Reticule +/-", MAIN_CONTROL_TAB, IP_RW,
ISR_ATMOST1, 60, IPS_IDLE);
IUFillNumber(&ElevationLimitN[0], "minAlt", "Elev Min", "%+03f", -90.0, 90.0, 1.0, -30.0);
IUFillNumber(&ElevationLimitN[1], "maxAlt", "Elev Max", "%+03f", -90.0, 90.0, 1.0, 89.0);
IUFillNumberVector(&ElevationLimitNP, ElevationLimitN, 2, getDeviceName(), "Slew elevation Limit", "", MAIN_CONTROL_TAB,
IP_RW, 0, IPS_IDLE);
IUFillText(&ObjectInfoT[0], "Info", "", "");
IUFillTextVector(&ObjectInfoTP, ObjectInfoT, 1, getDeviceName(), "Object Info", "", MAIN_CONTROL_TAB, IP_RO, 0, IPS_IDLE);
// ============== CONNECTION_TAB
// ============== OPTION_TAB
// ============== MOTION_CONTROL_TAB
//Override the standard slew rate command. Also add appropriate description. This also makes it work in Ekos Mount Control correctly
//Note that SlewRateSP and MaxSlewRateNP BOTH track the rate. I have left them in there because MaxRateNP reports OnStep Values
uint8_t nSlewRate = 10;
free(SlewRateS);
SlewRateS = (ISwitch *)malloc(sizeof(ISwitch) * nSlewRate);
// 0=.25X 1=.5x 2=1x 3=2x 4=4x 5=8x 6=24x 7=48x 8=half-MaxRate 9=MaxRate
IUFillSwitch(&SlewRateS[0], "0", "0.25x", ISS_OFF);
IUFillSwitch(&SlewRateS[1], "1", "0.5x", ISS_OFF);
IUFillSwitch(&SlewRateS[2], "2", "1x", ISS_OFF);
IUFillSwitch(&SlewRateS[3], "3", "2x", ISS_OFF);
IUFillSwitch(&SlewRateS[4], "4", "4x", ISS_OFF);
IUFillSwitch(&SlewRateS[5], "5", "8x", ISS_ON);
IUFillSwitch(&SlewRateS[6], "6", "24x", ISS_OFF);
IUFillSwitch(&SlewRateS[7], "7", "48x", ISS_OFF);
IUFillSwitch(&SlewRateS[8], "8", "Half-Max", ISS_OFF);
IUFillSwitch(&SlewRateS[9], "9", "Max", ISS_OFF);
IUFillSwitchVector(&SlewRateSP, SlewRateS, nSlewRate, getDeviceName(), "TELESCOPE_SLEW_RATE", "Slew Rate", MOTION_TAB,
IP_RW, ISR_1OFMANY, 0, IPS_IDLE);
IUFillNumber(&MaxSlewRateN[0], "maxSlew", "Rate", "%f", 0.0, 9.0, 1.0, 5.0); //2.0, 9.0, 1.0, 9.0
IUFillNumberVector(&MaxSlewRateNP, MaxSlewRateN, 1, getDeviceName(), "Max slew Rate", "", MOTION_TAB, IP_RW, 0, IPS_IDLE);
IUFillSwitch(&TrackCompS[0], "1", "Full Compensation", ISS_OFF);
IUFillSwitch(&TrackCompS[1], "2", "Refraction", ISS_OFF);
IUFillSwitch(&TrackCompS[2], "3", "Off", ISS_ON);
IUFillSwitchVector(&TrackCompSP, TrackCompS, 3, getDeviceName(), "Compensation", "Compensation Tracking", MOTION_TAB, IP_RW,
ISR_1OFMANY, 0, IPS_IDLE);
IUFillSwitch(&TrackAxisS[0], "1", "Single Axis", ISS_OFF);
IUFillSwitch(&TrackAxisS[1], "2", "Dual Axis", ISS_OFF);
IUFillSwitchVector(&TrackAxisSP, TrackAxisS, 2, getDeviceName(), "Multi-Axis", "Multi-Axis Tracking", MOTION_TAB, IP_RW,
ISR_1OFMANY, 0, IPS_IDLE);
IUFillSwitch(&TrackAxisS[0], "1", "Single Axis", ISS_OFF);
IUFillSwitch(&TrackAxisS[1], "2", "Dual Axis", ISS_OFF);
IUFillSwitchVector(&TrackAxisSP, TrackAxisS, 2, getDeviceName(), "Multi-Axis", "Multi-Axis Tracking", MOTION_TAB, IP_RW,
ISR_1OFMANY, 0, IPS_IDLE);
IUFillNumber(&BacklashN[0], "Backlash DEC", "DE", "%g", 0, 3600, 1, 15);
IUFillNumber(&BacklashN[1], "Backlash RA", "RA", "%g", 0, 3600, 1, 15);
IUFillNumberVector(&BacklashNP, BacklashN, 2, getDeviceName(), "Backlash", "", MOTION_TAB, IP_RW, 0, IPS_IDLE);
IUFillNumber(&GuideRateN[RA_AXIS], "GUIDE_RATE_WE", "W/E Rate", "%g", 0, 1, 0.25, 0.5);
IUFillNumber(&GuideRateN[DEC_AXIS], "GUIDE_RATE_NS", "N/S Rate", "%g", 0, 1, 0.25, 0.5);
IUFillNumberVector(&GuideRateNP, GuideRateN, 2, getDeviceName(), "GUIDE_RATE", "Guiding Rate", MOTION_TAB, IP_RO, 0,
IPS_IDLE);
IUFillSwitch(&AutoFlipS[0], "1", "AutoFlip: OFF", ISS_OFF);
IUFillSwitch(&AutoFlipS[1], "2", "AutoFlip: ON", ISS_OFF);
IUFillSwitchVector(&AutoFlipSP, AutoFlipS, 2, getDeviceName(), "AutoFlip", "Meridian Auto Flip", MOTION_TAB, IP_RW,
ISR_1OFMANY, 0, IPS_IDLE);
IUFillSwitch(&HomePauseS[0], "1", "HomePause: OFF", ISS_OFF);
IUFillSwitch(&HomePauseS[1], "2", "HomePause: ON", ISS_OFF);
IUFillSwitch(&HomePauseS[2], "3", "HomePause: Continue", ISS_OFF);
IUFillSwitchVector(&HomePauseSP, HomePauseS, 3, getDeviceName(), "HomePause", "Pause at Home", MOTION_TAB, IP_RW,
ISR_1OFMANY, 0, IPS_IDLE);
IUFillSwitch(&FrequencyAdjustS[0], "1", "Frequency -", ISS_OFF);
IUFillSwitch(&FrequencyAdjustS[1], "2", "Frequency +", ISS_OFF);
IUFillSwitch(&FrequencyAdjustS[2], "3", "Reset Sidereal Frequency", ISS_OFF);
IUFillSwitchVector(&FrequencyAdjustSP, FrequencyAdjustS, 3, getDeviceName(), "FrequencyAdjust", "Frequency Adjust",
MOTION_TAB, IP_RW, ISR_1OFMANY, 0, IPS_IDLE);
IUFillSwitch(&PreferredPierSideS[0], "1", "West", ISS_OFF);
IUFillSwitch(&PreferredPierSideS[1], "2", "East", ISS_OFF);
IUFillSwitch(&PreferredPierSideS[2], "3", "Best", ISS_OFF);
IUFillSwitchVector(&PreferredPierSideSP, PreferredPierSideS, 3, getDeviceName(), "Preferred Pier Side",
"Preferred Pier Side", MOTION_TAB, IP_RW, ISR_1OFMANY, 0, IPS_IDLE);
IUFillNumber(&minutesPastMeridianN[0], "East", "East", "%g", 0, 180, 1, 30);
IUFillNumber(&minutesPastMeridianN[1], "West", "West", "%g", 0, 180, 1, 30);
IUFillNumberVector(&minutesPastMeridianNP, minutesPastMeridianN, 2, getDeviceName(), "Minutes Past Meridian",
"Minutes Past Meridian", MOTION_TAB, IP_RW, 0, IPS_IDLE);
// ============== SITE_MANAGEMENT_TAB
IUFillSwitch(&SetHomeS[0], "RETURN_HOME", "Return Home", ISS_OFF);
IUFillSwitch(&SetHomeS[1], "AT_HOME", "At Home (Reset)", ISS_OFF);
IUFillSwitchVector(&SetHomeSP, SetHomeS, 2, getDeviceName(), "HOME_INIT", "Homing", SITE_TAB, IP_RW, ISR_ATMOST1, 60,
IPS_IDLE);
// ============== GUIDE_TAB
// ============== FOCUS_TAB
// Focuser 1
IUFillSwitch(&OSFocus1InitializeS[0], "Focus1_0", "Zero", ISS_OFF);
IUFillSwitch(&OSFocus1InitializeS[1], "Focus1_2", "Mid", ISS_OFF);
// IUFillSwitch(&OSFocus1InitializeS[2], "Focus1_3", "max", ISS_OFF);
IUFillSwitchVector(&OSFocus1InitializeSP, OSFocus1InitializeS, 2, getDeviceName(), "Foc1Rate", "Initialize", FOCUS_TAB,
IP_RW, ISR_ATMOST1, 0, IPS_IDLE);
IUFillSwitch(&OSFocusSelectS[0], "Focuser_Primary_1", "Focuser 1", ISS_ON);
IUFillSwitch(&OSFocusSelectS[1], "Focuser_Primary_2", "Focuser 2/Swap", ISS_OFF);
// For when OnStepX comes out
IUFillSwitch(&OSFocusSelectS[2], "Focuser_Primary_3", "3", ISS_OFF);
IUFillSwitch(&OSFocusSelectS[3], "Focuser_Primary_4", "4", ISS_OFF);
IUFillSwitch(&OSFocusSelectS[4], "Focuser_Primary_5", "5", ISS_OFF);
IUFillSwitch(&OSFocusSelectS[5], "Focuser_Primary_6", "6", ISS_OFF);
IUFillSwitch(&OSFocusSelectS[6], "Focuser_Primary_7", "7", ISS_OFF);
IUFillSwitch(&OSFocusSelectS[7], "Focuser_Primary_8", "8", ISS_OFF);
IUFillSwitch(&OSFocusSelectS[8], "Focuser_Primary_9", "9", ISS_OFF);
IUFillSwitch(&OSFocusSelectS[9], "Focuser_Primary_10", "10", ISS_OFF);
IUFillSwitchVector(&OSFocusSelectSP, OSFocusSelectS, 1, getDeviceName(), "OSFocusSWAP", "Primary Focuser", FOCUS_TAB,
IP_RW, ISR_ATMOST1, 0, IPS_IDLE);
// Focuser 2
//IUFillSwitch(&OSFocus2SelS[0], "Focus2_Sel1", "Foc 1", ISS_OFF);
//IUFillSwitch(&OSFocus2SelS[1], "Focus2_Sel2", "Foc 2", ISS_OFF);
//IUFillSwitchVector(&OSFocus2SelSP, OSFocus2SelS, 2, getDeviceName(), "Foc2Sel", "Foc 2", FOCUS_TAB, IP_RW, ISR_ATMOST1, 0, IPS_IDLE);
IUFillSwitch(&OSFocus2MotionS[0], "Focus2_In", "In", ISS_OFF);
IUFillSwitch(&OSFocus2MotionS[1], "Focus2_Out", "Out", ISS_OFF);
IUFillSwitch(&OSFocus2MotionS[2], "Focus2_Stop", "Stop", ISS_OFF);
IUFillSwitchVector(&OSFocus2MotionSP, OSFocus2MotionS, 3, getDeviceName(), "Foc2Mot", "Foc 2 Motion", FOCUS_TAB, IP_RW,
ISR_ATMOST1, 0, IPS_IDLE);
IUFillSwitch(&OSFocus2RateS[0], "Focus2_1", "min", ISS_OFF);
IUFillSwitch(&OSFocus2RateS[1], "Focus2_2", "0.01", ISS_OFF);
IUFillSwitch(&OSFocus2RateS[2], "Focus2_3", "0.1", ISS_OFF);
IUFillSwitch(&OSFocus2RateS[3], "Focus2_4", "1", ISS_OFF);
IUFillSwitchVector(&OSFocus2RateSP, OSFocus2RateS, 4, getDeviceName(), "Foc2Rate", "Foc 2 Rates", FOCUS_TAB, IP_RW,
ISR_ATMOST1, 0, IPS_IDLE);
IUFillNumber(&OSFocus2TargN[0], "FocusTarget2", "Abs Pos", "%g", -25000, 25000, 1, 0);
IUFillNumberVector(&OSFocus2TargNP, OSFocus2TargN, 1, getDeviceName(), "Foc2Targ", "Foc 2 Target", FOCUS_TAB, IP_RW, 0,
IPS_IDLE);
// =========== ROTATOR TAB
IUFillSwitch(&OSRotatorDerotateS[0], "Derotate_OFF", "OFF", ISS_OFF);
IUFillSwitch(&OSRotatorDerotateS[1], "Derotate_ON", "ON", ISS_OFF);
IUFillSwitchVector(&OSRotatorDerotateSP, OSRotatorDerotateS, 2, getDeviceName(), "Derotate_Status", "DEROTATE", ROTATOR_TAB,
IP_RW,
ISR_ATMOST1, 0, IPS_IDLE);
// ============== FIRMWARE_TAB
IUFillText(&VersionT[0], "Date", "", "");
IUFillText(&VersionT[1], "Time", "", "");
IUFillText(&VersionT[2], "Number", "", "");
IUFillText(&VersionT[3], "Name", "", "");
IUFillTextVector(&VersionTP, VersionT, 4, getDeviceName(), "Firmware Info", "", FIRMWARE_TAB, IP_RO, 0, IPS_IDLE);
//PEC Tab
IUFillSwitch(&OSPECStatusS[0], "OFF", "OFF", ISS_OFF);
IUFillSwitch(&OSPECStatusS[1], "Playing", "Playing", ISS_OFF);
IUFillSwitch(&OSPECStatusS[2], "Recording", "Recording", ISS_OFF);
IUFillSwitch(&OSPECStatusS[3], "Will Play", "Will Play", ISS_OFF);
IUFillSwitch(&OSPECStatusS[4], "Will Record", "Will Record", ISS_OFF);
IUFillSwitchVector(&OSPECStatusSP, OSPECStatusS, 5, getDeviceName(), "PEC Status", "PEC Status", PEC_TAB, IP_RO,
ISR_ATMOST1, 0, IPS_IDLE);
IUFillSwitch(&OSPECIndexS[0], "Not Detected", "Not Detected", ISS_ON);
IUFillSwitch(&OSPECIndexS[1], "Detected", "Detected", ISS_OFF);
IUFillSwitchVector(&OSPECIndexSP, OSPECIndexS, 2, getDeviceName(), "PEC Index Detect", "PEC Index", PEC_TAB, IP_RO,
ISR_ATMOST1, 0, IPS_IDLE);
IUFillSwitch(&OSPECRecordS[0], "Clear", "Clear", ISS_OFF);
IUFillSwitch(&OSPECRecordS[1], "Record", "Record", ISS_OFF);
IUFillSwitch(&OSPECRecordS[2], "Write to EEPROM", "Write to EEPROM", ISS_OFF);
IUFillSwitchVector(&OSPECRecordSP, OSPECRecordS, 3, getDeviceName(), "PEC Operations", "PEC Recording", PEC_TAB, IP_RW,
ISR_ATMOST1, 0, IPS_IDLE);
IUFillSwitch(&OSPECReadS[0], "Read", "Read PEC to FILE****", ISS_OFF);
IUFillSwitch(&OSPECReadS[1], "Write", "Write PEC from FILE***", ISS_OFF);
// IUFillSwitch(&OSPECReadS[2], "Write to EEPROM", "Write to EEPROM", ISS_OFF);
IUFillSwitchVector(&OSPECReadSP, OSPECReadS, 2, getDeviceName(), "PEC File", "PEC File", PEC_TAB, IP_RW, ISR_ATMOST1, 0,
IPS_IDLE);
// ============== New ALIGN_TAB
// Only supports Alpha versions currently (July 2018) Now Beta (Dec 2018)
IUFillSwitch(&OSNAlignStarsS[0], "1", "1 Star", ISS_OFF);
IUFillSwitch(&OSNAlignStarsS[1], "2", "2 Stars", ISS_OFF);
IUFillSwitch(&OSNAlignStarsS[2], "3", "3 Stars", ISS_ON);
IUFillSwitch(&OSNAlignStarsS[3], "4", "4 Stars", ISS_OFF);
IUFillSwitch(&OSNAlignStarsS[4], "5", "5 Stars", ISS_OFF);
IUFillSwitch(&OSNAlignStarsS[5], "6", "6 Stars", ISS_OFF);
IUFillSwitch(&OSNAlignStarsS[6], "7", "7 Stars", ISS_OFF);
IUFillSwitch(&OSNAlignStarsS[7], "8", "8 Stars", ISS_OFF);
IUFillSwitch(&OSNAlignStarsS[8], "9", "9 Stars", ISS_OFF);
IUFillSwitchVector(&OSNAlignStarsSP, OSNAlignStarsS, 9, getDeviceName(), "AlignStars", "Align using some stars, Alpha only",
ALIGN_TAB, IP_RW, ISR_ATMOST1, 0, IPS_IDLE);
IUFillSwitch(&OSNAlignS[0], "0", "Start Align", ISS_OFF);
IUFillSwitch(&OSNAlignS[1], "1", "Issue Align", ISS_OFF);
IUFillSwitch(&OSNAlignS[2], "3", "Write Align", ISS_OFF);
IUFillSwitchVector(&OSNAlignSP, OSNAlignS, 2, getDeviceName(), "NewAlignStar", "Align using up to 6 stars, Alpha only",
ALIGN_TAB, IP_RW, ISR_ATMOST1, 0, IPS_IDLE);
IUFillSwitch(&OSNAlignWriteS[0], "0", "Write Align to NVRAM/Flash", ISS_OFF);
IUFillSwitchVector(&OSNAlignWriteSP, OSNAlignWriteS, 1, getDeviceName(), "NewAlignStar2", "NVRAM", ALIGN_TAB, IP_RW,
ISR_ATMOST1, 0, IPS_IDLE);
IUFillSwitch(&OSNAlignPolarRealignS[0], "0", "Instructions", ISS_OFF);
IUFillSwitch(&OSNAlignPolarRealignS[1], "1", "Refine Polar Align (manually)", ISS_OFF);
IUFillSwitchVector(&OSNAlignPolarRealignSP, OSNAlignPolarRealignS, 2, getDeviceName(), "AlignMP",
"Polar Correction, See info box", ALIGN_TAB, IP_RW, ISR_ATMOST1, 0, IPS_IDLE);
IUFillText(&OSNAlignT[0], "0", "Align Process Status", "Align not started");
IUFillText(&OSNAlignT[1], "1", "1. Manual Process", "Point towards the NCP");
IUFillText(&OSNAlignT[2], "2", "2. Plate Solver Process", "Point towards the NCP");
IUFillText(&OSNAlignT[3], "3", "Manual Action after 1", "Press 'Start Align'");
IUFillText(&OSNAlignT[4], "4", "Current Status", "Not Updated");
IUFillText(&OSNAlignT[5], "5", "Max Stars", "Not Updated");
IUFillText(&OSNAlignT[6], "6", "Current Star", "Not Updated");
IUFillText(&OSNAlignT[7], "7", "# of Align Stars", "Not Updated");
IUFillTextVector(&OSNAlignTP, OSNAlignT, 8, getDeviceName(), "NAlign Process", "", ALIGN_TAB, IP_RO, 0, IPS_IDLE);
IUFillText(&OSNAlignErrT[0], "0", "EQ Polar Error Alt", "Available once Aligned");
IUFillText(&OSNAlignErrT[1], "1", "EQ Polar Error Az", "Available once Aligned");
// IUFillText(&OSNAlignErrT[2], "2", "2. Plate Solver Process", "Point towards the NCP");
// IUFillText(&OSNAlignErrT[3], "3", "After 1 or 2", "Press 'Start Align'");
// IUFillText(&OSNAlignErrT[4], "4", "Current Status", "Not Updated");
// IUFillText(&OSNAlignErrT[5], "5", "Max Stars", "Not Updated");
// IUFillText(&OSNAlignErrT[6], "6", "Current Star", "Not Updated");
// IUFillText(&OSNAlignErrT[7], "7", "# of Align Stars", "Not Updated");
IUFillTextVector(&OSNAlignErrTP, OSNAlignErrT, 2, getDeviceName(), "ErrAlign Process", "", ALIGN_TAB, IP_RO, 0, IPS_IDLE);
#ifdef ONSTEP_NOTDONE
// =============== OUTPUT_TAB
// ===============
IUFillSwitch(&OSOutput1S[0], "0", "OFF", ISS_ON);
IUFillSwitch(&OSOutput1S[1], "1", "ON", ISS_OFF);
IUFillSwitchVector(&OSOutput1SP, OSOutput1S, 2, getDeviceName(), "Output 1", "Output 1", OUTPUT_TAB, IP_RW, ISR_ATMOST1, 60,
IPS_ALERT);
IUFillSwitch(&OSOutput2S[0], "0", "OFF", ISS_ON);
IUFillSwitch(&OSOutput2S[1], "1", "ON", ISS_OFF);
IUFillSwitchVector(&OSOutput2SP, OSOutput2S, 2, getDeviceName(), "Output 2", "Output 2", OUTPUT_TAB, IP_RW, ISR_ATMOST1, 60,
IPS_ALERT);
#endif
for(int i = 0; i < PORTS_COUNT; i++)
{
char port_name[30];
snprintf(port_name, sizeof(port_name), "Output %d", i);
IUFillNumber(&OutputPorts[i], port_name, port_name, "%g", 0, 255, 1, 0);
}
IUFillNumberVector(&OutputPorts_NP, OutputPorts, PORTS_COUNT, getDeviceName(), "Outputs", "Outputs", OUTPUT_TAB, IP_WO, 60,
IPS_OK);
// ============== STATUS_TAB
IUFillText(&OnstepStat[0], ":GU# return", "", "");
IUFillText(&OnstepStat[1], "Tracking", "", "");
IUFillText(&OnstepStat[2], "Refractoring", "", "");
IUFillText(&OnstepStat[3], "Park", "", "");
IUFillText(&OnstepStat[4], "Pec", "", "");
IUFillText(&OnstepStat[5], "TimeSync", "", "");
IUFillText(&OnstepStat[6], "Mount Type", "", "");
IUFillText(&OnstepStat[7], "Error", "", "");
IUFillText(&OnstepStat[8], "Multi-Axis Tracking", "", "");
IUFillText(&OnstepStat[9], "TMC Axis1", "", "");
IUFillText(&OnstepStat[10], "TMC Axis2", "", "");
IUFillTextVector(&OnstepStatTP, OnstepStat, 11, getDeviceName(), "OnStep Status", "", STATUS_TAB, IP_RO, 0, IPS_OK);
// ============== WEATHER TAB
// Uses OnStep's defaults for this
IUFillNumber(&OSSetTemperatureN[0], "Set Temperature (C)", "C", "%4.2f", -100, 100, 1, 10);//-274, 999, 1, 10);
IUFillNumberVector(&OSSetTemperatureNP, OSSetTemperatureN, 1, getDeviceName(), "Set Temperature (C)", "", ENVIRONMENT_TAB,
IP_RW, 0, IPS_IDLE);
IUFillNumber(&OSSetHumidityN[0], "Set Relative Humidity (%)", "%", "%5.2f", 0, 100, 1, 70);
IUFillNumberVector(&OSSetHumidityNP, OSSetHumidityN, 1, getDeviceName(), "Set Relative Humidity (%)", "", ENVIRONMENT_TAB,
IP_RW, 0, IPS_IDLE);
IUFillNumber(&OSSetPressureN[0], "Set Pressure (hPa)", "hPa", "%4f", 500, 1500, 1, 1010);
IUFillNumberVector(&OSSetPressureNP, OSSetPressureN, 1, getDeviceName(), "Set Pressure (hPa)", "", ENVIRONMENT_TAB, IP_RW,
0, IPS_IDLE);
//Will eventually pull from the elevation in site settings
//TODO: Pull from elevation in site settings
IUFillNumber(&OSSetAltitudeN[0], "Set Altitude (m)", "m", "%4f", 0, 20000, 1, 110);
IUFillNumberVector(&OSSetAltitudeNP, OSSetAltitudeN, 1, getDeviceName(), "Set Altitude (m)", "", ENVIRONMENT_TAB, IP_RW, 0,
IPS_IDLE);
addParameter("WEATHER_TEMPERATURE", "Temperature (C)", -40, 85, 15);
addParameter("WEATHER_HUMIDITY", "Humidity %", 0, 100, 15);
addParameter("WEATHER_BAROMETER", "Pressure (hPa)", 0, 1500, 15);
addParameter("WEATHER_DEWPOINT", "Dew Point (C)", 0, 100, 15); // From OnStep
addParameter("WEATHER_CPU_TEMPERATURE", "OnStep CPU Temperature", -274, 200, -274); // From OnStep, -274 = unread
setCriticalParameter("WEATHER_TEMPERATURE");
addAuxControls();
setDriverInterface(getDriverInterface() | FOCUSER_INTERFACE | WEATHER_INTERFACE);
return true;
}
void LX200_OnStep::ISGetProperties(const char *dev)
{
if (dev != nullptr && strcmp(dev, getDeviceName()) != 0) return;
LX200Generic::ISGetProperties(dev);
}
bool LX200_OnStep::updateProperties()
{
LX200Generic::updateProperties();
//TODO: Properly setup Weather
WI::updateProperties();
if (isConnected())
{
// Firstinitialize some variables
// keep sorted by TABs is easier
// Main Control
defineProperty(&ReticSP);
defineProperty(&ElevationLimitNP);
defineProperty(&ObjectInfoTP);
// Connection
// Options
// OnStep Status
defineProperty(&OnstepStatTP);
// Motion Control
defineProperty(&MaxSlewRateNP);
defineProperty(&TrackCompSP);
defineProperty(&TrackAxisSP);
defineProperty(&BacklashNP);
defineProperty(&GuideRateNP);
defineProperty(&AutoFlipSP);
defineProperty(&HomePauseSP);
defineProperty(&FrequencyAdjustSP);
defineProperty(&PreferredPierSideSP);
defineProperty(&minutesPastMeridianNP);
// Site Management
defineProperty(&ParkOptionSP);
defineProperty(&SetHomeSP);
// Guide
// Focuser
// Focuser 1
OSNumFocusers = 0; //Reset before detection
if (!sendOnStepCommand(":FA#")) // do we have a Focuser 1
{
LOG_INFO("Focuser 1 found");
OSFocuser1 = true;
defineProperty(&OSFocus1InitializeSP);
OSNumFocusers = 1;
}
else
{
OSFocuser1 = false;
LOG_INFO("Focuser 1 NOT found");
}
// Focuser 2
if (!sendOnStepCommand(":fA#")) // Do we have a Focuser 2 (:fA# will only work for OnStep, not OnStepX)
{
LOG_INFO("Focuser 2 found");
OSFocuser2 = true;
OSNumFocusers = 2;
//defineProperty(&OSFocus2SelSP);
defineProperty(&OSFocus2MotionSP);
defineProperty(&OSFocus2RateSP);
defineProperty(&OSFocus2TargNP);
IUFillSwitchVector(&OSFocusSelectSP, OSFocusSelectS, OSNumFocusers, getDeviceName(), "OSFocusSWAP", "Primary Focuser",
FOCUS_TAB,
IP_RW, ISR_ATMOST1, 0, IPS_IDLE);
defineProperty(&OSFocusSelectSP); //Swap focusers (only matters if two focusers)
}
else //For OnStepX, up to 9 focusers
{
LOG_INFO("Focuser 2 NOT found (Checking for OnStepX Focusers)");
OSFocuser2 = false;
for (int i = 0; i < 9; i++)
{
char cmd[CMD_MAX_LEN] = {0};
char read_buffer[RB_MAX_LEN] = {0};
snprintf(cmd, sizeof(cmd), ":F%dA#", i + 1);
int fail_or_error = getCommandSingleCharResponse(PortFD, read_buffer, cmd);
if (!fail_or_error && read_buffer[0] == '1') // Do we have a Focuser X
{
LOGF_INFO("Focuser %i Found", i);
OSNumFocusers = i + 1;
}
else
{
if(fail_or_error < 0)
{
//Non detection = 0, Read errors < 0, stop
LOGF_INFO("Function call failed, stopping Focuser probe, return: %i", fail_or_error);
break;
}
}
}
if (OSNumFocusers > 1)
{
IUFillSwitchVector(&OSFocusSelectSP, OSFocusSelectS, OSNumFocusers, getDeviceName(), "OSFocusSWAP", "Primary Focuser",
FOCUS_TAB,
IP_RW, ISR_ATMOST1, 0, IPS_IDLE);
defineProperty(&OSFocusSelectSP);
}
}
if (OSNumFocusers == 0)
{
LOG_INFO("No Focusers found");
}
else
{
LOG_INFO("At least one focuser found, showing interface");
FI::updateProperties();
}
LOG_DEBUG("Focusers checked Variables:");
LOGF_DEBUG("OSFocuser1: %d, OSFocuser2: %d, OSNumFocusers: %i", OSFocuser1, OSFocuser2, OSNumFocusers);
//Rotation Information
if (!sendOnStepCommand(":rG#")) // do we have a Rotator 1
{
LOG_INFO("Rotator found.");
OSRotator1 = true;
RI::updateProperties();
defineProperty(&OSRotatorDerotateSP);
}
else
{
LOG_INFO("No Rotator found.");
OSRotator1 = false;
}
// Firmware Data
defineProperty(&VersionTP);
//PEC
//TODO: Define later when it might be supported
defineProperty(&OSPECStatusSP);
defineProperty(&OSPECIndexSP);
defineProperty(&OSPECRecordSP);
defineProperty(&OSPECReadSP);
defineProperty(&OSPECCurrentIndexNP);
defineProperty(&OSPECRWValuesNP);
//New Align
defineProperty(&OSNAlignStarsSP);
defineProperty(&OSNAlignSP);
defineProperty(&OSNAlignWriteSP);
defineProperty(&OSNAlignTP);
defineProperty(&OSNAlignErrTP);
defineProperty(&OSNAlignPolarRealignSP);
#ifdef ONSTEP_NOTDONE
//Outputs
defineProperty(&OSOutput1SP);
defineProperty(&OSOutput2SP);
#endif
Init_Outputs();
//Weather
defineProperty(&OSSetTemperatureNP);
defineProperty(&OSSetPressureNP);
defineProperty(&OSSetHumidityNP);
defineProperty(&OSSetAltitudeNP);
if (InitPark())
{
// If loading parking data is successful, we just set the default parking values.
SetAxis1ParkDefault(LocationN[LOCATION_LATITUDE].value >= 0 ? 0 : 180);
SetAxis2ParkDefault(LocationN[LOCATION_LATITUDE].value);
}
else
{
// Otherwise, we set all parking data to default in case no parking data is found.
SetAxis1Park(LocationN[LOCATION_LATITUDE].value >= 0 ? 0 : 180);
SetAxis1ParkDefault(LocationN[LOCATION_LATITUDE].value);
SetAxis1ParkDefault(LocationN[LOCATION_LATITUDE].value >= 0 ? 0 : 180);
SetAxis2ParkDefault(LocationN[LOCATION_LATITUDE].value);
}
double longitude = -1000, latitude = -1000;
// Get value from config file if it exists.
IUGetConfigNumber(getDeviceName(), "GEOGRAPHIC_COORD", "LONG", &longitude);
IUGetConfigNumber(getDeviceName(), "GEOGRAPHIC_COORD", "LAT", &latitude);
// if (longitude != -1000 && latitude != -1000)
// {
// updateLocation(latitude, longitude, 0);
// }
//NOTE: if updateProperties is called it clobbers this, so added here
IUFillSwitch(&SlewRateS[0], "0", "0.25x", ISS_OFF);
IUFillSwitch(&SlewRateS[1], "1", "0.5x", ISS_OFF);
IUFillSwitch(&SlewRateS[2], "2", "1x", ISS_OFF);
IUFillSwitch(&SlewRateS[3], "3", "2x", ISS_OFF);
IUFillSwitch(&SlewRateS[4], "4", "4x", ISS_OFF);
IUFillSwitch(&SlewRateS[5], "5", "8x", ISS_ON);
IUFillSwitch(&SlewRateS[6], "6", "24x", ISS_OFF);
IUFillSwitch(&SlewRateS[7], "7", "48x", ISS_OFF);
IUFillSwitch(&SlewRateS[8], "8", "Half-Max", ISS_OFF);
IUFillSwitch(&SlewRateS[9], "9", "Max", ISS_OFF);
}
else
{
// keep sorted by TABs is easier
// Main Control
deleteProperty(ReticSP.name);
deleteProperty(ElevationLimitNP.name);
// Connection
// Options
// Motion Control
deleteProperty(MaxSlewRateNP.name);
deleteProperty(TrackCompSP.name);
deleteProperty(TrackAxisSP.name);
deleteProperty(BacklashNP.name);
deleteProperty(GuideRateNP.name);
deleteProperty(AutoFlipSP.name);
deleteProperty(HomePauseSP.name);
deleteProperty(FrequencyAdjustSP.name);
deleteProperty(PreferredPierSideSP.name);
deleteProperty(minutesPastMeridianNP.name);
// Site Management
deleteProperty(ParkOptionSP.name);
deleteProperty(SetHomeSP.name);
// Guide
// Focuser
// Focuser 1
deleteProperty(OSFocus1InitializeSP.name);
// Focuser 2
//deleteProperty(OSFocus2SelSP.name);
deleteProperty(OSFocus2MotionSP.name);
deleteProperty(OSFocus2RateSP.name);
deleteProperty(OSFocus2TargNP.name);
deleteProperty(OSFocusSelectSP.name);
// Rotator
deleteProperty(OSRotatorDerotateSP.name);
// Firmware Data
deleteProperty(VersionTP.name);
//PEC
deleteProperty(OSPECStatusSP.name);
deleteProperty(OSPECIndexSP.name);
deleteProperty(OSPECRecordSP.name);
deleteProperty(OSPECReadSP.name);
deleteProperty(OSPECCurrentIndexNP.name);
deleteProperty(OSPECRWValuesNP.name);
//New Align
deleteProperty(OSNAlignStarsSP.name);
deleteProperty(OSNAlignSP.name);
deleteProperty(OSNAlignWriteSP.name);
deleteProperty(OSNAlignTP.name);
deleteProperty(OSNAlignErrTP.name);
deleteProperty(OSNAlignPolarRealignSP.name);
#ifdef ONSTEP_NOTDONE
//Outputs
deleteProperty(OSOutput1SP.name);
deleteProperty(OSOutput2SP.name);
#endif
deleteProperty(OutputPorts_NP.name);
// OnStep Status
deleteProperty(OnstepStatTP.name);
//Weather
deleteProperty(OSSetTemperatureNP.name);
deleteProperty(OSSetPressureNP.name);
deleteProperty(OSSetHumidityNP.name);
deleteProperty(OSSetAltitudeNP.name);
FI::updateProperties();
RI::updateProperties();
}
LOG_INFO("Initialization Complete");
return true;
}
bool LX200_OnStep::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
{
if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
{
if (strstr(name, "FOCUS_"))
return FI::processNumber(dev, name, values, names, n);
if (strstr(name, "ROTATOR_"))
return RI::processNumber(dev, name, values, names, n);
if (strcmp(name, "EQUATORIAL_EOD_COORD") == 0)
//Replace this from inditelescope so it doesn't change state
//Most of this needs to be handled by our updates, or it breaks things
{
// this is for us, and it is a goto
bool rc = false;
double ra = -1;
double dec = -100;
for (int x = 0; x < n; x++)
{
INumber *eqp = IUFindNumber(&EqNP, names[x]);
if (eqp == &EqN[AXIS_RA])
{
ra = values[x];
}
else if (eqp == &EqN[AXIS_DE])
{
dec = values[x];
}
}
if ((ra >= 0) && (ra <= 24) && (dec >= -90) && (dec <= 90))
{
// Check if it is already parked.
if (CanPark())
{
if (isParked())
{
LOG_DEBUG("Please unpark the mount before issuing any motion/sync commands.");
// EqNP.s = lastEqState = IPS_IDLE;
// IDSetNumber(&EqNP, nullptr);
return false;
}
}
// Check if it can sync
if (Telescope::CanSync())
{
ISwitch *sw;
sw = IUFindSwitch(&CoordSP, "SYNC");
if ((sw != nullptr) && (sw->s == ISS_ON))
{
rc = Sync(ra, dec);
// if (rc)
// EqNP.s = lastEqState = IPS_OK;
// else
// EqNP.s = lastEqState = IPS_ALERT;
// IDSetNumber(&EqNP, nullptr);
return rc;
}
}
// Remember Track State
// RememberTrackState = TrackState;
// Issue GOTO
rc = Goto(ra, dec);
if (rc)
{
// EqNP.s = lastEqState = IPS_BUSY;
// Now fill in target co-ords, so domes can start turning
TargetN[AXIS_RA].value = ra;
TargetN[AXIS_DE].value = dec;
IDSetNumber(&TargetNP, nullptr);
}
else
{
// EqNP.s = lastEqState = IPS_ALERT;
}
// IDSetNumber(&EqNP, nullptr);
}
return rc;
}
if (!strcmp(name, ObjectNoNP.name))
{
char object_name[256];
if (selectCatalogObject(PortFD, currentCatalog, (int)values[0]) < 0)
{
ObjectNoNP.s = IPS_ALERT;
IDSetNumber(&ObjectNoNP, "Failed to select catalog object.");
return false;
}
getLX200RA(PortFD, &targetRA);
getLX200DEC(PortFD, &targetDEC);
ObjectNoNP.s = IPS_OK;
IDSetNumber(&ObjectNoNP, "Object updated.");
if (getObjectInfo(PortFD, object_name) < 0)
IDMessage(getDeviceName(), "Getting object info failed.");
else
{
IUSaveText(&ObjectInfoTP.tp[0], object_name);
IDSetText(&ObjectInfoTP, nullptr);
}
Goto(targetRA, targetDEC);
return true;
}
if (!strcmp(name, MaxSlewRateNP.name))
{
int ret;
char cmd[CMD_MAX_LEN] = {0};
snprintf(cmd, 5, ":R%d#", (int)values[0]);
ret = sendOnStepCommandBlind(cmd);
//if (setMaxSlewRate(PortFD, (int)values[0]) < 0) //(int) MaxSlewRateN[0].value
if (ret == -1)
{
LOGF_DEBUG("Pas OK Return value =%d", ret);
LOGF_DEBUG("Setting Max Slew Rate to %f\n", values[0]);
MaxSlewRateNP.s = IPS_ALERT;
IDSetNumber(&MaxSlewRateNP, "Setting Max Slew Rate Failed");
return false;
}
LOGF_DEBUG("OK Return value =%d", ret);
MaxSlewRateNP.s = IPS_OK;
MaxSlewRateNP.np[0].value = values[0];
IDSetNumber(&MaxSlewRateNP, "Slewrate set to %04.1f", values[0]);
IUResetSwitch(&SlewRateSP);
SlewRateS[int(values[0])].s = ISS_ON;
SlewRateSP.s = IPS_OK;
IDSetSwitch(&SlewRateSP, nullptr);
return true;
}
if (!strcmp(name, BacklashNP.name))
{
//char cmd[CMD_MAX_LEN] = {0};
int i, nset;
double bklshdec = 0, bklshra = 0;
for (nset = i = 0; i < n; i++)
{
INumber *bktp = IUFindNumber(&BacklashNP, names[i]);
if (bktp == &BacklashN[0])
{
bklshdec = values[i];
LOGF_DEBUG("===CMD==> Backlash DEC= %f", bklshdec);
nset += bklshdec >= 0 && bklshdec <= 999; //range 0 to 999
}
else if (bktp == &BacklashN[1])
{
bklshra = values[i];
LOGF_DEBUG("===CMD==> Backlash RA= %f", bklshra);
nset += bklshra >= 0 && bklshra <= 999; //range 0 to 999
}
}
if (nset == 2)
{
char cmd[CMD_MAX_LEN] = {0};
snprintf(cmd, 9, ":$BD%d#", (int)bklshdec);
if (sendOnStepCommand(cmd))
{
BacklashNP.s = IPS_ALERT;
IDSetNumber(&BacklashNP, "Error Backlash DEC limit.");
}
const struct timespec timeout = {0, 100000000L};
nanosleep(&timeout, nullptr); // time for OnStep to respond to previous cmd
snprintf(cmd, 9, ":$BR%d#", (int)bklshra);
if (sendOnStepCommand(cmd))
{
BacklashNP.s = IPS_ALERT;
IDSetNumber(&BacklashNP, "Error Backlash RA limit.");
}
BacklashNP.np[0].value = bklshdec;
BacklashNP.np[1].value = bklshra;
BacklashNP.s = IPS_OK;
IDSetNumber(&BacklashNP, nullptr);
return true;
}
else
{
BacklashNP.s = IPS_ALERT;
IDSetNumber(&BacklashNP, "Backlash invalid.");
return false;
}
}
if (!strcmp(name, ElevationLimitNP.name))
{
// new elevation limits
double minAlt = 0, maxAlt = 0;
int i, nset;
for (nset = i = 0; i < n; i++)
{
INumber *altp = IUFindNumber(&ElevationLimitNP, names[i]);
if (altp == &ElevationLimitN[0])
{
minAlt = values[i];
nset += minAlt >= -30.0 && minAlt <= 30.0; //range -30 to 30
}
else if (altp == &ElevationLimitN[1])
{
maxAlt = values[i];
nset += maxAlt >= 60.0 && maxAlt <= 90.0; //range 60 to 90
}
}
if (nset == 2)
{
if (setMinElevationLimit(PortFD, (int)minAlt) < 0)
{
ElevationLimitNP.s = IPS_ALERT;
IDSetNumber(&ElevationLimitNP, "Error setting min elevation limit.");
}
if (setMaxElevationLimit(PortFD, (int)maxAlt) < 0)
{
ElevationLimitNP.s = IPS_ALERT;
IDSetNumber(&ElevationLimitNP, "Error setting max elevation limit.");
return false;
}
ElevationLimitNP.np[0].value = minAlt;
ElevationLimitNP.np[1].value = maxAlt;
ElevationLimitNP.s = IPS_OK;
IDSetNumber(&ElevationLimitNP, nullptr);
return true;
}
else
{
ElevationLimitNP.s = IPS_IDLE;
IDSetNumber(&ElevationLimitNP, "elevation limit missing or invalid.");
return false;
}
}
}
if (!strcmp(name, minutesPastMeridianNP.name))
{
//char cmd[CMD_MAX_LEN] ={0};
int i, nset;
double minPMEast = 0, minPMWest = 0;
for (nset = i = 0; i < n; i++)
{
INumber *bktp = IUFindNumber(&minutesPastMeridianNP, names[i]);
if (bktp == &minutesPastMeridianN[0])
{
minPMEast = values[i];
LOGF_DEBUG("===CMD==> minutesPastMeridianN[0]/East = %f", minPMEast);
nset += minPMEast >= 0 && minPMEast <= 180; //range 0 to 180
}
else if (bktp == &minutesPastMeridianN[1])
{
minPMWest = values[i];
LOGF_DEBUG("===CMD==> minutesPastMeridianN[1]/West= %f", minPMWest);
nset += minPMWest >= 0 && minPMWest <= 180; //range 0 to 180
}
}
if (nset == 2)
{
char cmd[CMD_MAX_LEN] = {0};
snprintf(cmd, 20, ":SXE9,%d#", (int) minPMEast);
if (sendOnStepCommand(cmd))
{
minutesPastMeridianNP.s = IPS_ALERT;
IDSetNumber(&minutesPastMeridianNP, "Error Backlash DEC limit.");
}
const struct timespec timeout = {0, 100000000L};
nanosleep(&timeout, nullptr); // time for OnStep to respond to previous cmd
snprintf(cmd, 20, ":SXEA,%d#", (int) minPMWest);
if (sendOnStepCommand(cmd))
{
minutesPastMeridianNP.s = IPS_ALERT;
IDSetNumber(&minutesPastMeridianNP, "Error Backlash RA limit.");
}
minutesPastMeridianNP.np[0].value = minPMEast;
minutesPastMeridianNP.np[1].value = minPMWest;
minutesPastMeridianNP.s = IPS_OK;
IDSetNumber(&minutesPastMeridianNP, nullptr);
return true;
}
else
{