summaryrefslogtreecommitdiffstats
path: root/src/flowparts/pulse.cpp
blob: 77f9dd067a8763b7a8eae2cd402562e60aabc635 (plain)
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
/***************************************************************************
 *   Copyright (C) 2003 by David Saxton                                    *
 *   [email protected]                                                    *
 *                                                                         *
 *   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 "libraryitem.h"
#include "flowcode.h"
#include "pulse.h"

#include <klocale.h>

Item* Pulse::construct( ItemDocument *itemDocument, bool newItem, const char *id )
{
	return new Pulse( (ICNDocument*)itemDocument, newItem, id );
}

LibraryItem* Pulse::libraryItem()
{
	return new LibraryItem(
		TQString("flow/pulse"),
		i18n("Pulse"),
		i18n("Functions"),
		"pppulse.png",
		LibraryItem::lit_flowpart,
		Pulse::construct
			);
}

Pulse::Pulse( ICNDocument *icnDocument, bool newItem, const char *id )
	: FlowPart( icnDocument, newItem, (id) ? id : "pulse" )
{
	m_name = i18n("Pulse");
	m_desc = i18n("Pulse a pin high/low for a given duration.");
	initProcessSymbol();
	createStdInput();
	createStdOutput();
	
	createProperty( "0-duration", Variant::Type::Double );
	property("0-duration")->setCaption( i18n("Duration") );
	property("0-duration")->setUnit("sec");
	property("0-duration")->setValue(2.0);
	
	createProperty( "1-high", Variant::Type::Double );
	property("1-high")->setCaption( i18n("High Time") );
	property("1-high")->setUnit("sec");
	property("1-high")->setValue(0.5);
	
	createProperty( "2-low", Variant::Type::Double );
	property("2-low")->setCaption( i18n("High Time") );
	property("2-low")->setUnit("sec");
	property("2-low")->setValue(0.5);
	
	createProperty( "3-pin", Variant::Type::Pin );
	property("3-pin")->setCaption( i18n("Pin") );
	property("3-pin")->setValue("RA0");
}

Pulse::~Pulse()
{
}


void Pulse::dataChanged()
{
	double pulse = dataDouble("0-duration");
	setCaption( i18n("Pulse %1 for %2 sec").arg(dataString("3-pin")).arg(TQString::number( pulse / getMultiplier(pulse), 'f', 1 ) + getNumberMag(pulse)) );
}

void Pulse::generateMicrobe( FlowCode *code )
{
	const double duration_ms = dataDouble("0-duration")*1e3;
	const double high_ms = dataDouble("1-high")*1e3;
	const double low_ms = dataDouble("2-low")*1e3;
	const TQString pin = dataString("3-pin");
	
	// TODO Do we want to change the format for pulsing?
	code->addCode( "pulse "+pin+" "+TQString::number(duration_ms)+" "+TQString::number(high_ms)+" "+TQString::number(low_ms) );
	code->addCodeBranch( outputPart("stdoutput") );
}