00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "writeport.h"
00012
00013 #include "libraryitem.h"
00014 #include "flowcode.h"
00015
00016 #include <klocale.h>
00017
00018 Item* WritePort::construct( ItemDocument *itemDocument, bool newItem, const char *id )
00019 {
00020 return new WritePort( (ICNDocument*)itemDocument, newItem, id );
00021 }
00022
00023 LibraryItem* WritePort::libraryItem()
00024 {
00025 return new LibraryItem(
00026 QString("flow/writeport"),
00027 i18n("Write to Port"),
00028 i18n("I\\/O"),
00029 "portwrite.png",
00030 LibraryItem::lit_flowpart,
00031 WritePort::construct );
00032 }
00033
00034 WritePort::WritePort( ICNDocument *icnDocument, bool newItem, const char *id )
00035 : FlowPart( icnDocument, newItem, (id) ? id : "writeport" )
00036 {
00037 m_name = i18n("Write to Port");
00038 m_desc = i18n("Sets the port's pins state to high/low from the given value. Only pins that have been configured as output pins will take on the value assigned to them.");
00039 initIOSymbol();
00040 createStdInput();
00041 createStdOutput();
00042
00043 createProperty( "0-var", Variant::Type::Combo );
00044 property("0-var")->setToolbarCaption( i18n("Write") );
00045 property("0-var")->setEditorCaption( i18n("Variable") );
00046 property("0-var")->setValue("x");
00047
00048 createProperty( "1-port", Variant::Type::Port );
00049 property("1-port")->setToolbarCaption( "to" );
00050 property("1-port")->setEditorCaption( i18n("Port") );
00051 property("1-port")->setValue("PORTA");
00052 }
00053
00054
00055 WritePort::~WritePort()
00056 {
00057 }
00058
00059
00060 void WritePort::dataChanged()
00061 {
00062 setCaption( i18n("Write %1 to %2").arg(dataString("0-var")).arg(dataString("1-port")) );
00063 }
00064
00065
00066 void WritePort::generateMicrobe( FlowCode *code )
00067 {
00068 code->addCode( dataString("1-port")+" = "+dataString("0-var") );
00069 code->addCodeBranch( outputPart("stdoutput") );
00070
00071 #if 0
00072 QString var = dataString("var");
00073 QString port = dataString("port");
00074
00075
00076
00077 QString newCode;
00078
00079 if ( FlowCode::isLiteral(var) ) newCode += "movlw " + var + " ; Move " + var + " to working register w\n";
00080 else
00081 {
00082 code->addVariable(var);
00083 newCode += "movf " + var + ",0 ; Move " + var + " to working register w\n";
00084 }
00085
00086 newCode += "movwf " + port + " ; Move register w to port\n";
00087
00088
00089
00090
00091 newCode += gotoCode("stdoutput") + "\n";
00092
00093 code->addCodeBlock( id(), newCode );
00094 #endif
00095 }