-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathR_gen.hpp
59 lines (49 loc) · 1.4 KB
/
R_gen.hpp
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
#pragma once
#include <QString>
struct Resistance
{
uint64_t value;
char const* display_text;
const char* jlc_part_number;
operator double() const
{
return value;
};
Resistance(const Resistance&) = default;
Resistance(uint64_t value) : value(value), display_text(0), jlc_part_number(0){}
Resistance(uint64_t value, const char* d, const char* jlc) : value(value), display_text(d), jlc_part_number(jlc){}
operator QString() const
{
if (display_text)
return QString::fromUtf8(display_text);
if (value<1000)
return QString("%1Ω").arg(value);
if (value<1000000)
{
if (value / 1000 * 1000 == value)
return QString("%1kΩ").arg(value/1000);
else
return QString("%1kΩ").arg(value/1000.0f);
}
if (value<1000000000)
{
if (value / 1000000 * 1000000 == value)
return QString("%1kΩ").arg(value/1000);
else
return QString("%1MΩ").arg(value/1000000);
}
return QString("%1MΩ").arg(value/1000000);
}
};
struct R_lib
{
enum R_type {
good_R, // 1%
regular_R, // 5%
free_R, // jlc free R
} current_type;
R_lib(int _type) : current_type((R_type)_type)
{}
Resistance operator()(int idx) const;
int get_R_counts() const;
};