File indexing completed on 2024-04-28 03:43:05
0001 /* 0002 SPDX-FileCopyrightText: 2023 John Evans <john.e.evans.email@googlemail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "ui_buildfilteroffsets.h" 0010 #include "filtermanager.h" 0011 0012 namespace Ekos 0013 { 0014 0015 class BuildFilterOffsets : public QDialog, public Ui::buildOffsetsDialog 0016 { 0017 Q_OBJECT 0018 0019 public: 0020 0021 BuildFilterOffsets(QSharedPointer<FilterManager> filterManager); 0022 ~BuildFilterOffsets(); 0023 0024 // Used by build filter offsets utility to process the completion of an AF run. 0025 void autoFocusComplete(FocusState completionState, int currentPosition, double currentTemperature, double currentAlt); 0026 0027 signals: 0028 // Trigger Autofocus 0029 void runAutoFocus(bool buildOffsets); 0030 // User has elected to abort Autofocus, pass on signal to FilterManager 0031 void abortAutoFocus(); 0032 // New Focus offset requested 0033 void newFocusOffset(int value, bool useAbsoluteOffset); 0034 // Emitted when filter change completed including all required actions 0035 void ready(); 0036 0037 private slots: 0038 void itemChanged(QStandardItem *item); 0039 void refChanged(QModelIndex index); 0040 0041 private: 0042 0043 // BFOColID references the columns in the table 0044 typedef enum 0045 { 0046 BFO_FILTER = 0, 0047 BFO_OFFSET, 0048 BFO_LOCK, 0049 BFO_NUM_FOCUS_RUNS, 0050 BFO_AF_RUN_1, 0051 BFO_AVERAGE, 0052 BFO_NEW_OFFSET, 0053 BFO_SAVE_CHECK 0054 } BFOColID; 0055 0056 // BFOButtonState controls the states used when using the dialog 0057 typedef enum 0058 { 0059 BFO_INIT, 0060 BFO_RUN, 0061 BFO_SAVE, 0062 BFO_STOP 0063 } BFOButtonState; 0064 0065 // buildOffsetsQItem is used to queue items for processing 0066 typedef struct 0067 { 0068 QString color; 0069 bool changeFilter; 0070 int numAFRun; 0071 } buildOffsetsQItem; 0072 0073 // AFSolutionDetail is used to store data used to calculate adaptive focus position info 0074 typedef struct 0075 { 0076 int position; 0077 int adaptedPosition; 0078 double temperature; 0079 double deltaTemp; 0080 double altitude; 0081 double deltaAlt; 0082 double ticksPerTemp; 0083 double ticksPerAlt; 0084 double deltaTicksTemperature; 0085 double deltaTicksAltitude; 0086 double deltaTicksTotal; 0087 } AFSolutionDetail; 0088 0089 // Function to setup signal/slots in and out of Build Filter Offsets 0090 void setupConnections(); 0091 // Setup the dialog GUI 0092 void setupGUI(); 0093 // Function to initialise resources for the build filter offsers dialog 0094 void initBuildFilterOffsets(); 0095 // Setup the table widget 0096 void setupBuildFilterOffsetsTable(); 0097 // Set the buttons state 0098 void setBuildFilterOffsetsButtons(const BFOButtonState state); 0099 // Function to setup the work required to build the offsets 0100 void buildTheOffsets(); 0101 // Function to stop in-flight processing, e.g AF runs 0102 void stopProcessing(); 0103 // Function to persist the calculated filter offsets 0104 void saveTheOffsets(); 0105 // When all automated processing is complete allow some cells to be editable 0106 void setCellsEditable(); 0107 // Function to call Autofocus to build the filter offsets 0108 void runBuildOffsets(); 0109 // Function to process a filter change event 0110 void buildTheOffsetsTaskComplete(); 0111 // Resize the dialog 0112 void buildOffsetsDialogResize(); 0113 // Calculate the average of the AF runs 0114 void calculateAFAverage(const int row, const int col); 0115 // Calculate the new offset for the filter 0116 void calculateOffset(const int row); 0117 // Process the passed in Q item 0118 void processQItem(const buildOffsetsQItem qitem); 0119 // Process successful Autofocus data 0120 void processAFcomplete(const int position, const double temperature, const double altitude); 0121 // Load the AF position into the table. 0122 void loadPosition(const bool checked, const int row, const int col); 0123 // Reload all AF positions processed so far depending on setting of adaptFocus checkbox 0124 void reloadPositions(const bool checked); 0125 // Return the column for the passed in ID 0126 int getColumn(const BFOColID id); 0127 // Get the number of AF runs for the passed in row 0128 int getNumRuns(const int row); 0129 // Get the maximum number of AF runs 0130 int getMaxRuns(); 0131 0132 QStandardItemModel m_BFOModel; 0133 0134 QVector <QString> m_filters; 0135 int m_refFilter { -1 }; 0136 double m_refTemperature { INVALID_VALUE }; 0137 double m_refAltitude { INVALID_VALUE }; 0138 0139 QQueue<buildOffsetsQItem> m_buildOffsetsQ; 0140 buildOffsetsQItem m_qItemInProgress; 0141 0142 QSharedPointer<FilterManager> m_filterManager; 0143 0144 bool m_inBuildOffsets { false }; 0145 int m_rowIdx { 0 }; 0146 int m_colIdx { 0 }; 0147 QPushButton *m_runButton; 0148 QPushButton *m_stopButton; 0149 bool m_problemFlag { false }; 0150 bool m_stopFlag { false }; 0151 bool m_abortAFPending { false }; 0152 bool m_tableInEditMode {false}; 0153 QVector<AFSolutionDetail> m_AFSolutions; 0154 }; 0155 0156 }