Skip to content

Commit

Permalink
Temporarily disable waveplayer triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiegle committed Sep 25, 2024
1 parent 6e26a93 commit be8d533
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 26 deletions.
78 changes: 57 additions & 21 deletions Source/UI/OneBoxInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ void AdcChannelButton::paintButton (Graphics& g, bool isMouseOver, bool isButton
if (useAsDigitalInput && status == AdcChannelStatus::AVAILABLE)
{
g.fillRect (3, 6, 7, 7);

if (triggersWaveplayer)
{
g.setColour (Colours::black);
g.drawRect (5, 8, 3, 3, 2.0);
}
}

}
Expand Down Expand Up @@ -206,28 +212,41 @@ void OneBoxInterface::comboBoxChanged (ComboBox* comboBox)
bool isOn = (bool) (comboBox->getSelectedId() - 1);
channels[selectedChannel->getChannelIndex()]->useAsDigitalInput = isOn;

if (isOn)
{
triggerSelector->setVisible (true);
}
else
//if (isOn)
//{
// triggerSelector->setVisible (true);
//}
//else
//{
// triggerSelector->setVisible (false);
//}

Array<AdcChannelButton*> channels;

for (auto channel : channels)
{
triggerSelector->setVisible (false);
if (channel->useAsDigitalInput)
{
channels.add (channel);
}
}

wavePlayer->updateAvailableTriggerChannels (channels);

repaint();
}
else if (comboBox == triggerSelector.get())
{
// set trigger
for (auto channel : channels)
{
adc->setTriggersWaveplayer (false,
channel->getChannelIndex());
channel->triggersWaveplayer = false;
}

adc->setTriggersWaveplayer ((bool) (comboBox->getSelectedId() - 1),
selectedChannel->getChannelIndex());
channels[selectedChannel->getChannelIndex()]->triggersWaveplayer = true;
wavePlayer->setTriggerChannel (selectedChannel->getChannelIndex());

repaint();
}
else if (comboBox == mappingSelector.get())
{
Expand All @@ -252,14 +271,14 @@ void OneBoxInterface::buttonClicked (Button* button)
digitalInputSelector->setSelectedId ((int) state, dontSendNotification);
LOGD ("Comparator state: ", (int) state, " for channel ", selectedChannel->getChannelIndex())

if (state == AdcComparatorState::COMPARATOR_ON)
{
triggerSelector->setVisible (true);
}
else
{
triggerSelector->setVisible (false);
}
//if (state == AdcComparatorState::COMPARATOR_ON)
//{
// triggerSelector->setVisible (true);
//}
// else
//{
// triggerSelector->setVisible (false);
//}
triggerSelector->setSelectedId ((int) adc->getTriggersWaveplayer (selectedChannel->getChannelIndex()) + 1, dontSendNotification);

Array<int> availableChannels = adc->getAvailableChannels (selectedChannel->getChannelIndex());
Expand Down Expand Up @@ -288,6 +307,21 @@ void OneBoxInterface::buttonClicked (Button* button)
repaint();
}

void OneBoxInterface::setTriggerChannel(int triggerChannel)
{
for (auto channel : channels)
{
channel->triggersWaveplayer = false;
}

if (triggerChannel > -1)
{
channels[triggerChannel]->triggersWaveplayer = true;
}

repaint();
}

void OneBoxInterface::setAsDac(int channel)
{
if (channel < 0 || channel > 11)
Expand Down Expand Up @@ -349,7 +383,7 @@ void OneBoxInterface::saveParameters (XmlElement* xml)
xmlNode->setAttribute ("index", channel->getChannelIndex());
xmlNode->setAttribute ("input_range", (int) adc->getAdcInputRange());
xmlNode->setAttribute ("comparator_state", (int) adc->getAdcComparatorState (channel->getChannelIndex()));
xmlNode->setAttribute ("triggers_waveplayer", adc->getTriggersWaveplayer (channel->getChannelIndex()));
xmlNode->setAttribute ("triggers_waveplayer", channel->triggersWaveplayer);
xmlNode->setAttribute ("selected", channel == selectedChannel);

//xmlNode->setAttribute("map_to_output", channel->mapToOutput);
Expand Down Expand Up @@ -383,8 +417,10 @@ void OneBoxInterface::loadParameters (XmlElement* xml)

adc->setAdcComparatorState ((AdcComparatorState) comparator_state, index);
channels[index]->useAsDigitalInput = (bool) (comparator_state - 1);
channels[index]->triggersWaveplayer = triggers_waveplayer;

adc->setTriggersWaveplayer (triggers_waveplayer, index);
if (triggers_waveplayer)
wavePlayer->setTriggerChannel (index);
}
}

Expand All @@ -411,7 +447,7 @@ void OneBoxInterface::paint (Graphics& g)
g.drawText ("ADC input range:", 300, 190 - 20, 300, 18, Justification::left, false);
g.drawText ("Use as digital input:", 300, 300 - 20, 300, 18, Justification::left, false);

