-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresinsetting.cpp
More file actions
138 lines (112 loc) · 4.86 KB
/
resinsetting.cpp
File metadata and controls
138 lines (112 loc) · 4.86 KB
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
#include "resinsetting.h"
#include <QFile>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QDebug>
#include <stdexcept>
using namespace Hix::Common;
const QString _resinPath = "/opt/capsuleFW/resin/";
ResinSetting::ResinSetting(QString resin) : Json::JsonSetting(_resinPath + resin + ".json")
// ,_layerHeight(layerHeight)
{
}
ResinSetting::~ResinSetting()
{
}
void ResinSetting::parse()
{
try {
for(auto &i : _object.keys()){
if(i == "last_update"){
lastUpdate = Hix::Common::Json::getValue<QString>(_object,"last_update");
}else{
resinInfo ri;
QJsonObject jo = Hix::Common::Json::getValue<QJsonObject>(_object,i);
ri.resinLedOffset = Hix::Common::Json::getValue<double>(jo,"led_offset");
ri.contractionRatio = Hix::Common::Json::getValue<double>(jo,"contraction_ratio");
ri.layerHeight = Hix::Common::Json::getValue<double>(jo,"layer_height");
ri.bedCuringLayer = Hix::Common::Json::getValue<int>(jo,"bed_curing_layer");
ri.curingTime = Hix::Common::Json::getValue<int>(jo,"curing_time");
ri.zHopHeight = Hix::Common::Json::getValue<int>(jo,"z_hop_height");
ri.maxSpeed = Hix::Common::Json::getValue<int>(jo,"max_speed");
ri.initSpeed = Hix::Common::Json::getValue<int>(jo,"init_speed");
ri.upAccelSpeed = Hix::Common::Json::getValue<int>(jo,"up_accel_speed");
ri.upDecelSpeed = Hix::Common::Json::getValue<int>(jo,"up_decel_speed");
ri.downAccelSpeed = Hix::Common::Json::getValue<int>(jo,"down_accel_speed");
ri.downDecelSpeed = Hix::Common::Json::getValue<int>(jo,"down_decel_speed");
ri.bedCuringTime = Hix::Common::Json::getValue<int>(jo,"bed_curing_time");
ri.layerDelay = Hix::Common::Json::getValue<int>(jo,"layer_delay");
ri.material = Hix::Common::Json::getValue<int>(jo,"material");
resinList.insert(i,ri);
}
}
} catch (std::runtime_error &e) {
qDebug() << e.what();
}
}
QString ResinSetting::serialize()
{
save();
QJsonDocument doc(_object);
return doc.toJson();
}
void ResinSetting::save()
{
QJsonObject jo;
QFile saveFile(_path);
Json::setValue<QString>(jo,"last_update",lastUpdate);
for(auto &i : resinList.keys()){
QJsonObject resinObject;
Hix::Common::Json::setValue<double>(resinObject,"led_offset",resinList[i].resinLedOffset);
Hix::Common::Json::setValue<double>(resinObject,"contraction_ratio",resinList[i].contractionRatio);
Hix::Common::Json::setValue<double>(resinObject,"layer_height",resinList[i].layerHeight);
Hix::Common::Json::setValue<int>(resinObject,"bed_curing_layer",resinList[i].bedCuringLayer);
Hix::Common::Json::setValue<int>(resinObject,"curing_time",resinList[i].curingTime);
Hix::Common::Json::setValue<int>(resinObject,"z_hop_height",resinList[i].zHopHeight);
Hix::Common::Json::setValue<int>(resinObject,"max_speed",resinList[i].maxSpeed);
Hix::Common::Json::setValue<int>(resinObject,"init_speed",resinList[i].initSpeed);
Hix::Common::Json::setValue<int>(resinObject,"up_accel_speed",resinList[i].upAccelSpeed);
Hix::Common::Json::setValue<int>(resinObject,"up_decel_speed",resinList[i].upDecelSpeed);
Hix::Common::Json::setValue<int>(resinObject,"down_accel_speed",resinList[i].downAccelSpeed);
Hix::Common::Json::setValue<int>(resinObject,"down_decel_speed",resinList[i].downDecelSpeed);
Hix::Common::Json::setValue<int>(resinObject,"bed_curing_time",resinList[i].bedCuringTime);
Hix::Common::Json::setValue<int>(resinObject,"layer_delay",resinList[i].layerDelay);
Hix::Common::Json::setValue<int>(resinObject,"material",resinList[i].material);
Hix::Common::Json::setValue<QJsonObject>(jo,i,resinObject);
}
if(!saveFile.open(QIODevice::WriteOnly)){
qDebug() << "save file open error";
}
_object = jo;
QJsonDocument saveDoc(jo);
saveFile.write(saveDoc.toJson());
}
bool ResinSetting::removeFile()
{
QFile reFile(_path);
reFile.setFileName(_path);
if(reFile.exists()){
if(reFile.remove()){
qDebug() << "file remove " << _path;
return true;
}else{
qDebug() << "cannot remove this file " << _path;
return false;
}
}else{
qDebug() << "cannot remove this file : does not exist " << _path;
return false;
}
}
bool ResinSetting::createFile()
{
QFile loadFile(_path);
if(!loadFile.open(QIODevice::ReadWrite)){
qDebug() << "Could not open json file to ReadWrite " << _path;
qDebug() << loadFile.errorString();
return false;
}else{
return true;
}
}