Skip to content

Commit

Permalink
ParseChannelTypeFromString: Generalize WB_ParseStimulusType
Browse files Browse the repository at this point in the history
  • Loading branch information
t-b committed Jan 17, 2024
1 parent cc80b47 commit 402d327
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 40 deletions.
35 changes: 9 additions & 26 deletions Packages/MIES/MIES_DAEphys.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -4214,32 +4214,15 @@ Function DAP_ParsePanelControl(ctrl, channelIndex, channelType, controlType)
break
endswitch

strswitch(elem1)
case "DataAcqHS":
channelType = CHANNEL_TYPE_HEADSTAGE
break
case "DA":
channelType = CHANNEL_TYPE_DAC
break
case "AD":
channelType = CHANNEL_TYPE_ADC
break
case "TTL":
channelType = CHANNEL_TYPE_TTL
break
case "AsyncAlarm":
channelType = CHANNEL_TYPE_ALARM
break
case "AsyncAD":
channelType = CHANNEL_TYPE_ASYNC
break
default:
channelIndex = NaN
channelType = NaN
controlType = NaN
return 1
break
endswitch
channelType = ParseChannelTypeFromString(elem1, allowFail = 1)

if(IsNaN(channelType))
channelIndex = NaN
channelType = NaN
controlType = NaN

return 1
endif

strswitch(elem2)
case "All":
Expand Down
27 changes: 27 additions & 0 deletions Packages/MIES/MIES_MiesUtilities.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,33 @@ Function/S ChannelTypeToString(variable channelType)
endswitch
End

/// @brief Convert a channel type string from ChannelTypeToString to one of the constants from @ref ChannelTypeAndControlConstants
///
/// @param channelType channel type
/// @param allowFail [optional, defaults to false] return NaN on unknown channel types (true) or assert (false)
Function ParseChannelTypeFromString(string channelType, [variable allowFail])

allowFail = ParamIsDefault(allowFail) ? 0 : !!allowFail

strswitch(channelType)
case "DataAcqHS":
return CHANNEL_TYPE_HEADSTAGE
case "DA":
return CHANNEL_TYPE_DAC
case "AD":
return CHANNEL_TYPE_ADC
case "TTL":
return CHANNEL_TYPE_TTL
case "AsyncAlarm":
return CHANNEL_TYPE_ALARM
case "AsyncAD":
return CHANNEL_TYPE_ASYNC
default:
ASSERT(allowFail, "Invalid channelType")
return NaN
endswitch
End

/// @brief Returns the name of a control from the DA_EPHYS panel
///
/// Constants are defined at @ref ChannelTypeAndControlConstants
Expand Down
14 changes: 1 addition & 13 deletions Packages/MIES/MIES_WaveBuilder.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -2718,18 +2718,6 @@ static Function WB_CheckForEmptyEpochs(string setname)
return 0
End

Function WB_ParseStimulusType(string stimulusType)

strswitch(stimulusType)
case "DA":
return CHANNEL_TYPE_DAC
case "TTL":
return CHANNEL_TYPE_TTL
default:
ASSERT(0, "unknown stimulus type")
endswitch
End

/// @brief Return the name of a stimulus set build up from the passed parts
///
/// @returns complete stimulus set name or an empty string in case the basename is too long
Expand Down Expand Up @@ -2775,7 +2763,7 @@ Function WB_SplitStimsetName(string setName, string &setPrefix, variable &stimul

setNumber = str2num(setNumberString)
setPrefix = setPrefixString
stimulusType = WB_ParseStimulusType(stimulusTypeString)
stimulusType = ParseChannelTypeFromString(stimulusTypeString)
End

/// @brief Changes an existing stimset to a third party stimset
Expand Down
2 changes: 1 addition & 1 deletion Packages/MIES/MIES_WaveBuilderPanel.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ static Function WBP_ChangeWaveType()
End

Function WBP_GetStimulusType()
return WB_ParseStimulusType(GetPopupMenuString(panel, "popup_wavebuilder_outputtype"))
return ParseChannelTypeFromString(GetPopupMenuString(panel, "popup_wavebuilder_outputtype"))
End

Function WBP_PopMenuProc_WaveType(pa) : PopupMenuControl
Expand Down

0 comments on commit 402d327

Please sign in to comment.