summaryrefslogtreecommitdiffstats
path: root/src/flowparts/delay.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 01:49:02 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 01:49:02 +0000
commit5de3dd4762ca33a0f92e79ffa4fe2ff67069d531 (patch)
treebad482b7afa4cdf47422d60a5dd2c61c7e333b09 /src/flowparts/delay.cpp
downloadktechlab-5de3dd4762ca33a0f92e79ffa4fe2ff67069d531.tar.gz
ktechlab-5de3dd4762ca33a0f92e79ffa4fe2ff67069d531.zip
Added KDE3 version of ktechlab
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/ktechlab@1095338 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/flowparts/delay.cpp')
-rw-r--r--src/flowparts/delay.cpp136
1 files changed, 136 insertions, 0 deletions
diff --git a/src/flowparts/delay.cpp b/src/flowparts/delay.cpp
new file mode 100644
index 0000000..fa37770
--- /dev/null
+++ b/src/flowparts/delay.cpp
@@ -0,0 +1,136 @@
+/***************************************************************************
+ * Copyright (C) 2003 by David Saxton *
+ * david@bluehaze.org *
+ * *
+ * 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. *
+ ***************************************************************************/
+
+#include "delay.h"
+
+#include "libraryitem.h"
+#include "flowcode.h"
+
+#include <klocale.h>
+
+Item* Delay::construct( ItemDocument *itemDocument, bool newItem, const char *id )
+{
+ return new Delay( (ICNDocument*)itemDocument, newItem, id );
+}
+
+LibraryItem* Delay::libraryItem()
+{
+ return new LibraryItem(
+ QString::QString("flow/delay"),
+ i18n("Delay"),
+ i18n("Functions"),
+ "delay.png",
+ LibraryItem::lit_flowpart,
+ Delay::construct );
+}
+
+Delay::Delay( ICNDocument *icnDocument, bool newItem, const char *id )
+ : FlowPart( icnDocument, newItem, (id) ? id : "delay" )
+{
+ m_name = i18n("Delay");
+ m_desc = i18n("Delay the program execution for a fixed period of time.");
+ initProcessSymbol();
+ createStdInput();
+ createStdOutput();
+
+ createProperty( "delay_length", Variant::Type::Double );
+ property("delay_length")->setCaption( i18n("Pause Length") );
+ property("delay_length")->setUnit("sec");
+ property("delay_length")->setValue(1.0);
+}
+
+Delay::~Delay()
+{
+}
+
+void Delay::dataChanged()
+{
+ double delay = dataDouble("delay_length");
+ setCaption( i18n("Delay for %1 sec").arg(QString::number( delay / getMultiplier(delay), 'g', 3 )+getNumberMag(delay)) );
+}
+
+void Delay::generateMicrobe( FlowCode *code )
+{
+ const double delayLength_ms = dataDouble("delay_length")*1e3;
+ code->addCode( "delay "+QString::number(delayLength_ms) );
+ code->addCodeBranch( outputPart("stdoutput") );
+
+// code->addVariable("COUNT_REPEAT");
+
+#if 0
+ // Code for pauses less than 769uS
+ if ( pauseLength < 769 )
+ {
+ code->addCodeBlock( id(), "movlw " + QString::number(pauseLength/3) + "\n"
+ "movwf COUNT_REPEAT\n"
+ "call count_3uS\n"
+ + gotoCode("stdoutput") );
+
+ code->addCodeBlock( "count_3uS", "decfsz COUNT_REPEAT,1\n"
+ "goto count_3uS\n"
+ "return" );
+ }
+ else if ( pauseLength < 196609 )
+ {
+ code->addVariable("COUNT_LOOP_1");
+
+ code->addCodeBlock( id(), "movlw " + QString::number(pauseLength/(3*256)) + "\n"
+ "movwf COUNT_REPEAT\n"
+ "call count_768uS\n"
+ + gotoCode("stdoutput") );
+
+ code->addCodeBlock( "count_768uS", "decfsz COUNT_LOOP_1,1\n"
+ "goto count_768uS\n"
+ "decfsz COUNT_REPEAT,1\n"
+ "goto count_768uS\n"
+ "return" );
+ }
+ else if ( pauseLength < 50331649 )
+ {
+ code->addVariable("COUNT_LOOP_1");
+ code->addVariable("COUNT_LOOP_2");
+
+ code->addCodeBlock( id(), "movlw " + QString::number(pauseLength/(3*256*256)) + "\n"
+ "movwf COUNT_REPEAT\n"
+ "call count_200mS\n"
+ + gotoCode("stdoutput") );
+
+ code->addCodeBlock( "count_200mS", "decfsz COUNT_LOOP_1,1\n"
+ "goto count_200mS\n"
+ "decfsz COUNT_LOOP_2,1\n"
+ "goto count_200mS\n"
+ "decfsz COUNT_REPEAT,1\n"
+ "goto count_200mS\n"
+ "return" );
+ }
+ else/* if ( pauseLength < 12884901889 )*/
+ {
+ code->addVariable("COUNT_LOOP_1");
+ code->addVariable("COUNT_LOOP_2");
+ code->addVariable("COUNT_LOOP_3");
+
+ code->addCodeBlock( id(), "movlw " + QString::number(pauseLength/(3*256*256*256)) + "\n"
+ "movwf COUNT_REPEAT\n"
+ "call count_50S\n"
+ + gotoCode("stdoutput") );
+
+ code->addCodeBlock( "count_50S", "decfsz COUNT_LOOP_1,1\n"
+ "goto count_50S\n"
+ "decfsz COUNT_LOOP_2,1\n"
+ "goto count_50S\n"
+ "decfsz COUNT_LOOP_3,1\n"
+ "goto count_50S\n"
+ "decfsz COUNT_REPEAT,1\n"
+ "goto count_50S\n"
+ "return" );
+ }
+#endif
+}
+