if (selectedChannel->useAsDigitalInput)
if (false) //selectedChannel->useAsDigitalInput)
{
g.drawText ("Trigger WavePlayer:", 300, 350 - 20, 300, 18, Justification::left, false);
//g.drawText ("Map to output:", 300, 400 - 20, 300, 18, Justification::left, false);
Expand Down
6 changes: 6 additions & 0 deletions Source/UI/OneBoxInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class AdcChannelButton : public ToggleButton
/** Whether ADC channel is using the comparator*/
bool useAsDigitalInput = false;

/** Whether ADC channel triggers the waveplayer */
bool triggersWaveplayer = false;

private:
void paintButton (Graphics& g, bool isMouseOver, bool isButtonDown);

Expand Down Expand Up @@ -124,6 +127,9 @@ class OneBoxInterface : public SettingsInterface,
/** Update combo boxes to reflect available channels */
void updateAvailableChannels();

/** Sets the waveplayer trigger channel */
void setTriggerChannel (int triggerChannel);

/** Set a channel as a DAC (0-11) */
void setAsDac(int channel);

Expand Down
33 changes: 28 additions & 5 deletions Source/UI/WavePlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ void WavePlayerBackground::updateCurrentWaveform (Pattern* pattern)
void WavePlayerBackground::paint (Graphics& g)
{
g.setColour (findColour (ThemeColours::defaultText));
g.drawRect (0, 0, getWidth(), getHeight(), 3.0);
g.drawRect (0, 0, getWidth(), getHeight(), 1.0);

g.setFont (20);
g.drawText ("WavePlayer", 7, 5, 150, 20, Justification::left);

g.setFont (13);
g.drawText ("Trigger channel:", 12, 77, 150, 20, Justification::left);
//g.setFont (13);
//g.drawText ("Trigger channel:", 12, 77, 150, 20, Justification::left);

g.setColour (Colours::orange);
g.strokePath (currentWaveform, PathStrokeType (1.0), pathTransform);
Expand Down Expand Up @@ -110,15 +110,15 @@ WavePlayer::WavePlayer (OneBoxDAC* dac_, OneBoxADC* adc_, OneBoxInterface* ui_)
triggerSelector->setEnabled (false);
triggerSelector->addItem ("NONE", 1);
triggerSelector->setSelectedId (1);
addAndMakeVisible (triggerSelector.get());
//addAndMakeVisible (triggerSelector.get());

enableButton = std::make_unique<UtilityButton> ("DISABLED");
enableButton->setBounds (120, 5, 70, 20);
enableButton->addListener (this);
addAndMakeVisible (enableButton.get());

startStopButton = std::make_unique<UtilityButton> ("RUN");
startStopButton->setBounds (42, 135, 60, 30);
startStopButton->setBounds (42, 105, 60, 30);
startStopButton->addListener (this);
startStopButton->setEnabled (false);
addAndMakeVisible (startStopButton.get());
Expand Down Expand Up @@ -166,6 +166,24 @@ void WavePlayer::resized()
background->setBounds (0, 0, getWidth(), getHeight());
}

void WavePlayer::updateAvailableTriggerChannels(Array <AdcChannelButton*> channels)
{
triggerSelector->clear();
triggerSelector->addItem ("NONE", 1);

for (int i = 0; i < channels.size(); i++)
{
triggerSelector->addItem (channels[i]->getName(), channels[i]->getChannelIndex()+2);
}
}

void WavePlayer::setTriggerChannel(int triggerChannel)
{
currentPattern->triggerChannel = triggerChannel;

triggerSelector->setSelectedId (triggerChannel + 2);
}

float WavePlayer::getSampleRate()
{
// sample rate fixed at 30 kHz
Expand Down Expand Up @@ -252,6 +270,11 @@ void WavePlayer::comboBoxChanged (ComboBox* comboBox)
initializePattern (currentPattern);
}
}
else if (comboBox == triggerSelector.get())
{
currentPattern->triggerChannel = triggerSelector->getSelectedId() - 2;
ui->setTriggerChannel (currentPattern->triggerChannel);
}
}

void WavePlayer::selectPatternType (PatternType t)
Expand Down
7 changes: 7 additions & 0 deletions Source/UI/WavePlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class PulsePatternGenerator;
class SinePatternGenerator;
class CustomPatternGenerator;
class AnalogPatternInfo;
class AdcChannelButton;

/**
Expand Down Expand Up @@ -101,6 +102,12 @@ class WavePlayer : public Component,
/** Updates the waveform to be triggered */
void updateWaveform();

/** Updates available trigger channels (ADCs with comparators enabled) */
void updateAvailableTriggerChannels (Array <AdcChannelButton*> channels);

/** Sets the trigger channel */
void setTriggerChannel(int triggerChannel);

/** Resizes interface */
void resized();

Expand Down

0 comments on commit be8d533

Please sign in to comment.