File indexing completed on 2024-12-08 11:06:54
0001 /*************************************************************************** 0002 * Copyright (C) 2003-2004 by David Saxton * 0003 * david@bluehaze.org * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 ***************************************************************************/ 0010 0011 #include "setpin.h" 0012 0013 #include "flowcode.h" 0014 #include "flowcodedocument.h" 0015 #include "libraryitem.h" 0016 #include "microsettings.h" 0017 #include "picinfo.h" 0018 0019 #include <KLocalizedString> 0020 0021 Item *SetPin::construct(ItemDocument *itemDocument, bool newItem, const char *id) 0022 { 0023 return new SetPin(static_cast<ICNDocument *>(itemDocument), newItem, id); 0024 } 0025 0026 LibraryItem *SetPin::libraryItem() 0027 { 0028 return new LibraryItem(QStringList(QString("flow/setpin")), i18n("Set Pin State"), i18n("I\\/O"), "pinwrite.png", LibraryItem::lit_flowpart, SetPin::construct); 0029 } 0030 0031 SetPin::SetPin(ICNDocument *icnDocument, bool newItem, const char *id) 0032 : FlowPart(icnDocument, newItem, id ? id : "setpin") 0033 { 0034 m_name = i18n("Set Pin State"); 0035 initIOSymbol(); 0036 createStdInput(); 0037 createStdOutput(); 0038 0039 createProperty("state", Variant::Type::Select); 0040 property("state")->setCaption(i18n("State")); 0041 property("state")->setAllowed((QStringList("high") << "low")); 0042 property("state")->setValue("high"); 0043 0044 createProperty("pin", Variant::Type::Pin); 0045 property("pin")->setCaption(i18n("Pin")); 0046 property("pin")->setValue("RA0"); 0047 } 0048 0049 SetPin::~SetPin() 0050 { 0051 } 0052 0053 void SetPin::dataChanged() 0054 { 0055 setCaption(i18n("Set %1 %2", dataString("pin"), dataString("state"))); 0056 } 0057 0058 void SetPin::generateMicrobe(FlowCode *code) 0059 { 0060 const QString pin = dataString("pin"); 0061 const QString port = "PORT" + QString(static_cast<QChar>(pin[1])); 0062 const QString bit = static_cast<QChar>(pin[2]); 0063 code->addCode(port + "." + bit + " = " + dataString("state")); 0064 code->addCodeBranch(outputPart("stdoutput")); 0065 0066 #if 0 0067 const QString pin = dataString("pin"); 0068 const bool isHigh = (dataString("state") == "High"); 0069 const QString port = "PORT" + QString(static_cast<QChar>(pin[1])); 0070 const QString bit = static_cast<QChar>(pin[2]); 0071 0072 QString newCode; 0073 if (isHigh) 0074 { 0075 newCode += "bsf " + port + "," + bit + " ; Set bit high\n"; 0076 } 0077 else 0078 { 0079 newCode += "bcf " + port + "," + bit + " ; Set bit low\n"; 0080 } 0081 0082 code->addCodeBlock( id(), newCode ); 0083 #endif 0084 }