[Pikloops-svn] SF.net SVN: pikloops: [184] prog/trunk
Brought to you by:
dionysos-sf
|
From: <dio...@us...> - 2007-10-19 15:13:06
|
Revision: 184
http://pikloops.svn.sourceforge.net/pikloops/?rev=184&view=rev
Author: dionysos-sf
Date: 2007-10-19 08:13:07 -0700 (Fri, 19 Oct 2007)
Log Message:
-----------
New feature: delay, frequency and time unit can be add on the command line
Modified Paths:
--------------
prog/trunk/NEWS
prog/trunk/src/main.cpp
prog/trunk/src/mainwidgetpl.cpp
Added Paths:
-----------
prog/trunk/src/options.h
Modified: prog/trunk/NEWS
===================================================================
--- prog/trunk/NEWS 2007-10-18 15:08:33 UTC (rev 183)
+++ prog/trunk/NEWS 2007-10-19 15:13:07 UTC (rev 184)
@@ -1,5 +1,6 @@
Version 0.3.0 :
New feature: a time unit selector
+ New feature: delay, frequency and time unit can be add on the command line
Don't display trailing zeroes
Version 0.2.5 :
Modified: prog/trunk/src/main.cpp
===================================================================
--- prog/trunk/src/main.cpp 2007-10-18 15:08:33 UTC (rev 183)
+++ prog/trunk/src/main.cpp 2007-10-19 15:13:07 UTC (rev 184)
@@ -26,17 +26,33 @@
#include <kcmdlineargs.h>
#include <klocale.h>
+extern double optFrequency;
+extern double optDelay;
+extern double optUnit;
static const char description[] = I18N_NOOP("Pic Delay Calculator");
static const char version[] = VERSION;
static KCmdLineOptions options[] =
{
// { "+[URL]", I18N_NOOP( "Document to open." ), 0 },
+
+ { "f", 0, 0 },
+ { "frequency <frequency>", I18N_NOOP("Frequency of the PIC oscillator in MHz"), "4.0" },
+ { "d", 0, 0 },
+ { "delay <delay>", I18N_NOOP("Requested delay"), "1.0" },
+ { "u", 0, 0 },
+ { "time-unit <unit>", I18N_NOOP("Time unit of the delay\nValid units are \"s\", \"ms\" and \"us\""), "ms" },
KCmdLineLastOption
};
int main(int argc, char **argv)
{
+ QCString argFrequency;
+ QCString argDelay;
+ QCString argUnit;
+ bool parseOptionFailed=FALSE;
+ bool conversionIsOk;
+
KAboutData about("pikloops",
I18N_NOOP("PikLoops"),
version,
@@ -73,6 +89,40 @@
/// @todo do something with the command line args here
+ argFrequency = args->getOption("frequency");
+ argDelay = args->getOption("delay");
+ argUnit = args->getOption("time-unit");
+
+ if ( qstrcmp (argUnit, "s") == 0 ) {
+ optUnit = 1.0 ;
+ }
+ else if ( qstrcmp (argUnit, "ms") == 0 ) {
+ optUnit = 0.001 ;
+ }
+ else if ( qstrcmp (argUnit, "us") == 0 ) {
+ optUnit = 0.000001 ;
+ }
+ else {
+ QString msgError = QString(i18n("\"%1\" isn't a valid time unit.\n")).arg(argUnit);
+ msgError += i18n("Valid units are \"s\", \"ms\" and \"us\"");
+ qDebug(msgError);
+ parseOptionFailed=TRUE;
+ }
+
+ optFrequency = argFrequency.toDouble(&conversionIsOk);
+ if ( conversionIsOk == FALSE ) {
+ QString msgError = QString(i18n("\"%1\" isn't a valid frequency.\n")).arg(argFrequency);
+ qDebug(msgError);
+ parseOptionFailed=TRUE;
+ }
+
+ optDelay = argDelay.toDouble(&conversionIsOk);
+ if ( conversionIsOk == FALSE ) {
+ QString msgError = QString(i18n("\"%1\" isn't a valid delay.\n")).arg(argDelay);
+ qDebug(msgError);
+ parseOptionFailed=TRUE;
+ }
+
mainWin = new PiKLoops();
app.setMainWidget( mainWin );
@@ -82,7 +132,9 @@
args->clear();
}
+ if ( parseOptionFailed==FALSE ) {
// mainWin has WDestructiveClose flag by default, so it will delete itself.
- return app.exec();
+ return app.exec();
+ }
}
Modified: prog/trunk/src/mainwidgetpl.cpp
===================================================================
--- prog/trunk/src/mainwidgetpl.cpp 2007-10-18 15:08:33 UTC (rev 183)
+++ prog/trunk/src/mainwidgetpl.cpp 2007-10-19 15:13:07 UTC (rev 184)
@@ -20,6 +20,7 @@
* */
#include "mainwidgetpl.h"
+#include "options.h"
#include <qlayout.h>
#include <qlabel.h>
#include <qtextedit.h>
@@ -43,7 +44,7 @@
: QVBox(parent, name)
{
QFont LabelFont;
- loopValues = new PiKDelay(4.00, 1.00, 0.001);
+ loopValues = new PiKDelay(optFrequency, optDelay, optUnit);
statusMessage = i18n("Actual delay: %1%2 (%3 clock cycles).") ;
setSpacing(3) ;
@@ -58,13 +59,25 @@
"32.000000", "40.000000", 0};
clock->insertStrList( items );
clock->setEditable(true) ;
- clock->setCurrentItem(2) ;
+
+ for (int i=0; items[i]!=0; i++) {
+ if ( QString("%1").arg(*items[i],0,'g',-1).toDouble() == optFrequency ) {
+ clock->setCurrentItem(i) ;
+ }
+ }
+
+ if ( clock->currentText().toDouble() != optFrequency ) {
+ clock->insertItem(QString("%1").arg(optFrequency,0,'f',8),-1);
+ clock->setCurrentItem(10) ;
+ }
QToolTip::add(clock,i18n("Select a standard device clock, or type a custom clock frequency.")) ;
(new QHBox(grinput))->setMinimumWidth(10) ;
new QLabel(i18n("Needed delay (s)"), grinput) ;
delay = new KRestrictedLine (grinput,"delay editor","0123456789.") ;
- delay->setText("1");
+
+ delay->setText(QString("%1").arg(optDelay,0,'g',-1));
+
delay->setMinimumWidth(60);
(new QHBox(grinput))->setMinimumWidth(10) ;
@@ -73,8 +86,16 @@
static const char* units_items[] = { "s", "ms", "us", 0};
units->insertStrList( units_items );
units->setEditable(false) ;
- units->setCurrentItem(1) ;
+ if ( optUnit == 1.0 ) {
+ units->setCurrentItem(0) ;
+ }
+ else if ( optUnit == 0.000001 ) {
+ units->setCurrentItem(2) ;
+ }
+ else {
+ units->setCurrentItem(1) ;
+ }
// output
QVGroupBox *groutput = new QVGroupBox( i18n("Ouput data") , this) ;
Added: prog/trunk/src/options.h
===================================================================
--- prog/trunk/src/options.h (rev 0)
+++ prog/trunk/src/options.h 2007-10-19 15:13:07 UTC (rev 184)
@@ -0,0 +1,30 @@
+/**
+ * Copyright (C) 2007 - Alain Portal <aportal AT univ-montp2 DOT fr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * */
+
+#ifndef OPTIONS_H
+#define OPTIONS_H
+
+
+ double optFrequency;
+ double optDelay;
+ double optUnit;
+
+
+#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|