summaryrefslogtreecommitdiffstats
path: root/src/microsettings.h
blob: d960f106a41997b1ed5a780a95639000a209707b (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/***************************************************************************
 *   Copyright (C) 2003-2005 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.                                   *
 ***************************************************************************/

#ifndef MICROSETTINGS_H
#define MICROSETTINGS_H

#include <qobject.h>
#include <qvariant.h>

class QString;
class QVariant;
class MicroData;
class MicroInfo;

class VariableInfo
{
public:
	VariableInfo();
	
	// Returns the value as a string
	QString valueAsString() const;
	
	// MicroSettings::VariableType (don't rely on this just yet...)
	int type;
	
	// Sets the value
	void setValue( const QVariant & value );
	
	// If true, the variable will be initialised at the start of the FlowCode
	// to the given value
	bool initAtStart;
	
	// True if the variable was "created" by the user in the variable dialog,
	// as opposed to being from a variable name entry box
	bool permanent;
	
private:
	QVariant value;
};


typedef QMap< QString, VariableInfo > VariableMap; // Variable name, variable info


/**
@short Stores pic pin settings - type/state
@author David Saxton
*/
class PinSettings : public QObject
{
	Q_OBJECT
	public:
		enum pin_type
		{
			pt_input,
			pt_output
		};
	
		enum pin_state
		{
			ps_on,
			ps_off
		};
	
		PinSettings();
		PinSettings( PinSettings::pin_type _type, PinSettings::pin_state _state, const QString &id, const QString &port );
	
		PinSettings::pin_type type() const { return m_type; }
		PinSettings::pin_state state() const { return m_state; }
		QString id() const { return m_id; }
		QString port() const { return m_port; }
	
		void setType( PinSettings::pin_type type );
		void setState( PinSettings::pin_state state );
		
	signals:
		/**
		 * Emitted when either the type or the state is changed.
		 */
		void settingsChanged();
	
	private:
		PinSettings::pin_type m_type;
		PinSettings::pin_state m_state;
		QString m_id;
		QString m_port;
};
typedef QValueList<PinSettings*> PinSettingsList;

class PinMapping;
typedef QMap< QString, PinMapping > PinMappingMap;
typedef QMap< QString, PinSettingsList > PortList;

/**
This class stores PIC settings that are specific to the PIC program being devloped. 
This includes such things as port settings and variable settings.
This is different from PIC info, which includes stuff such as PIC pin names

@short Stores Pic settings - pin settings
@author David Saxton
*/
class MicroSettings : public QObject
{
	Q_OBJECT
public:
    enum VariableType
	{
    	vt_signedInteger,
		vt_unsignedInteger,
		vt_unknown
	};
    MicroSettings( MicroInfo *microInfo );
    ~MicroSettings();
	/**
	 * Returns microdata to describe the microsettings.
	 * This includes ports settins and variable settings
	 */
	MicroData microData() const;
	void restoreFromMicroData( const MicroData &microData );
	/**
	 * Returns a pointer to the MicroInfo object for the PIC in use
	 */
	MicroInfo *microInfo() const { return _microInfo; }
	/**
	 * Set the pin with the given id to the given initial type (input/output)
	 */
	void setPinType( const QString &id, PinSettings::pin_type type );
	/**
	 * Set the pin with the given id to the given initial state (on/off)
	 */
	void setPinState( const QString &id, PinSettings::pin_state state );
	/**
	 * Returns a pointer to the PinSettings for the pin with the given id,
	 * or null if no such pin exists.
	 */
	PinSettings* pinWithID( const QString &id );
	/**
	 * Returns the initial port state (on/off) for the given port.
	 * Each pin state occupies one bit of the returned integer. 
	 */
	int portState( const QString &port );
	/**
	 * Sets the port with the given name to the given state
	 */
	void setPortState( const QString &port, int state );
	/**
	 * Sets the port with the given name to the given type
	 */
	void setPortType( const QString &port, int type );
	/**
	 * Returns the initial port type (intput/output) for the given port.
	 * Each pin type occupies one bit of the returned integer. 
	 */
	int portType( const QString &port );
	/**
	 * Sets the variable "name" to the initial value "value. If the variable
	 * already exists, its value will be changed. Else, the variable will be
	 * created.
	 */
	void setVariable( const QString &name, QVariant value, bool permanent = true );
	/**
	 * Returns the list of initial variables as a QStringList, just the names
	 * without the values. Generated from the VariableMap m_variables.
	 */
	QStringList variableNames();
	/**
	 * Returns a pointer to the variable info with the given name, or NULL
	 * if the variable is not found
	 */
	VariableInfo *variableInfo( const QString &name );
	/**
	 * Deletes the variable with the given name, returns true if successul
	 * (i.e. a variable with that name existed), or false if not
	 */
	bool deleteVariable( const QString &name );
	/**
	 * Removes all variables
	 */
	void removeAllVariables();
	/**
	 * Sets the list of Pin Mappings to that given.
	 */
	void setPinMappings( const PinMappingMap & pinMappings );
	/**
	 * Returns the pic pin mapping with the given id.
	 */
	PinMapping pinMapping( const QString & id ) const;
	/**
	 * Returns the list of different Pin Mappings;
	 */
	PinMappingMap pinMappings() const;
	
signals:
	void pinMappingsChanged();
	
private:
	PinMappingMap m_pinMappings;
	PinSettingsList m_pinSettingsList;
	MicroInfo *_microInfo;
	VariableMap m_variableMap;
	PortList m_ports;
};

#endif