File indexing completed on 2024-06-16 11:34:27

0001 /***************************************************************************
0002  *   Copyright (C) 2003 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 "pulse.h"
0012 #include "flowcode.h"
0013 #include "libraryitem.h"
0014 #include "icndocument.h"
0015 
0016 #include <KLocalizedString>
0017 
0018 Item *Pulse::construct(ItemDocument *itemDocument, bool newItem, const char *id)
0019 {
0020     return new Pulse(static_cast<ICNDocument *>(itemDocument), newItem, id);
0021 }
0022 
0023 LibraryItem *Pulse::libraryItem()
0024 {
0025     return new LibraryItem(QStringList(QString("flow/pulse")), i18n("Pulse"), i18n("Functions"), "pppulse.png", LibraryItem::lit_flowpart, Pulse::construct);
0026 }
0027 
0028 Pulse::Pulse(ICNDocument *icnDocument, bool newItem, const char *id)
0029     : FlowPart(icnDocument, newItem, id ? id : "pulse")
0030 {
0031     m_name = i18n("Pulse");
0032     initProcessSymbol();
0033     createStdInput();
0034     createStdOutput();
0035 
0036     createProperty("0-duration", Variant::Type::Double);
0037     property("0-duration")->setCaption(i18n("Duration"));
0038     property("0-duration")->setUnit("sec");
0039     property("0-duration")->setValue(2.0);
0040 
0041     createProperty("1-high", Variant::Type::Double);
0042     property("1-high")->setCaption(i18n("High Time"));
0043     property("1-high")->setUnit("sec");
0044     property("1-high")->setValue(0.5);
0045 
0046     createProperty("2-low", Variant::Type::Double);
0047     property("2-low")->setCaption(i18n("Low Time"));
0048     property("2-low")->setUnit("sec");
0049     property("2-low")->setValue(0.5);
0050 
0051     createProperty("3-pin", Variant::Type::Pin);
0052     property("3-pin")->setCaption(i18n("Pin"));
0053     property("3-pin")->setValue("RA0");
0054 }
0055 
0056 Pulse::~Pulse()
0057 {
0058 }
0059 
0060 void Pulse::dataChanged()
0061 {
0062     double pulse = dataDouble("0-duration");
0063     setCaption(i18n("Pulse %1 for %2 sec", dataString("3-pin"), QString::number(pulse / getMultiplier(pulse), 'f', 1) + getNumberMag(pulse)));
0064 }
0065 
0066 void Pulse::generateMicrobe(FlowCode *code)
0067 {
0068     const double duration_ms = dataDouble("0-duration") * 1e3;
0069     const double high_ms = dataDouble("1-high") * 1e3;
0070     const double low_ms = dataDouble("2-low") * 1e3;
0071     const QString pin = dataString("3-pin");
0072 
0073     // TODO Do we want to change the format for pulsing?
0074     code->addCode("pulse " + pin + " " + QString::number(duration_ms) + " " + QString::number(high_ms) + " " + QString::number(low_ms));
0075     code->addCodeBranch(outputPart("stdoutput"));
0076 }