00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "setpin.h"
00012
00013 #include "libraryitem.h"
00014 #include "flowcode.h"
00015 #include "picinfo.h"
00016 #include "flowcodedocument.h"
00017 #include "microsettings.h"
00018
00019 #include <klocale.h>
00020
00021 Item* SetPin::construct( ItemDocument *itemDocument, bool newItem, const char *id )
00022 {
00023 return new SetPin( (ICNDocument*)itemDocument, newItem, id );
00024 }
00025
00026 LibraryItem* SetPin::libraryItem()
00027 {
00028 return new LibraryItem(
00029 QString("flow/setpin"),
00030 i18n("Set Pin State"),
00031 i18n("I\\/O"),
00032 "pinwrite.png",
00033 LibraryItem::lit_flowpart,
00034 SetPin::construct );
00035 }
00036
00037 SetPin::SetPin( ICNDocument *icnDocument, bool newItem, const char *id )
00038 : FlowPart( icnDocument, newItem, (id) ? id : "setpin" )
00039 {
00040 m_name = i18n("Set Pin State");
00041 m_desc = i18n("Set a pin on a port high or low. The pin needs to be set as an output pin.");
00042 initIOSymbol();
00043 createStdInput();
00044 createStdOutput();
00045
00046 createProperty( "state", Variant::Type::Select );
00047 property("state")->setCaption( i18n("State") );
00048 property("state")->setAllowed( QStringList::split( ',', "high,low" ) );
00049 property("state")->setValue("high");
00050
00051 createProperty( "pin", Variant::Type::Pin );
00052 property("pin")->setCaption( i18n("Pin") );
00053 property("pin")->setValue("RA0");
00054 }
00055
00056 SetPin::~SetPin()
00057 {
00058 }
00059
00060 void SetPin::dataChanged()
00061 {
00062 setCaption( i18n("Set %1 %2").arg(dataString("pin")).arg(dataString("state")) );
00063 }
00064
00065 void SetPin::generateMicrobe( FlowCode *code )
00066 {
00067 const QString pin = dataString("pin");
00068 const QString port = "PORT" + QString((QChar)pin[1]);
00069 const QString bit = (QChar)pin[2];
00070 code->addCode( port+"."+bit+" = "+dataString("state") );
00071 code->addCodeBranch( outputPart("stdoutput") );
00072
00073 #if 0
00074 const QString pin = dataString("pin");
00075 const bool isHigh = (dataString("state") == "High");
00076 const QString port = "PORT" + QString((QChar)pin[1]);
00077 const QString bit = (QChar)pin[2];
00078
00079 QString newCode;
00080 if (isHigh)
00081 {
00082 newCode += "bsf " + port + "," + bit + " ; Set bit high\n";
00083 }
00084 else
00085 {
00086 newCode += "bcf " + port + "," + bit + " ; Set bit low\n";
00087 }
00088
00089 code->addCodeBlock( id(), newCode );
00090 #endif
00091 }