Skip to content

Commit

Permalink
Merge pull request micro-manager#487 from samdrea/pr
Browse files Browse the repository at this point in the history
Added license to OpenFlexure project
  • Loading branch information
henrypinkard authored Sep 27, 2024
2 parents 0d5608d + 295bb10 commit 58989a4
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 16 deletions.
49 changes: 36 additions & 13 deletions DeviceAdapters/OpenFlexure/OpenFlexure.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
//////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// FILE: OpenFlexure.cpp
// PROJECT: Micro-Manager
// SUBSYSTEM: DeviceAdapters
//-----------------------------------------------------------------------------
// DESCRIPTION: Adapter for the OpenFlexure Microscope. This adapter is used on the v5 Sangaboard.
// DESCRIPTION: Adapter for the OpenFlexure Microscope. This adapter is used on the v5 Sangaboard.
// - Tested with Sangaboard Firmware v1.0.1-dev || Sangaboard v0.5.x
//
// AUTHOR: Samdrea Hsu, [email protected], 09/23/2024
//
// COPYRIGHT: Samdrea Hsu
//
// AUTHOR: Samdrea Hsu, [email protected], 06/22/2024
// LICENSE: This file is distributed under the BSD license.
// License text is included with the source distribution.
//
// This file is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES.
//
//////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -72,7 +84,8 @@ SangaBoardHub::SangaBoardHub() : initialized_(false), port_("Undefined"), portAv

// Pre-initialization property: port name
CPropertyAction* pAct = new CPropertyAction(this, &SangaBoardHub::OnPort);
CreateProperty(MM::g_Keyword_Port, "Undefined", MM::String, false, pAct, true);
int ret = CreateProperty(MM::g_Keyword_Port, "Undefined", MM::String, false, pAct, true);

}

SangaBoardHub::~SangaBoardHub()
Expand All @@ -82,24 +95,33 @@ SangaBoardHub::~SangaBoardHub()

int SangaBoardHub::Initialize()
{
// Send a command to check if Sangaboard is connected
SendCommand("version", _serial_answer); // Example response is "Sangaboard v0.5.x"

// Check if the response contains "Sangaboard"
if (_serial_answer.find("Sangaboard") == std::string::npos) {
// If not found, return an error code
return DEVICE_NOT_CONNECTED;
}

initialized_ = true;

// Set up Manual Command Interface to send command directly to SangaBoard
CPropertyAction* pCommand = new CPropertyAction(this, &SangaBoardHub::OnManualCommand);
int ret = CreateProperty(g_Keyword_Command, "", MM::String, false, pCommand);
assert(DEVICE_OK == ret);
if (DEVICE_OK != ret) return DEVICE_CAN_NOT_SET_PROPERTY;

// Set up property to display most recent serial response (read-only)
ret = CreateProperty(g_Keyword_Response, "", MM::String, false);
assert(DEVICE_OK == ret);
if (DEVICE_OK != ret) return DEVICE_CAN_NOT_SET_PROPERTY;

// Initialize the cache values to the current values stored on hardware
this->SyncState();

// Set up Step Delay property for changing velocity
CPropertyAction* pStepDel = new CPropertyAction(this, &SangaBoardHub::OnStepDelay);
ret = CreateIntegerProperty(g_Keyword_StepDelay, step_delay_, false, pStepDel);
assert(DEVICE_OK == ret);
if (DEVICE_OK != ret) return DEVICE_CAN_NOT_SET_PROPERTY;
AddAllowedValue(g_Keyword_StepDelay, "1000");
AddAllowedValue(g_Keyword_StepDelay, "2000");
AddAllowedValue(g_Keyword_StepDelay, "3000");
Expand All @@ -109,7 +131,7 @@ int SangaBoardHub::Initialize()
// Set up Ramp Time property for changing acceleration
CPropertyAction* pRampTime = new CPropertyAction(this, &SangaBoardHub::OnRampTime);
ret = CreateIntegerProperty(g_Keyword_RampTime, ramp_time_, false, pRampTime);
assert(DEVICE_OK == ret);
if (DEVICE_OK != ret) return DEVICE_CAN_NOT_SET_PROPERTY;
AddAllowedValue(g_Keyword_RampTime, "0", 0);
AddAllowedValue(g_Keyword_RampTime, "100000"); // Not really sure if these values really do much for acceleration...
AddAllowedValue(g_Keyword_RampTime, "200000");
Expand All @@ -118,7 +140,7 @@ int SangaBoardHub::Initialize()
// Set up extra functions drop down menu
CPropertyAction* pExtras= new CPropertyAction(this, &SangaBoardHub::OnExtraCommands);
ret = CreateStringProperty(g_Keyword_Extras, g_Keyword_None, false, pExtras);
assert(DEVICE_OK == ret);
if (DEVICE_OK != ret) return DEVICE_CAN_NOT_SET_PROPERTY;
AddAllowedValue(g_Keyword_Extras, g_ExtraCommand_Stop);
AddAllowedValue(g_Keyword_Extras, g_ExtraCommand_Zero);
AddAllowedValue(g_Keyword_Extras, g_ExtraCommand_Release);
Expand Down Expand Up @@ -321,7 +343,8 @@ int SangaBoardHub::SendCommand(std::string cmd, std::string& ans)
}

// Reflect the command in the serial response property
SetProperty(g_Keyword_Response, ans.c_str());
ret = SetProperty(g_Keyword_Response, ans.c_str());
if (DEVICE_OK != ret) return DEVICE_CAN_NOT_SET_PROPERTY;

return DEVICE_OK;

Expand Down Expand Up @@ -447,7 +470,7 @@ int XYStage::Initialize()
std::string cmd = "blocking_moves false";
pHub->SendCommand(cmd, _serial_answer);
if (_serial_answer.find("done") == -1) {
return DEVICE_ERR;
return DEVICE_SERIAL_INVALID_RESPONSE;
}

// Set the current stage position
Expand Down Expand Up @@ -653,7 +676,7 @@ int ZStage::Initialize()
std::string cmd = "blocking_moves false";
pHub->SendCommand(cmd, _serial_answer);
if (_serial_answer.find("done") == -1) {
return DEVICE_ERR;
return DEVICE_SERIAL_INVALID_RESPONSE;
}

// Set the current stagePosition
Expand Down Expand Up @@ -940,4 +963,4 @@ int LEDIllumination::SetBrightness()
pHub->SendCommand(cmd, _serial_answer);

return DEVICE_OK;
}
}
18 changes: 15 additions & 3 deletions DeviceAdapters/OpenFlexure/OpenFlexure.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
//////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// FILE: OpenFlexure.h
// PROJECT: Micro-Manager
// SUBSYSTEM: DeviceAdapters
//-----------------------------------------------------------------------------
// DESCRIPTION: Adapter for the OpenFlexure Microscope. This adapter is used on the v5 Sangaboard.
// DESCRIPTION: Adapter for the OpenFlexure Microscope. This adapter is used on the v5 Sangaboard.
// - Tested with Sangaboard Firmware v1.0.1-dev || Sangaboard v0.5.x
//
// AUTHOR: Samdrea Hsu, [email protected], 09/23/2024
//
// COPYRIGHT: Samdrea Hsu
//
// AUTHOR: Samdrea Hsu, [email protected], 06/22/2024
// LICENSE: This file is distributed under the BSD license.
// License text is included with the source distribution.
//
// This file is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES.
//
//////////////////////////////////////////////////////////////////////////////

Expand Down

0 comments on commit 58989a4

Please sign in to comment.