almost ready to merge into master
[avrdudequi:avrdudequi.git] / fusebyte.cpp
1 #include "fusebyte.h"
2 #include "fusewidget.h"
3 #include <QGroupBox>
4 #include <QPushButton>
5 #include <QLabel>
6 #include <QDebug>
7
8 FuseByte::FuseByte(QObject *parent) :
9     QObject(parent), mcuWidget(0), cBoxLowFuse(0),
10     cBoxHighFuse(0), cBoxExtendedFuse(0)
11 {
12 }
13
14 FuseByte::~FuseByte()
15 {
16
17 }
18
19 void FuseByte::widgetInit(QWidget *w)
20 {
21     mcuWidget = w;
22
23     QGroupBox *gBoxLFuse = mcuWidget->findChild<QGroupBox*>("gBoxLFuse");
24     qDebug() << "gBoxLFuse" << gBoxLFuse;
25     if (gBoxLFuse) {
26
27         lowFuseWidget = new FuseWidget(gBoxLFuse, FuseWidget::Low, this);
28         QLabel *lLFcurrentValue = w->findChild<QLabel *>("lLFcurrentValue");
29         if (lLFcurrentValue)
30             lowFuseWidget->setLabelValue(lLFcurrentValue);
31         QComboBox *cBox = w->findChild<QComboBox*>("cBoxLowFuse");
32         if (cBox)
33             lowFuseWidget->appendComboBox(cBox);
34         QComboBox *cBox1 = w->findChild<QComboBox*>("cBoxLowFuse1");
35         if (cBox1)
36             lowFuseWidget->appendComboBox(cBox1);
37         QPushButton *pButtonLFuseReset = w->findChild<QPushButton*>("pButtonLFuseReset");
38         // connette il pulsante solo se esiste
39         if (pButtonLFuseReset)
40             connect(pButtonLFuseReset, SIGNAL(clicked()), this, SLOT(resetLowFuse()));
41
42     }
43
44     QGroupBox *gBoxHFuse = mcuWidget->findChild<QGroupBox*>("gBoxHFuse");
45     if (gBoxHFuse) {
46         highFuseWidget = new FuseWidget(gBoxHFuse, FuseWidget::High, this);
47         QLabel *lHFcurrentValue = w->findChild<QLabel *>("lHFcurrentValue");
48         if (lHFcurrentValue)
49             highFuseWidget->setLabelValue(lHFcurrentValue);
50         QComboBox *cBox = w->findChild<QComboBox*>("cBoxHighFuse");
51         if (cBox)
52             highFuseWidget->appendComboBox(cBox);
53         QComboBox *cBox1 = w->findChild<QComboBox*>("cBoxHighFuse1");
54         if (cBox1)
55             highFuseWidget->appendComboBox(cBox1);
56
57         QPushButton *pButtonHFuseReset = w->findChild<QPushButton*>("pButtonHFuseReset");
58         // connette il pulsante solo se esiste
59         if (pButtonHFuseReset)
60             connect(pButtonHFuseReset, SIGNAL(clicked()), this, SLOT(resetHighFuse()));
61
62     }
63     QGroupBox *gBoxEFuse = mcuWidget->findChild<QGroupBox*>("gBoxEFuse");
64
65     if (gBoxEFuse) {
66         extendedFuseWidget = new FuseWidget(gBoxEFuse, FuseWidget::Extended, this);
67         QLabel *lEFcurrentValue = w->findChild<QLabel *>("lEFcurrentValue");
68         if (lEFcurrentValue)
69             extendedFuseWidget->setLabelValue(lEFcurrentValue);
70
71         QComboBox *cBox = w->findChild<QComboBox*>("cBoxExtendedFuse");
72         if (cBox)
73             extendedFuseWidget->appendComboBox(cBox);
74
75         QComboBox *cBox1 = w->findChild<QComboBox*>("cBoxExtendedFuse1");
76         if (cBox1)
77             extendedFuseWidget->appendComboBox(cBox1);
78
79         QPushButton *pButtonEFuseReset = w->findChild<QPushButton*>("pButtonEFuseReset");
80         // connette il pulsante solo se esiste
81         if (pButtonEFuseReset)
82             connect(pButtonEFuseReset, SIGNAL(clicked()), this, SLOT(resetExtendedFuse()));
83
84     }
85
86 }
87
88 void FuseByte::setFuseValue(QMap<QString, QString> &fuses)
89 {
90     //qDebug() << "fuse map:" << fuses;
91     if (lowFuseWidget)
92         lowFuseWidget->setFuseValue(fuses.value("lfuse").toUInt(0,16));
93     if (highFuseWidget)
94         highFuseWidget->setFuseValue(fuses.value("hfuse").toUInt(0,16));
95     if (extendedFuseWidget)
96         extendedFuseWidget->setFuseValue(fuses.value("efuse").toUInt(0,16));
97
98 }
99
100 QList<QMap<QString, QString> > FuseByte::getAllFuses()
101 {
102
103     QList<QMap<QString, QString> > m_allFuses;
104     QMap<QString, QString> m_fuses;
105     if (lowFuseWidget) {
106         m_fuses.insert("FuseArg",lowFuseWidget->getFuseArg());
107         m_fuses.insert("FuseValue", lowFuseWidget->getFuseValueInHex());
108         m_allFuses.append(m_fuses);
109
110         //allFuse = "-U " + lowFuseWidget->getFuseArg() + ":w:" + lowFuseWidget->getFuseValueInHex() + ":m";
111     }
112     if (highFuseWidget) {
113         m_fuses.insert("FuseArg",highFuseWidget->getFuseArg());
114         m_fuses.insert("FuseValue", highFuseWidget->getFuseValueInHex());
115         m_allFuses.append(m_fuses);
116     }
117     //qDebug() << "m_allFuses" << m_allFuses;
118     if (extendedFuseWidget) {
119         m_fuses.insert("FuseArg", extendedFuseWidget->getFuseArg());
120         m_fuses.insert("FuseValue", extendedFuseWidget->getFuseValueInHex());
121         m_allFuses.append(m_fuses);
122     }
123
124     return m_allFuses;
125 }
126
127 void FuseByte::resetLowFuse()
128 {
129     lowFuseWidget->resetValue();
130 }
131
132 void FuseByte::resetHighFuse()
133 {
134     highFuseWidget->resetValue();
135 }
136
137 void FuseByte::resetExtendedFuse()
138 {
139     extendedFuseWidget->resetValue();
140
141 }