Skip to content

Commit

Permalink
AI: Refactor AmplifierInteraction
Browse files Browse the repository at this point in the history
- Moved MCC specific Amplifier functions to MIES_AmplifierInteraction_MolecularDevices.ipf
- prefixed these functions with AIMCC_
- For all non-static AI_ functions, added abstraction that depending on device
  the MCC functions is called or a placeholder for Sutter amplifier is used.
- Added device argument to AI_ functions that did not used one, adapted depending
  call sites
- Kept checks of optional arguments in public AI_ functions
- Changed function declaration of public AIMCC_ functions to not use optional arguments
  The reason is that optional arguments can not easily promoted through function calls.
- Added updateView argument to AIMCC_UpdateAmpModel as ParamIsDefault state of value was
  used also for decision for updating the AmpView. This does not change the previous behavior.
- Adapted function declaration of all AIMCC_ functions to use modern syntax
  • Loading branch information
MichaelHuth committed Jun 10, 2024
1 parent b54b06e commit d309547
Show file tree
Hide file tree
Showing 10 changed files with 1,752 additions and 1,566 deletions.
1,667 changes: 118 additions & 1,549 deletions Packages/MIES/MIES_AmplifierInteraction.ipf

Large diffs are not rendered by default.

1,607 changes: 1,607 additions & 0 deletions Packages/MIES/MIES_AmplifierInteraction_MolecularDevices.ipf

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Packages/MIES/MIES_Configuration.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -2012,7 +2012,7 @@ static Function CONF_RestoreHeadstageAssociation(device, jsonID, midExp)
WAVE telegraphServers = GetAmplifierTelegraphServers()
numRows = DimSize(telegraphServers, ROWS)
if(!numRows)
Assert(AI_OpenMCCs(ampSerialList, ampTitleList = ampTitleList), "Evil kittens prevented MultiClamp from opening - FULL STOP")
Assert(AI_OpenMCCs(device, ampSerialList, ampTitleList = ampTitleList), "Evil kittens prevented MultiClamp from opening - FULL STOP")
endif

CONF_Position_MCC_Win(ampSerialList, ampTitleList, CONF_GetStringFromSettings(jsonID, EXPCONFIG_JSON_POSITION_MCC))
Expand Down
4 changes: 2 additions & 2 deletions Packages/MIES/MIES_Constants.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ Constant I_EQUAL_ZERO_MODE = 2

Constant NUM_CLAMP_MODES = 3

/// @name Possible values for the function parameter of AI_SendToAmp
/// @anchor AI_SendToAmpConstants
/// @name Possible values for the function parameter of AIMCC_SendToAmp
/// @anchor AIMCC_SendToAmpConstants
/// @{
Constant MCC_BEGIN_INVALID_FUNC = 10000
Constant MCC_SETHOLDING_FUNC = 10001
Expand Down
19 changes: 11 additions & 8 deletions Packages/MIES/MIES_DAEphys.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ Function GetHeadstageFromSettings(device, channelType, channelNumber, clampMode)

variable i, row

if(!AI_IsValidClampMode(clampMode))
if(!AI_IsValidClampMode(device, clampMode))
return NaN
endif

Expand Down Expand Up @@ -1748,9 +1748,12 @@ End
Function DAP_ButtonCtrlFindConnectedAmps(ba) : ButtonControl
STRUCT WMButtonAction &ba

string device

switch(ba.eventcode)
case 2: // mouse up
AI_FindConnectedAmps()
device = ba.win
AI_FindConnectedAmps(device)
break
endswitch
End
Expand Down Expand Up @@ -2552,7 +2555,7 @@ static Function DAP_CheckHeadStage(device, headStage, mode)

// needs to be at the beginning as DAP_ApplyClmpModeSavdSettngs writes into
// ChanAmpAssign/ChanAmpAssignUnit
if(ampConnState == AMPLIFIER_CONNECTION_SUCCESS && AI_IsValidClampMode(clampMode))
if(ampConnState == AMPLIFIER_CONNECTION_SUCCESS && AI_IsValidClampMode(device, clampMode))
DAP_ApplyClmpModeSavdSettngs(device, headstage, clampMode)
endif

Expand All @@ -2579,7 +2582,7 @@ static Function DAP_CheckHeadStage(device, headStage, mode)
if(ampConnState == AMPLIFIER_CONNECTION_SUCCESS)

AI_EnsureCorrectMode(device, headStage)
AI_QueryGainsUnitsForClampMode(device, headStage, clampMode, DAGainMCC, ADGainMCC, DAUnitMCC, ADUnitMCC)
[DAGainMCC, ADGainMCC, DAUnitMCC, ADUnitMCC] = AI_QueryGainsUnitsForClampMode(device, headStage, clampMode)

if(cmpstr(DAUnit, DAUnitMCC))
printf "(%s) The configured unit for the DA channel %d differs from the one in the \"DAC Channel and Device Associations\" menu (%s vs %s).\r", device, DACchannel, DAUnit, DAUnitMCC
Expand Down Expand Up @@ -3263,7 +3266,7 @@ Function DAP_GetInfoFromControl(device, ctrl, mode, headStage)
ASSERT(0, "unhandled control")
endif

AI_AssertOnInvalidClampMode(mode)
AI_AssertOnInvalidClampMode(device, mode)
End

