File indexing completed on 2024-10-13 05:05:20
0001 /*************************************************************************** 0002 * Copyright (C) 2003-2005 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 #ifndef MICROSETTINGS_H 0012 #define MICROSETTINGS_H 0013 0014 #include <QObject> 0015 #include <QVariant> 0016 0017 class QString; 0018 class QVariant; 0019 class MicroData; 0020 class MicroInfo; 0021 0022 class VariableInfo 0023 { 0024 public: 0025 VariableInfo(); 0026 0027 // Returns the value as a string 0028 QString valueAsString() const; 0029 0030 // MicroSettings::VariableType (don't rely on this just yet...) 0031 int type; 0032 0033 // Sets the value 0034 void setValue(const QVariant &value); 0035 0036 // If true, the variable will be initialised at the start of the FlowCode 0037 // to the given value 0038 bool initAtStart; 0039 0040 // True if the variable was "created" by the user in the variable dialog, 0041 // as opposed to being from a variable name entry box 0042 bool permanent; 0043 0044 private: 0045 QVariant value; 0046 }; 0047 0048 typedef QMap<QString, VariableInfo> VariableMap; // Variable name, variable info 0049 0050 /** 0051 @short Stores pic pin settings - type/state 0052 @author David Saxton 0053 */ 0054 class PinSettings : public QObject 0055 { 0056 Q_OBJECT 0057 public: 0058 enum pin_type { pt_input, pt_output }; 0059 0060 enum pin_state { ps_on, ps_off }; 0061 0062 PinSettings(); 0063 PinSettings(PinSettings::pin_type _type, PinSettings::pin_state _state, const QString &id, const QString &port); 0064 0065 PinSettings::pin_type type() const 0066 { 0067 return m_type; 0068 } 0069 PinSettings::pin_state state() const 0070 { 0071 return m_state; 0072 } 0073 QString id() const 0074 { 0075 return m_id; 0076 } 0077 QString port() const 0078 { 0079 return m_port; 0080 } 0081 0082 void setType(PinSettings::pin_type type); 0083 void setState(PinSettings::pin_state state); 0084 0085 signals: 0086 /** 0087 * Emitted when either the type or the state is changed. 0088 */ 0089 void settingsChanged(); 0090 0091 private: 0092 PinSettings::pin_type m_type; 0093 PinSettings::pin_state m_state; 0094 QString m_id; 0095 QString m_port; 0096 }; 0097 typedef QList<PinSettings *> PinSettingsList; 0098 0099 class PinMapping; 0100 typedef QMap<QString, PinMapping> PinMappingMap; 0101 typedef QMap<QString, PinSettingsList> PortList; 0102 0103 /** 0104 This class stores PIC settings that are specific to the PIC program being devloped. 0105 This includes such things as port settings and variable settings. 0106 This is different from PIC info, which includes stuff such as PIC pin names 0107 0108 @short Stores Pic settings - pin settings 0109 @author David Saxton 0110 */ 0111 class MicroSettings : public QObject 0112 { 0113 Q_OBJECT 0114 public: 0115 enum VariableType { vt_signedInteger, vt_unsignedInteger, vt_unknown }; 0116 MicroSettings(MicroInfo *microInfo); 0117 ~MicroSettings() override; 0118 /** 0119 * Returns microdata to describe the microsettings. 0120 * This includes ports settins and variable settings 0121 */ 0122 MicroData microData() const; 0123 void restoreFromMicroData(const MicroData µData); 0124 /** 0125 * Returns a pointer to the MicroInfo object for the PIC in use 0126 */ 0127 MicroInfo *microInfo() const 0128 { 0129 return _microInfo; 0130 } 0131 /** 0132 * Set the pin with the given id to the given initial type (input/output) 0133 */ 0134 void setPinType(const QString &id, PinSettings::pin_type type); 0135 /** 0136 * Set the pin with the given id to the given initial state (on/off) 0137 */ 0138 void setPinState(const QString &id, PinSettings::pin_state state); 0139 /** 0140 * Returns a pointer to the PinSettings for the pin with the given id, 0141 * or null if no such pin exists. 0142 */ 0143 PinSettings *pinWithID(const QString &id); 0144 /** 0145 * Returns the initial port state (on/off) for the given port. 0146 * Each pin state occupies one bit of the returned integer. 0147 */ 0148 int portState(const QString &port); 0149 /** 0150 * Sets the port with the given name to the given state 0151 */ 0152 void setPortState(const QString &port, int state); 0153 /** 0154 * Sets the port with the given name to the given type 0155 */ 0156 void setPortType(const QString &port, int type); 0157 /** 0158 * Returns the initial port type (intput/output) for the given port. 0159 * Each pin type occupies one bit of the returned integer. 0160 */ 0161 int portType(const QString &port); 0162 /** 0163 * Sets the variable "name" to the initial value "value. If the variable 0164 * already exists, its value will be changed. Else, the variable will be 0165 * created. 0166 */ 0167 void setVariable(const QString &name, QVariant value, bool permanent = true); 0168 /** 0169 * Returns the list of initial variables as a QStringList, just the names 0170 * without the values. Generated from the VariableMap m_variables. 0171 */ 0172 QStringList variableNames(); 0173 /** 0174 * Returns a pointer to the variable info with the given name, or nullptr 0175 * if the variable is not found 0176 */ 0177 VariableInfo *variableInfo(const QString &name); 0178 /** 0179 * Deletes the variable with the given name, returns true if successul 0180 * (i.e. a variable with that name existed), or false if not 0181 */ 0182 bool deleteVariable(const QString &name); 0183 /** 0184 * Removes all variables 0185 */ 0186 void removeAllVariables(); 0187 /** 0188 * Sets the list of Pin Mappings to that given. 0189 */ 0190 void setPinMappings(const PinMappingMap &pinMappings); 0191 /** 0192 * Returns the pic pin mapping with the given id. 0193 */ 0194 PinMapping pinMapping(const QString &id) const; 0195 /** 0196 * Returns the list of different Pin Mappings; 0197 */ 0198 PinMappingMap pinMappings() const; 0199 0200 signals: 0201 void pinMappingsChanged(); 0202 0203 private: 0204 PinMappingMap m_pinMappings; 0205 PinSettingsList m_pinSettingsList; 0206 MicroInfo *_microInfo; 0207 VariableMap m_variableMap; 0208 PortList m_ports; 0209 }; 0210 0211 #endif