1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
/***************************************************************************
* Copyright (C) 2003-2004 by David Saxton *
* david@bluehaze.org *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "setpin.h"
#include "libraryitem.h"
#include "flowcode.h"
#include "picinfo.h"
#include "flowcodedocument.h"
#include "microsettings.h"
#include <klocale.h>
Item* SetPin::construct( ItemDocument *itemDocument, bool newItem, const char *id )
{
return new SetPin( (ICNDocument*)itemDocument, newItem, id );
}
LibraryItem* SetPin::libraryItem()
{
return new LibraryItem(
TQString("flow/setpin"),
i18n("Set Pin State"),
i18n("I\\/O"),
"pinwrite.png",
LibraryItem::lit_flowpart,
SetPin::construct );
}
SetPin::SetPin( ICNDocument *icnDocument, bool newItem, const char *id )
: FlowPart( icnDocument, newItem, (id) ? id : "setpin" )
{
m_name = i18n("Set Pin State");
m_desc = i18n("Set a pin on a port high or low. The pin needs to be set as an output pin.");
initIOSymbol();
createStdInput();
createStdOutput();
createProperty( "state", Variant::Type::Select );
property("state")->setCaption( i18n("State") );
property("state")->setAllowed( TQStringList::split( ',', "high,low" ) );
property("state")->setValue("high");
createProperty( "pin", Variant::Type::Pin );
property("pin")->setCaption( i18n("Pin") );
property("pin")->setValue("RA0");
}
SetPin::~SetPin()
{
}
void SetPin::dataChanged()
{
setCaption( i18n("Set %1 %2").arg(dataString("pin")).arg(dataString("state")) );
}
void SetPin::generateMicrobe( FlowCode *code )
{
const TQString pin = dataString("pin");
const TQString port = "PORT" + TQString((TQChar)pin[1]);
const TQString bit = (TQChar)pin[2];
code->addCode( port+"."+bit+" = "+dataString("state") );
code->addCodeBranch( outputPart("stdoutput") );
#if 0
const TQString pin = dataString("pin");
const bool isHigh = (dataString("state") == "High");
const TQString port = "PORT" + TQString((TQChar)pin[1]);
const TQString bit = (TQChar)pin[2];
TQString newCode;
if (isHigh)
{
newCode += "bsf " + port + "," + bit + " ; Set bit high\n";
}
else
{
newCode += "bcf " + port + "," + bit + " ; Set bit low\n";
}
code->addCodeBlock( id(), newCode );
#endif
}
|