17 #ifndef MODULARELECTRONICS_UTILS_h_
18 #define MODULARELECTRONICS_UTILS_h_
66 namespace interface_utils {
75 String cmd_element =
"";
77 while (received !=
'\r') {
78 if(Serial.available()) {
79 received = Serial.read();
80 if (received ==
'\n' || received ==
' ') {
81 }
else if (received ==
',' || received ==
'\r' || received ==
':') {
82 cmd[cmd_size] = cmd_element;
86 cmd_element += received;
99 for (uint8_t index = 0; index < string_in.length(); ++index) {
100 array_out[index] = String(string_in[index]).toInt();
102 return string_in.length();
112 String array_out[], uint8_t n_shift) {
113 for (uint8_t index = 0; index < array_in_size; ++index) {
114 array_out[index] = array_in[index + n_shift];
126 namespace meas_utils {
143 template <
typename T1,
typename T2>
145 uint8_t dac_channels[], uint8_t n_dac_channels,
146 uint8_t adc_channels[], uint8_t n_adc_channels,
147 double start_voltages[],
double end_voltages[],
148 uint32_t n_steps, uint32_t step_delay,
149 uint8_t delay_unit=0) {
153 for (uint32_t step = 0; step < n_steps; step++) {
155 for (uint8_t dac_channel_index = 0;
156 dac_channel_index < n_dac_channels;
157 dac_channel_index++) {
158 uint8_t channel = dac_channels[dac_channel_index];
159 double start_voltage = start_voltages[dac_channel_index];
160 double end_voltage = end_voltages[dac_channel_index];
162 double next_voltage = start_voltage +
163 (end_voltage - start_voltage) * step / (n_steps - 1);
165 dac.SetVoltage(channel, next_voltage,
false);
168 dac.UpdateAnalogOutputs();
170 if (delay_unit == 0) {
171 delayMicroseconds(step_delay);
177 for (uint8_t adc_channel_index = 0;
178 adc_channel_index < n_adc_channels;
179 adc_channel_index++) {
180 uint8_t channel = adc_channels[adc_channel_index];
184 if (step > 0 || adc_channel_index > 0) {
186 n_meas = adc.ReadVoltage(channel, meas,
true);
190 n_meas = adc.ReadVoltage(channel, meas,
false);
195 for (uint8_t meas_index = 0; meas_index < n_meas; meas_index++) {
196 Serial.write(meas[meas_index]);
uint8_t block_size
Definition: utils.h:50
void shift_array_left(String array_in[], uint8_t array_in_size, String array_out[], uint8_t n_shift)
Definition: utils.h:111
uint8_t string_to_int_array(String string_in, uint8_t array_out[])
Definition: utils.h:98
static const uint8_t kdata_len_
Definition: utils.h:39
uint8_t n_blocks
Definition: utils.h:55
uint8_t BufferRamp(T1 dac, T2 adc, uint8_t dac_channels[], uint8_t n_dac_channels, uint8_t adc_channels[], uint8_t n_adc_channels, double start_voltages[], double end_voltages[], uint32_t n_steps, uint32_t step_delay, uint8_t delay_unit=0)
Definition: utils.h:144
uint8_t query_serial(String cmd[])
Definition: utils.h:73
byte msg[kdata_len_]
Definition: utils.h:44