Function DAP_CheckProc_ClampMode(cba) : CheckBoxControl
Expand Down Expand Up @@ -3338,7 +3341,7 @@ Function DAP_ChangeHeadStageMode(device, clampMode, headstage, options)
string iZeroCtrl, VCctrl, ICctrl, headstageCtrl, ctrl
variable activeHS, testPulseMode, oppositeMode, DAC, ADC, i, oldTab, oldState, newSliderPos

AI_AssertOnInvalidClampMode(clampMode)
AI_AssertOnInvalidClampMode(device, clampMode)
DAP_AbortIfUnlocked(device)

if(options != MCC_SKIP_UPDATES)
Expand Down Expand Up @@ -3489,7 +3492,7 @@ static Function DAP_UpdateClampmodeTabs(device, headStage, clampMode)

string highlightSpec = "\\f01\\Z11"

AI_AssertOnInvalidClampMode(clampMode)
AI_AssertOnInvalidClampMode(device, clampMode)

AI_SyncAmpStorageToGUI(device, headStage)
PGC_SetAndActivateControl(device, "tab_DataAcq_Amp", val = clampMode)
Expand Down Expand Up @@ -4564,7 +4567,7 @@ Function DAP_LockDevice(string win)
locked = 1
DAP_UpdateDataFolderDisplay(deviceLocked, locked)

AI_FindConnectedAmps()
AI_FindConnectedAmps(deviceLocked)
DAP_UpdateListOfLockedDevices()
DAP_UpdateListOfPressureDevices()
headstage = str2num(GetPopupMenuString(deviceLocked, "Popup_Settings_HeadStage"))
Expand Down
2 changes: 1 addition & 1 deletion Packages/MIES/MIES_DAEphys_GuiState.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ End
/// @brief Return a wave with `NUM_HEADSTAGES` rows with `1` where
/// the given headstages is active and in the given clamp mode.
Function/WAVE DAG_GetActiveHeadstages(string device, variable clampMode)
AI_AssertOnInvalidClampMode(clampMode)
AI_AssertOnInvalidClampMode(device, clampMode)

WAVE statusHS = DAG_GetChannelState(device, CHANNEL_TYPE_HEADSTAGE)
WAVE GUIState = GetDA_EphysGuiStateNum(device)
Expand Down
1 change: 1 addition & 0 deletions Packages/MIES_Include.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ End
#include "MIES_AcceleratedModifyGraph"
#include "MIES_AcquisitionStateHandling"
#include "MIES_AmplifierInteraction"
#include "MIES_AmplifierInteraction_MolecularDevices"
#include "MIES_AnalysisBrowser"
#include "MIES_AnalysisBrowser_Macro"
#include "MIES_AnalysisBrowser_SweepBrowser"
Expand Down
8 changes: 7 additions & 1 deletion Packages/tests/PAPlot/UTF_PA_Tests.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,10 @@
// data is properly NaNed on the left and right edge.
static Constant PA_TEST_FP_EPSILON = 1E-6

static StrConstant DEVICENAME_SUTTER = "IPA_E_000000"
static StrConstant DEVICENAME_NI = "Dev1"
static StrConstant DEVICENAME_ITC = "ITC"

static Function TEST_BEGIN_OVERRIDE(string name)
TestBeginCommon()
End
Expand Down Expand Up @@ -926,7 +930,9 @@ static Function PAT_CheckPulseWaveNote(string win, WAVE pulse)
CHECK_LT_VAR(first, last)

setting = PAT_GetNumberFromPulseWaveNote(pulse, NOTE_KEY_CLAMP_MODE)
CHECK(AI_IsValidClampMode(setting))
CHECK(AI_IsValidClampMode(DEVICENAME_ITC, setting))
CHECK(AI_IsValidClampMode(DEVICENAME_NI, setting))
CHECK(AI_IsValidClampMode(DEVICENAME_SUTTER, setting))

// no zeros inside the pulse
// this requires that the DA and AD channels on the hardware are connected directly when acquiring this data
Expand Down
6 changes: 3 additions & 3 deletions Packages/tests/UTF_HardwareHelperFunctions.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1100,8 +1100,8 @@ Function OpenDatabrowser()
PGC_SetAndActivateControl(bsPanel, "check_BrowserSettings_DS", val = 1)
End

Function EnsureMCCIsOpen()
AI_FindConnectedAmps()
Function EnsureMCCIsOpen(string device)
AI_FindConnectedAmps(device)

WAVE ampMCC = GetAmplifierMultiClamps()
WAVE ampTel = GetAmplifierTelegraphServers()
Expand Down Expand Up @@ -1422,7 +1422,7 @@ Function AcquireData_NG(STRUCT DAQSettings &s, string device)
variable i, activeHS

if(s.amp)
EnsureMCCIsOpen()
EnsureMCCIsOpen(device)
endif

FetchCustomizationFunctions(s)
Expand Down
2 changes: 1 addition & 1 deletion Packages/tests/UTF_HelperFunctions.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Function FixupJSONConfigImplRig(variable jsonId)
variable serialNum, i

// replace stored serial number with present serial number
AI_FindConnectedAmps()
AI_FindConnectedAmps("")
WAVE ampMCC = GetAmplifierMultiClamps()

CHECK_GT_VAR(DimSize(ampMCC, ROWS), 0)
Expand Down

0 comments on commit d309547

Please sign in to comment.