Commit 01d26fd9 authored by Jasem Mutlaq's avatar Jasem Mutlaq

Add support to per-filter exposure time that is persistent

parent 485cc276
......@@ -155,6 +155,15 @@ bool KSUserDB::Initialize()
query.exec(columnQuery);
}
// If prior to 2.7.6 upgrade database to add column for filter exposure
if (currentDBVersion < "2.7.6")
{
QSqlQuery query(userdb_);
QString columnQuery = QString("ALTER TABLE filter ADD COLUMN Exposure TEXT DEFAULT '1'");
query.exec(columnQuery);
}
}
}
userdb_.close();
......@@ -236,7 +245,9 @@ bool KSUserDB::RebuildDB()
"Model TEXT DEFAULT NULL, "
"Type TEXT DEFAULT NULL, "
"Offset TEXT DEFAULT NULL, "
"Color TEXT DEFAULT NULL)");
"Color TEXT DEFAULT NULL),"
"Exposure TEXT DEFAULT '1')"
);
tables.append("CREATE TABLE wishlist ( "
"id INTEGER DEFAULT NULL PRIMARY KEY AUTOINCREMENT, "
......@@ -798,7 +809,7 @@ void KSUserDB::GetAllLenses(QList<OAL::Lens *> &lens_list)
* filter section
*/
void KSUserDB::AddFilter(const QString &vendor, const QString &model,
const QString &type, const QString &offset, const QString &color)
const QString &type, const QString &offset, const QString &color, const QString &exposure)
{
userdb_.open();
QSqlTableModel equip(0, userdb_);
......@@ -809,8 +820,9 @@ void KSUserDB::AddFilter(const QString &vendor, const QString &model,
equip.setData(equip.index(row, 1), vendor); // row,0 is autoincerement ID
equip.setData(equip.index(row, 2), model);
equip.setData(equip.index(row, 3), type);
equip.setData(equip.index(row, 4), color);
equip.setData(equip.index(row, 5), offset);
equip.setData(equip.index(row, 4), offset);
equip.setData(equip.index(row, 5), color);
equip.setData(equip.index(row, 6), exposure);
if (equip.submitAll() == false)
qCritical() << "AddFilter:" << equip.lastError();
......@@ -819,7 +831,7 @@ void KSUserDB::AddFilter(const QString &vendor, const QString &model,
}
void KSUserDB::AddFilter(const QString &vendor, const QString &model,
const QString &type, const QString &offset, const QString &color,
const QString &type, const QString &offset, const QString &color, const QString &exposure,
const QString &id)
{
userdb_.open();
......@@ -833,9 +845,10 @@ void KSUserDB::AddFilter(const QString &vendor, const QString &model,
QSqlRecord record = equip.record(0);
record.setValue(1, vendor);
record.setValue(2, model);
record.setValue(3, type);
record.setValue(4, color);
record.setValue(5, offset);
record.setValue(3, type);
record.setValue(4, offset);
record.setValue(5, color);
record.setValue(6, exposure);
equip.setRecord(0, record);
if (equip.submitAll() == false)
qCritical() << "AddFilter:" << equip.lastError();
......@@ -861,7 +874,8 @@ void KSUserDB::GetAllFilters(QList<OAL::Filter *> &filter_list)
QString type = record.value("Type").toString();
QString color = record.value("Color").toString();
QString offset = record.value("Offset").toString();
OAL::Filter * o= new OAL::Filter(id, model, vendor, type, offset, color);
QString exposure = record.value("Exposure").toString();
OAL::Filter * o= new OAL::Filter(id, model, vendor, type, offset, color, exposure);
filter_list.append(o);
}
......@@ -1206,7 +1220,7 @@ void KSUserDB::readLens()
void KSUserDB::readFilter()
{
QString model, vendor, type, offset, color;
QString model, vendor, type, offset, color, exposure;
while( ! reader_->atEnd() )
{
reader_->readNext();
......@@ -1236,9 +1250,13 @@ void KSUserDB::readFilter()
{
color = reader_->readElementText() ;
}
else if( reader_->name() == "exposure" )
{
exposure = reader_->readElementText() ;
}
}
}
AddFilter(vendor, model, type, offset, color );
AddFilter(vendor, model, type, offset, color, exposure);
}
QList<ArtificialHorizonEntity *> KSUserDB::GetAllHorizons()
......
......@@ -267,13 +267,13 @@ class KSUserDB
*
* @return void
**/
void AddFilter(const QString &vendor, const QString &model, const QString &type, const QString &offset, const QString &color);
void AddFilter(const QString &vendor, const QString &model, const QString &type, const QString &offset, const QString &color, const QString &exposure);
/**
* @brief Replace a filter at given ID with new content
*
* @return void
**/
void AddFilter(const QString &vendor, const QString &model, const QString &type, const QString &offset, const QString &color,
void AddFilter(const QString &vendor, const QString &model, const QString &type, const QString &offset, const QString &color, const QString &exposure,
const QString &id);
#ifndef KSTARS_LITE
/**
......
......@@ -4172,12 +4172,12 @@ void Capture::showFilterOffsetDialog()
// If no filter exists, let's create one
if (matchedFilter == NULL)
{
KStarsData::Instance()->userdb()->AddFilter(FilterCaptureCombo->currentText(), "", "", QString::number(oneOffset->offset), oneOffset->filter);
KStarsData::Instance()->userdb()->AddFilter(FilterCaptureCombo->currentText(), "", "", QString::number(oneOffset->offset), oneOffset->filter, "1");
}
// Or update Existing one
else
{
KStarsData::Instance()->userdb()->AddFilter(FilterCaptureCombo->currentText(), "", "", QString::number(oneOffset->offset), oneOffset->filter, matchedFilter->id());
KStarsData::Instance()->userdb()->AddFilter(FilterCaptureCombo->currentText(), "", "", QString::number(oneOffset->offset), oneOffset->filter, matchedFilter->exposure(), matchedFilter->id());
}
}
}
......
......@@ -28,6 +28,7 @@
#include "indi/indifilter.h"
#include "auxiliary/kspaths.h"
#include "auxiliary/ksuserdb.h"
#include "fitsviewer/fitsviewer.h"
#include "fitsviewer/fitstab.h"
......@@ -36,6 +37,7 @@
#include "ekos/auxiliary/darklibrary.h"
#include "kstars.h"
#include "kstarsdata.h"
#include "focusadaptor.h"
#include <basedevice.h>
......@@ -134,6 +136,8 @@ Focus::Focus()
connect(binningCombo, SIGNAL(activated(int)), this, SLOT(setActiveBinning(int)));
connect(focusBoxSize, SIGNAL(valueChanged(int)), this, SLOT(updateBoxSize(int)));
connect(exposureIN, SIGNAL(editingFinished()), this, SLOT(saveFilterExposure()));
focusDetection = static_cast<StarAlgorithm>(Options::focusDetection());
focusDetectionCombo->setCurrentIndex(focusDetection);
......@@ -250,7 +254,7 @@ Focus::Focus()
defaultScale = static_cast<FITSScale>(Options::focusEffect());
connect(filterCombo, SIGNAL(activated(int)), this, SLOT(filterChangeWarning(int)));
exposureIN->setValue(Options::focusExposure());
//exposureIN->setValue(Options::focusExposure());
toleranceIN->setValue(Options::focusTolerance());
stepIN->setValue(Options::focusTicks());
autoStarCheck->setChecked(Options::focusAutoStarEnabled());
......@@ -457,6 +461,7 @@ void Focus::addFilter(ISD::GDInterface * newFilter)
FilterCaptureCombo->setCurrentIndex(0);
refreshFilterExposure();
}
bool Focus::setFilter(QString device, int filterSlot)
......@@ -481,7 +486,7 @@ bool Focus::setFilter(QString device, int filterSlot)
}
void Focus::checkFilter(int filterNum)
{
{
if (filterNum == -1)
{
filterNum = FilterCaptureCombo->currentIndex();
......@@ -491,8 +496,13 @@ void Focus::checkFilter(int filterNum)
QStringList filterAlias = Options::filterAlias();
bool deviceChanged=false;
if (filterNum <= Filters.count())
{
if (currentFilter != Filters.at(filterNum))
deviceChanged = true;
currentFilter = Filters.at(filterNum);
}
FilterPosCombo->clear();
......@@ -520,7 +530,7 @@ void Focus::checkFilter(int filterNum)
FilterPosCombo->addItem(item);
}
}
if (lockFilterCheck->isChecked() == false)
FilterPosCombo->setCurrentIndex( currentFilterIndex);
......@@ -545,6 +555,9 @@ void Focus::checkFilter(int filterNum)
}
}
if (deviceChanged)
refreshFilterExposure();
}
void Focus::filterLockToggled(bool enable)
......@@ -571,6 +584,8 @@ void Focus::updateFilterPos(int index)
Options::setLockFocusFilterIndex(lockedFilterIndex);
emit filterLockUpdated(currentFilter, lockedFilterIndex);
}
refreshFilterExposure();
}
void Focus::addFocuser(ISD::GDInterface * newFocuser)
......@@ -763,7 +778,7 @@ void Focus::start()
Options::setFocusTicks(stepIN->value());
Options::setFocusTolerance(toleranceIN->value());
Options::setFocusExposure(exposureIN->value());
//Options::setFocusExposure(exposureIN->value());
Options::setFocusMaxTravel(maxTravelIN->value());
Options::setFocusBoxSize(focusBoxSize->value());
Options::setFocusSubFrame(kcfg_subFrame->isChecked());
......@@ -2756,4 +2771,47 @@ bool Focus::findMinimum(double expected, double * position, double * hfr)
return (status == GSL_SUCCESS);
}
void Focus::saveFilterExposure()
{
// Find matching filter if any and save its exposure
OAL::Filter * matchedFilter=NULL;
foreach( OAL::Filter * o, m_filterList )
{
if (o->vendor() == FilterCaptureCombo->currentText() && o->color() == FilterPosCombo->currentText())
{
matchedFilter = o;
break;
}
}
// If doesn't exist, create one
if (matchedFilter == NULL)
KStarsData::Instance()->userdb()->AddFilter(FilterCaptureCombo->currentText(), "", "", "0", FilterPosCombo->currentText(), QString::number(exposureIN->value()));
// Or update existing
else
KStarsData::Instance()->userdb()->AddFilter(FilterCaptureCombo->currentText(), "", "", matchedFilter->offset(), matchedFilter->color(), QString::number(exposureIN->value()), matchedFilter->id());
// Reload
KStarsData::Instance()->userdb()->GetAllFilters(m_filterList);
}
void Focus::refreshFilterExposure()
{
KStarsData::Instance()->userdb()->GetAllFilters(m_filterList);
OAL::Filter * matchedFilter=NULL;
foreach( OAL::Filter * o, m_filterList )
{
if (o->vendor() == FilterCaptureCombo->currentText() && o->color() == FilterPosCombo->currentText())
{
matchedFilter = o;
break;
}
}
if (matchedFilter)
exposureIN->setValue(matchedFilter->exposure().toDouble());
else
// Default value
exposureIN->setValue(1);
}
}
......@@ -14,8 +14,9 @@
#include "ekos/ekos.h"
#include "focus.h"
//#include "capture/capture.h"
#include "oal/filter.h"
#include "ui_focus.h"
#include "indi/indistd.h"
......@@ -340,6 +341,16 @@ class Focus : public QWidget, public Ui::Focus
void toggleFocusingWidgetFullScreen();
/**
* @brief saveFilterExposure Save filter exposure value in database
*/
void saveFilterExposure();
/**
* @brief refreshFilterExposure Load filter exposure value from DB and apply it to current exposure value
*/
void refreshFilterExposure();
//void registerFocusProperty(INDI::Property *prop);
signals:
......@@ -528,6 +539,9 @@ class Focus : public QWidget, public Ui::Focus
// Polynomial fitting coefficients
std::vector<double> coeff;
int polySolutionFound=0;
// Filters from DB
QList<OAL::Filter *> m_filterList;
};
}
......
......@@ -265,7 +265,7 @@ void EquipmentWriter::slotNewLens()
void EquipmentWriter::slotAddFilter()
{
KStarsData::Instance()->userdb()->AddFilter( ui.f_Vendor->text(), ui.f_Model->text(),
ui.f_Type->text(), ui.f_Offset->text(), ui.f_Color->text());
ui.f_Type->text(), ui.f_Offset->text(), ui.f_Color->text(), ui.f_Exposure->text());
loadEquipment();
ui.f_Id->clear();
ui.f_Model->clear();
......@@ -273,6 +273,7 @@ void EquipmentWriter::slotAddFilter()
ui.f_Type->clear();
ui.f_Offset->clear();
ui.f_Color->clear();
ui.f_Exposure->clear();
}
void EquipmentWriter::slotRemoveFilter()
......@@ -285,6 +286,7 @@ void EquipmentWriter::slotRemoveFilter()
ui.f_Type->clear();
ui.f_Offset->clear();
ui.f_Color->clear();
ui.f_Exposure->clear();
ui.FilterList->clear();
foreach( OAL::Filter * f, *( KStarsData::Instance()->logObject()->filterList() ) )
ui.FilterList->addItem( f->name() );
......@@ -293,7 +295,7 @@ void EquipmentWriter::slotRemoveFilter()
void EquipmentWriter::slotSaveFilter()
{
KStarsData::Instance()->userdb()->AddFilter( ui.f_Vendor->text(), ui.f_Model->text(),
ui.f_Type->text(), ui.f_Color->text(),
ui.f_Type->text(), ui.f_Color->text(), ui.f_Exposure->text(),
ui.f_Id->text());
loadEquipment();
}
......@@ -310,6 +312,7 @@ void EquipmentWriter::slotSetFilter( QString name )
ui.f_Type->setText( f->type() );
ui.f_Offset->setText(f->offset());
ui.f_Color->setText( f->color() );
ui.f_Exposure->setText(f->exposure());
newFilter = false;
}
}
......@@ -322,6 +325,7 @@ void EquipmentWriter::slotNewFilter()
ui.f_Type->clear();
ui.f_Model->clear();
ui.f_Color->clear();
ui.f_Exposure->clear();
ui.FilterList->selectionModel()->clear();
newFilter = true;
}
......
......@@ -625,6 +625,9 @@
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_18">
<property name="toolTip">
<string>Filter focus offset</string>
</property>
<property name="text">
<string>Offset:</string>
</property>
......@@ -633,6 +636,20 @@
<item row="5" column="1">
<widget class="QLineEdit" name="f_Offset"/>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_19">
<property name="text">
<string>Exposure:</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QLineEdit" name="f_Exposure">
<property name="toolTip">
<string>Filter default exposure time in Ekos Focus Module</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
......
......@@ -18,7 +18,7 @@
#include "oal/filter.h"
void OAL::Filter::setFilter(const QString &_id, const QString &_model, const QString &_vendor, const QString &_type, const QString &_offset, const QString &_color )
void OAL::Filter::setFilter(const QString &_id, const QString &_model, const QString &_vendor, const QString &_type, const QString &_offset, const QString &_color , const QString &_exposure)
{
m_Id = _id;
m_Model = _model;
......@@ -27,4 +27,5 @@ void OAL::Filter::setFilter(const QString &_id, const QString &_model, const QSt
m_Color = _color;
m_Name = _vendor + ' ' + _model + " - " + _type + ' ' + _color + " (" + _id + ')';
m_Offset = _offset;
m_Exposure = _exposure;
}
......@@ -30,9 +30,9 @@
class OAL::Filter
{
public:
Filter( const QString &id, const QString &model, const QString &vendor, const QString &type, const QString &offset, const QString &color )
Filter( const QString &id, const QString &model, const QString &vendor, const QString &type, const QString &offset, const QString &color, const QString &exposure )
{
setFilter( id, model, vendor, type, offset, color );
setFilter( id, model, vendor, type, offset, color, exposure );
}
QString id() const
{
......@@ -66,8 +66,16 @@ class OAL::Filter
{
m_Offset = _offset;
}
void setFilter( const QString &_id, const QString &_model, const QString &_vendor, const QString &_type, const QString &_offset, const QString &_color );
QString exposure() const
{
return m_Exposure;
}
void setExposure(const QString &_exposure)
{
m_Exposure = _exposure;
}
void setFilter( const QString &_id, const QString &_model, const QString &_vendor, const QString &_type, const QString &_offset, const QString &_color, const QString &_exposure );
private:
QString m_Id, m_Model, m_Vendor, m_Type, m_Color, m_Name, m_Offset;
QString m_Id, m_Model, m_Vendor, m_Type, m_Color, m_Name, m_Offset, m_Exposure;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment