File indexing completed on 2024-06-09 13:46:36

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 "testpin.h"
0012 
0013 #include "flowcode.h"
0014 #include "libraryitem.h"
0015 #include "icndocument.h"
0016 
0017 #include <KLocalizedString>
0018 
0019 Item *TestPin::construct(ItemDocument *itemDocument, bool newItem, const char *id)
0020 {
0021     return new TestPin(static_cast<ICNDocument *>(itemDocument), newItem, id);
0022 }
0023 
0024 LibraryItem *TestPin::libraryItem()
0025 {
0026     return new LibraryItem(QStringList(QString("flow/testpin")), i18n("Test Pin State"), i18n("I\\/O"), "pinread.png", LibraryItem::lit_flowpart, TestPin::construct);
0027 }
0028 
0029 TestPin::TestPin(ICNDocument *icnDocument, bool newItem, const char *id)
0030     : FlowPart(icnDocument, newItem, id ? id : "testpin")
0031 {
0032     m_name = i18n("Test Pin State");
0033     initDecisionSymbol();
0034     createStdInput();
0035     createStdOutput();
0036     createAltOutput();
0037 
0038     createProperty("pin", Variant::Type::Pin);
0039     property("pin")->setCaption(i18n("Pin"));
0040     property("pin")->setValue("RA0");
0041 
0042     addDisplayText("output_false", QRect(offsetX() + width(), 2, 40, 20), "Low");
0043     addDisplayText("output_true", QRect(0, offsetY() + height(), 50, 20), "High");
0044 }
0045 
0046 TestPin::~TestPin()
0047 {
0048 }
0049 
0050 void TestPin::dataChanged()
0051 {
0052     setCaption("Test " + dataString("pin"));
0053 }
0054 
0055 void TestPin::generateMicrobe(FlowCode *code)
0056 {
0057     const QString pin = dataString("pin");
0058     const QString port = "PORT" + QString(static_cast<QChar>(pin[1]));
0059     const QString bit = static_cast<QChar>(pin[2]);
0060 
0061     handleIfElse(code, port + "." + bit + " is high", port + "." + bit + " is low", "stdoutput", "altoutput");
0062 
0063 #if 0
0064     QString newCode;
0065     
0066     newCode += "btfss "+port+","+bit+" ; Check if pin is clear\n";
0067     newCode += gotoCode("altoutput") + " ; Pin is low\n";
0068     newCode += gotoCode("stdoutput") + " ; Pin is high, continue on from this point\n";
0069     
0070     code->addCodeBlock( id(), newCode );
0071 #endif
0072 }