00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "delay.h"
00012
00013 #include "libraryitem.h"
00014 #include "flowcode.h"
00015
00016 #include <klocale.h>
00017
00018 Item* Delay::construct( ItemDocument *itemDocument, bool newItem, const char *id )
00019 {
00020 return new Delay( (ICNDocument*)itemDocument, newItem, id );
00021 }
00022
00023 LibraryItem* Delay::libraryItem()
00024 {
00025 return new LibraryItem(
00026 QString::QString("flow/delay"),
00027 i18n("Delay"),
00028 i18n("Functions"),
00029 "delay.png",
00030 LibraryItem::lit_flowpart,
00031 Delay::construct );
00032 }
00033
00034 Delay::Delay( ICNDocument *icnDocument, bool newItem, const char *id )
00035 : FlowPart( icnDocument, newItem, (id) ? id : "delay" )
00036 {
00037 m_name = i18n("Delay");
00038 m_desc = i18n("Delay the program execution for a fixed period of time.");
00039 initProcessSymbol();
00040 createStdInput();
00041 createStdOutput();
00042
00043 createProperty( "delay_length", Variant::Type::Double );
00044 property("delay_length")->setCaption( i18n("Pause Length") );
00045 property("delay_length")->setUnit("sec");
00046 property("delay_length")->setValue(1.0);
00047 }
00048
00049 Delay::~Delay()
00050 {
00051 }
00052
00053 void Delay::dataChanged()
00054 {
00055 double delay = dataDouble("delay_length");
00056 setCaption( i18n("Delay for %1 sec").arg(QString::number( delay / getMultiplier(delay), 'g', 3 )+getNumberMag(delay)) );
00057 }
00058
00059 void Delay::generateMicrobe( FlowCode *code )
00060 {
00061 const double delayLength_ms = dataDouble("delay_length")*1e3;
00062 code->addCode( "delay "+QString::number(delayLength_ms) );
00063 code->addCodeBranch( outputPart("stdoutput") );
00064
00065
00066
00067 #if 0
00068
00069 if ( pauseLength < 769 )
00070 {
00071 code->addCodeBlock( id(), "movlw " + QString::number(pauseLength/3) + "\n"
00072 "movwf COUNT_REPEAT\n"
00073 "call count_3uS\n"
00074 + gotoCode("stdoutput") );
00075
00076 code->addCodeBlock( "count_3uS", "decfsz COUNT_REPEAT,1\n"
00077 "goto count_3uS\n"
00078 "return" );
00079 }
00080 else if ( pauseLength < 196609 )
00081 {
00082 code->addVariable("COUNT_LOOP_1");
00083
00084 code->addCodeBlock( id(), "movlw " + QString::number(pauseLength/(3*256)) + "\n"
00085 "movwf COUNT_REPEAT\n"
00086 "call count_768uS\n"
00087 + gotoCode("stdoutput") );
00088
00089 code->addCodeBlock( "count_768uS", "decfsz COUNT_LOOP_1,1\n"
00090 "goto count_768uS\n"
00091 "decfsz COUNT_REPEAT,1\n"
00092 "goto count_768uS\n"
00093 "return" );
00094 }
00095 else if ( pauseLength < 50331649 )
00096 {
00097 code->addVariable("COUNT_LOOP_1");
00098 code->addVariable("COUNT_LOOP_2");
00099
00100 code->addCodeBlock( id(), "movlw " + QString::number(pauseLength/(3*256*256)) + "\n"
00101 "movwf COUNT_REPEAT\n"
00102 "call count_200mS\n"
00103 + gotoCode("stdoutput") );
00104
00105 code->addCodeBlock( "count_200mS", "decfsz COUNT_LOOP_1,1\n"
00106 "goto count_200mS\n"
00107 "decfsz COUNT_LOOP_2,1\n"
00108 "goto count_200mS\n"
00109 "decfsz COUNT_REPEAT,1\n"
00110 "goto count_200mS\n"
00111 "return" );
00112 }
00113 else
00114 {
00115 code->addVariable("COUNT_LOOP_1");
00116 code->addVariable("COUNT_LOOP_2");
00117 code->addVariable("COUNT_LOOP_3");
00118
00119 code->addCodeBlock( id(), "movlw " + QString::number(pauseLength/(3*256*256*256)) + "\n"
00120 "movwf COUNT_REPEAT\n"
00121 "call count_50S\n"
00122 + gotoCode("stdoutput") );
00123
00124 code->addCodeBlock( "count_50S", "decfsz COUNT_LOOP_1,1\n"
00125 "goto count_50S\n"
00126 "decfsz COUNT_LOOP_2,1\n"
00127 "goto count_50S\n"
00128 "decfsz COUNT_LOOP_3,1\n"
00129 "goto count_50S\n"
00130 "decfsz COUNT_REPEAT,1\n"
00131 "goto count_50S\n"
00132 "return" );
00133 }
00134 #endif
00135 }
00136