mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-27 19:01:02 +00:00
Resync the DeviceCore state models
This commit is contained in:
@@ -12,8 +12,15 @@
|
||||
#include <stdexcept>
|
||||
|
||||
#include <boost/log/trivial.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
/* Sequence Id*/
|
||||
#define STUDIO_START_SEQ_ID 20000
|
||||
#define STUDIO_END_SEQ_ID 30000
|
||||
#define CLOUD_SEQ_ID 0
|
||||
|
||||
namespace Slic3r
|
||||
{
|
||||
|
||||
@@ -27,14 +34,18 @@ public:
|
||||
public:
|
||||
static int get_flag_bits(std::string str, int start, int count = 1);
|
||||
static int get_flag_bits(int num, int start, int count = 1, int base = 10);
|
||||
static uint32_t get_flag_bits_no_border(std::string str, int start_idx, int count = 1);
|
||||
|
||||
// Extract the hex digit at position `pos` (0 = least-significant).
|
||||
// eg. get_hex_bits(16, 1, 10) = 1
|
||||
static int get_hex_bits(int num, int pos, int input_num_base = 10) { return get_flag_bits(num, pos * 4, 4, input_num_base); }
|
||||
static int get_hex_bits(int num, int pos, int input_num_base = 10) { return get_flag_bits(num, pos * 4, 4, input_num_base);};
|
||||
|
||||
static float string_to_float(const std::string& str_value);
|
||||
|
||||
static std::string convertToIp(long long ip);
|
||||
|
||||
// sequence id check
|
||||
static bool is_studio_cmd(int seq) { return seq >= STUDIO_START_SEQ_ID && seq < STUDIO_END_SEQ_ID;};
|
||||
static bool is_cloud_cmd(int seq) { return seq == CLOUD_SEQ_ID;};
|
||||
};
|
||||
|
||||
|
||||
@@ -108,4 +119,94 @@ struct NumericStrCompare
|
||||
}
|
||||
};
|
||||
|
||||
enum class DirtyMode{
|
||||
COUNTER,
|
||||
TIMER
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class DevDirtyHandler{
|
||||
public:
|
||||
DevDirtyHandler(T init_value, int setting_threshold, DirtyMode mode): m_value(init_value), m_setting_threshold(setting_threshold), m_mode(mode)
|
||||
{
|
||||
m_threshold = setting_threshold;
|
||||
}
|
||||
~DevDirtyHandler(){};
|
||||
|
||||
T GetValue() const { return m_value; };
|
||||
|
||||
void SetOptimisticValue(const T& data)
|
||||
{
|
||||
m_value = data;
|
||||
m_start_time = time(nullptr);
|
||||
m_threshold = m_setting_threshold;
|
||||
}
|
||||
|
||||
void UpdateValue(const T& data)
|
||||
{
|
||||
if (m_mode == DirtyMode::COUNTER)
|
||||
{
|
||||
if (m_threshold > 0)
|
||||
m_threshold--;
|
||||
else
|
||||
m_value = data;
|
||||
}
|
||||
else if (m_mode == DirtyMode::TIMER)
|
||||
{
|
||||
if (time(nullptr) - m_start_time > m_threshold)
|
||||
m_value = data;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
T m_value;
|
||||
DirtyMode m_mode;
|
||||
int m_setting_threshold{0};
|
||||
|
||||
int m_start_time{0};
|
||||
int m_threshold{0};
|
||||
};
|
||||
|
||||
|
||||
static std::string s_get_diameter_str(float diameter)
|
||||
{
|
||||
return (boost::format("%.2f") % diameter).str();
|
||||
}
|
||||
|
||||
static std::string s_get_diameter_str(const std::string& diameter)
|
||||
{
|
||||
try {
|
||||
float dia = boost::lexical_cast<float>(diameter);
|
||||
return s_get_diameter_str(dia);
|
||||
} catch (...) {
|
||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " failed to boost::lexical_cast: " << diameter;
|
||||
return diameter;
|
||||
}
|
||||
|
||||
try {
|
||||
float dia = std::stof(diameter);
|
||||
return s_get_diameter_str(dia);
|
||||
} catch (...) {
|
||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " std::stof: " << diameter;
|
||||
return diameter;
|
||||
}
|
||||
}
|
||||
|
||||
static float s_get_diameter(const std::string& diameter)
|
||||
{
|
||||
try {
|
||||
return boost::lexical_cast<float>(diameter);
|
||||
} catch (...) {
|
||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " failed to boost::lexical_cast: " << diameter;
|
||||
}
|
||||
|
||||
try {
|
||||
return std::stof(diameter);
|
||||
} catch (...) {
|
||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " std::stof: " << diameter;
|
||||
}
|
||||
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
}; // namespace Slic3r
|
||||
Reference in New Issue
Block a user