Skip to content

Commit 3edda9d

Browse files
committed
..
1 parent 2f12f83 commit 3edda9d

File tree

4 files changed

+72
-4
lines changed

4 files changed

+72
-4
lines changed

include/compatibility.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
1+
#ifdef CORE_TEENSY
2+
#include <Arduino.h>
3+
#endif
24

35
#ifndef FLASHMEM
46
#define FLASHMEM

include/parameters/Parameter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,7 @@ class DataParameterBase : public FloatParameter {
949949
this->setRangeMinimumLimit(value.toFloat());
950950
return true;
951951
} else if (incoming_key.startsWith(prefix__parameter + label_string + prefix__range_maximum)) {
952+
//Serial.printf("load_parse_key_value(%s, %s) found new value to set in %s: %3.3f\n", incoming_key.c_str(), value.c_str(), this->label, value.toFloat());
952953
this->setRangeMaximumLimit(value.toFloat());
953954
return true;
954955
} else {

include/voltage_sources/PicoSDKADCVoltageSource.h

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ class WorkshopVoltageSource : public WorkshopVoltageSourceBase {
7575
if (!already_succeeded)
7676
Debug_printf("WorkshopVoltageSource#fetch_current_voltage reading from channel %i, check you're using correct address ADC board if crash here!\n", this->channel);
7777

78-
digitalWrite(MX_A, bank & 1);
79-
digitalWrite(MX_B, bank & 2);
78+
gpio_put(MX_A, bank & 1);
79+
gpio_put(MX_B, bank & 2);
8080

8181
// NB this seems to need 1us delay for pins to 'settle' before reading.
8282
sleep_us(1);
@@ -115,4 +115,69 @@ class WorkshopVoltageSource : public WorkshopVoltageSourceBase {
115115

116116
};
117117

118+
#include "ComputerCard.h"
119+
120+
class ComputerCardVoltageSource : public WorkshopVoltageSourceBase {
121+
public:
122+
byte channel = 0;
123+
ComputerCard *sw = nullptr;
124+
125+
ComputerCardVoltageSource(int global_slot, ComputerCard *sw, byte channel, float maximum_input_voltage = 5.0, bool supports_pitch = false)
126+
: WorkshopVoltageSourceBase(global_slot, supports_pitch) {
127+
this->sw = sw;
128+
this->channel = channel;
129+
this->maximum_input_voltage = maximum_input_voltage;
130+
//this->debug = true;
131+
}
132+
133+
// returns the last read raw voltage value
134+
virtual float get_voltage() override {
135+
//this->update();
136+
return this->current_value;
137+
}
138+
139+
bool already_succeeded = false;
140+
virtual float fetch_current_voltage() override {
141+
if (this->debug) {
142+
Serial.printf("in WorkshopVoltageSource#fetch_current_voltage(slot=%i, channel=%i)..", global_slot, channel);
143+
//Debug_printf(F("\tads_source is @%p, reading from channel %i\n"), this->ads_source, this->channel);
144+
}
145+
if (!already_succeeded)
146+
Debug_printf("WorkshopVoltageSource#fetch_current_voltage reading from channel %i, check you're using correct address ADC board if crash here!\n", this->channel);
147+
148+
149+
int adcReading = channel < 3 ? sw->KnobVal((ComputerCard::Knob)channel) :
150+
channel==3 ? sw->SwitchVal() : sw->CVIn(channel-4);
151+
152+
float voltageFromAdc = this->adcread_to_voltage(adcReading);
153+
154+
if (this->debug) {
155+
Serial.printf("WorkshopVoltageSource channel %i read ADC voltageFromAdc %i\t :", channel, adcReading); Serial_flush();
156+
}
157+
158+
float voltageCorrected = this->get_corrected_voltage(voltageFromAdc);
159+
160+
if (this->debug) {
161+
Serial.print(F(" after correction stage 2 got "));
162+
Serial.println(voltageCorrected);
163+
}
164+
165+
if (this->debug) Serial.printf("in WorkshopVoltageSource#fetch_current_voltage() finishing (and returning %f)\n", voltageCorrected);
166+
167+
return maximum_input_voltage - voltageCorrected;
168+
}
169+
170+
virtual float adcread_to_voltage(int16_t adcReading) {
171+
float voltageFromAdc = float(adcReading) * (maximum_input_voltage / 4095.0); // 12 bit ADC, 0-4095
172+
return voltageFromAdc;
173+
}
174+
175+
virtual float get_corrected_voltage(float voltageFromAdc) {
176+
return (voltageFromAdc * correction_value_1) + correction_value_2;
177+
//return (voltageFromAdc + correction_value_2) * correction_value_1;
178+
//return (voltageFromAdc - 0.25) * 2.0;
179+
}
180+
181+
};
182+
118183
#endif

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "parameters",
3-
"version": "0.0.43.1",
3+
"version": "0.0.43.2",
44
"repository":
55
{
66
"type": "git",

0 commit comments

Comments
 (0)