mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-05-03 21:44:13 +02:00
Dev/ctb clocks fix (#1434)
* introduced new type Hz, typetraits, String conversions, command generation (not yet generated) * incorrect unit typo * cmd generation and compiles * default to MHz, removed space between units for consistency with timers, min and max checks for clks * in python, but need to change the default to Hz again for clean code and intuition * allow ints, doubles, implicit conversions * dont allow raw ints, doubles and implicit conversions * fixed tests * added operators for Hz in python * fix test for min clk for xilinx ctb * fix test * fix python tests * fixed xilinx period and default clks * test fix * removed the 3 clock cycle check for ctb and implemented properly the max adc clk frq for altera ctb * removing 3 clock cycle code from xilinx as well * formatting * loadpattern before 3 clk cycles code * actualtime and measurement time to be implemented in 100ns already in fw * fix tests * pyzmq dependency forthe tests * fixed pyctbgui for freq
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-other
|
||||
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
||||
/*
|
||||
This file contains Python bindings for the Hz and for conversion to other units from and to string.
|
||||
*/
|
||||
#include "py_headers.h"
|
||||
#include <cmath>
|
||||
|
||||
#include "sls/ToString.h"
|
||||
#include "sls/sls_detector_defs.h"
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
constexpr double kHz = 1e3;
|
||||
constexpr double MHz = 1e6;
|
||||
|
||||
void init_freq(py::module &m) {
|
||||
|
||||
py::class_<slsDetectorDefs::Hz> Hz(m, "Hz");
|
||||
Hz.def(py::init<int>());
|
||||
Hz.def_readwrite("value", &slsDetectorDefs::Hz::value);
|
||||
Hz.def("__repr__", [](const slsDetectorDefs::Hz &f) {
|
||||
return sls::ToString(f);
|
||||
});
|
||||
Hz.def("__str__", [](const slsDetectorDefs::Hz &f) {
|
||||
return sls::ToString(f);
|
||||
});
|
||||
|
||||
Hz.def(py::self == py::self);
|
||||
Hz.def("__mul__", [](const slsDetectorDefs::Hz &h, int x) {
|
||||
return slsDetectorDefs::Hz(h.value * x);
|
||||
}, py::is_operator());
|
||||
Hz.def("__rmul__", [](const slsDetectorDefs::Hz &h, int x) {
|
||||
return slsDetectorDefs::Hz(h.value * x);
|
||||
}, py::is_operator());
|
||||
Hz.def("__truediv__", [](const slsDetectorDefs::Hz &h, int x) {
|
||||
return slsDetectorDefs::Hz(h.value / x);
|
||||
}, py::is_operator());
|
||||
Hz.def("__add__", [](const slsDetectorDefs::Hz &a,
|
||||
const slsDetectorDefs::Hz &b) {
|
||||
return slsDetectorDefs::Hz(a.value + b.value);
|
||||
}, py::is_operator());
|
||||
Hz.def("__sub__", [](const slsDetectorDefs::Hz &a,
|
||||
const slsDetectorDefs::Hz &b) {
|
||||
return slsDetectorDefs::Hz(a.value - b.value);
|
||||
}, py::is_operator());
|
||||
|
||||
m.def("kHz", [](double v) {
|
||||
return slsDetectorDefs::Hz(static_cast<int>(std::round(v * kHz)));
|
||||
});
|
||||
|
||||
m.def("MHz", [](double v) {
|
||||
return slsDetectorDefs::Hz(static_cast<int>(std::round(v * MHz)));
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user