[Pikloops-svn] SF.net SVN: pikloops: [178] prog/trunk
Brought to you by:
dionysos-sf
From: <dio...@us...> - 2007-10-18 14:11:07
|
Revision: 178 http://pikloops.svn.sourceforge.net/pikloops/?rev=178&view=rev Author: dionysos-sf Date: 2007-10-18 07:11:09 -0700 (Thu, 18 Oct 2007) Log Message: ----------- New feature: time unit selector. Change number display format Modified Paths: -------------- prog/trunk/NEWS prog/trunk/src/mainwidgetpl.cpp prog/trunk/src/mainwidgetpl.h prog/trunk/src/pikdelay.cpp prog/trunk/src/pikdelay.h Modified: prog/trunk/NEWS =================================================================== --- prog/trunk/NEWS 2007-10-17 15:34:50 UTC (rev 177) +++ prog/trunk/NEWS 2007-10-18 14:11:09 UTC (rev 178) @@ -1,3 +1,7 @@ +Version 0.3.0 : + New feature: a time unit selector + Don't display trailing zeroes + Version 0.2.5 : Fix bug in delay calculation Modify delay calculation management Modified: prog/trunk/src/mainwidgetpl.cpp =================================================================== --- prog/trunk/src/mainwidgetpl.cpp 2007-10-17 15:34:50 UTC (rev 177) +++ prog/trunk/src/mainwidgetpl.cpp 2007-10-18 14:11:09 UTC (rev 178) @@ -43,8 +43,8 @@ : QVBox(parent, name) { QFont LabelFont; - loopValues = new PiKDelay(4.00, 1.00); - statusMessage = i18n("Actual delay: %1 s (%2 clock cycles).") ; + loopValues = new PiKDelay(4.00, 1.00, 0.001); + statusMessage = i18n("Actual delay: %1%2 (%3 clock cycles).") ; setSpacing(3) ; setMargin(6) ; @@ -61,12 +61,21 @@ clock->setCurrentItem(2) ; QToolTip::add(clock,i18n("Select a standard device clock, or type a custom clock frequency.")) ; - (new QHBox(grinput))->setMinimumWidth(40) ; + (new QHBox(grinput))->setMinimumWidth(10) ; new QLabel(i18n("Needed delay (s)"), grinput) ; delay = new KRestrictedLine (grinput,"delay editor","0123456789.") ; delay->setText("1"); delay->setMinimumWidth(60); + (new QHBox(grinput))->setMinimumWidth(10) ; + new QLabel(i18n("Unit"), grinput) ; + units = new QComboBox(grinput) ; + static const char* units_items[] = { "s", "ms", "us", 0}; + units->insertStrList( units_items ); + units->setEditable(false) ; + units->setCurrentItem(1) ; + + // output QVGroupBox *groutput = new QVGroupBox( i18n("Ouput data") , this) ; CodeText = new GQTextEdit(groutput,"code displayer"); @@ -74,10 +83,12 @@ CodeText->setReadOnly(true); cycles = new QLabel(statusMessage - .arg(loopValues->getTimeDelay(),0,'f',8) + .arg(loopValues->getTimeDelay(),0,'g',-1) + .arg(units->currentText()) .arg((loopValues->getMachineCycles()),0,'f',0) , groutput ) ; connect(clock, SIGNAL(activated(const QString &)), this, SLOT(ClockChanged(const QString &))); + connect(units, SIGNAL(activated(const QString &)), this, SLOT(UnitChanged(const QString &))); connect(delay, SIGNAL(returnPressed()), this, SLOT(TimeDelayChanged())); connect(delay, SIGNAL(lostFocus()), this, SLOT(TimeDelayChanged())); @@ -100,11 +111,13 @@ // set label names QString routineName = i18n("delay_") ; routineName += delay->text() ; - routineName += i18n("_sec") ; + routineName += "_" ; + routineName += units->currentText() ; QString loopName = routineName + i18n("_loop") ; QString subRoutineName = i18n("sub_delay_") ; subRoutineName += delay->text() ; - subRoutineName += i18n("_sec") ; + subRoutineName += "_" ; + subRoutineName += units->currentText() ; QString loopSubRoutineName = subRoutineName + i18n("_loop") ; // generate comments @@ -114,8 +127,10 @@ tmpCode += QDateTime::currentDateTime().toString(i18n("ddd yyyy-MMM-dd hh:mm:ss")) ; tmpCode += ")\n; " ; - tmpCode += QString(i18n("Time Delay = %1s with Osc = %2MHz\n\n")). - arg(loopValues->getTimeDelay(),0,'f',8).arg(loopValues->getClockFrequency(),0,'f',8); + tmpCode += QString(i18n("Time Delay = %1%2 with Osc = %3MHz\n\n")) + .arg(loopValues->getTimeDelay(),0,'g',-1) + .arg(units->currentText()) + .arg(loopValues->getClockFrequency(),0,'g',-1); tmpCode += routineName ; tmpCode += "\n" ; @@ -205,8 +220,9 @@ } } // update status line - cycles->setText(statusMessage.arg(loopValues->getTimeDelay(),0,'f',8) - .arg((loopValues->getMachineCycles()),0,'f',0) ) ; + cycles->setText(statusMessage.arg(loopValues->getTimeDelay(),0,'g',-1) + .arg(units->currentText()) + .arg((loopValues->getMachineCycles()),0,'f',0) ) ; CodeText->setText(tmpCode); CodeText->setFocus(); @@ -246,6 +262,29 @@ refreshWidget(); } + +/*! + \fn MainWidgetPL::UnitChanged() + */ +void MainWidgetPL::UnitChanged(const QString& s) +{ + double tmp; + + if ( s == "s" ) { + tmp = 1.0; + } + else if ( s == "us" ) { + tmp = 0.000001; + } + else { + tmp = 0.001; + } + + loopValues->setTimeUnit(tmp) ; + loopValues->Refresh(); + refreshWidget(); +} + #include "mainwidgetpl.moc" Modified: prog/trunk/src/mainwidgetpl.h =================================================================== --- prog/trunk/src/mainwidgetpl.h 2007-10-17 15:34:50 UTC (rev 177) +++ prog/trunk/src/mainwidgetpl.h 2007-10-18 14:11:09 UTC (rev 178) @@ -50,6 +50,7 @@ private: PiKDelay *loopValues; QComboBox *clock; + QComboBox *units; QTextEdit *CodeText; QLabel *cycles; KRestrictedLine *delay; @@ -61,6 +62,7 @@ protected slots: void ClockChanged(const QString &); + void UnitChanged(const QString &); void TimeDelayChanged(); public slots: Modified: prog/trunk/src/pikdelay.cpp =================================================================== --- prog/trunk/src/pikdelay.cpp 2007-10-17 15:34:50 UTC (rev 177) +++ prog/trunk/src/pikdelay.cpp 2007-10-18 14:11:09 UTC (rev 178) @@ -23,10 +23,11 @@ #include <math.h> -PiKDelay::PiKDelay(double ClkF, double TmDly) +PiKDelay::PiKDelay(double ClkF, double TmDly, double TmUnt) { setClockFrequency(ClkF); setTimeDelay(TmDly); + setTimeUnit(TmUnt); Refresh(); } @@ -43,7 +44,7 @@ { CounterA = CounterB = CounterC = -1; Overflow = 0 ; - MachineCycleTime = 4.0/(ClockFrequency*1000000.0); + MachineCycleTime = 4.0/(ClockFrequency*1000000.0*TimeUnit); MachineCycles = floor(TimeDelay/MachineCycleTime); if ( MachineCycles < MACHINE_CYCLE_MIN ) { @@ -128,6 +129,20 @@ /*! + \fn PiKDelay::setTimeUnit(double = 0.001) + */ +void PiKDelay::setTimeUnit(double TU) +{ + if ( TU == 1.0 || TU == 0.000001 ) { + TimeUnit = TU; + } + else { + TimeUnit = 0.001; + } +} + + +/*! \fn PiKDelay::getMachineCycles() */ double PiKDelay::getMachineCycles() Modified: prog/trunk/src/pikdelay.h =================================================================== --- prog/trunk/src/pikdelay.h 2007-10-17 15:34:50 UTC (rev 177) +++ prog/trunk/src/pikdelay.h 2007-10-18 14:11:09 UTC (rev 178) @@ -32,11 +32,12 @@ class PiKDelay{ public: - PiKDelay(double = 4.00, double = 1.00); + PiKDelay(double = 4.00, double = 1.00, double = 0.001); ~PiKDelay(); void setClockFrequency(double); void setTimeDelay(double); + void setTimeUnit(double); double getMachineCycles(); double getTimeDelay(); double getClockFrequency(); @@ -50,6 +51,7 @@ private: double ClockFrequency; double TimeDelay; + double TimeUnit; double MachineCycles; double MachineCycleTime; int CounterA; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |