BoardPanel.cc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // Copyright (C) 2015 Michael McMaster <michael@codesrc.com>
  2. //
  3. // This file is part of SCSI2SD.
  4. //
  5. // SCSI2SD is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // SCSI2SD is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with SCSI2SD. If not, see <http://www.gnu.org/licenses/>.
  17. // For compilers that support precompilation, includes "wx/wx.h".
  18. #include <wx/wxprec.h>
  19. #ifndef WX_PRECOMP
  20. #include <wx/wx.h>
  21. #endif
  22. #include <wx/wrapsizer.h>
  23. #include "ConfigUtil.hh"
  24. #include "BoardPanel.hh"
  25. #include <limits>
  26. #include <sstream>
  27. #include <math.h>
  28. #include <string.h>
  29. using namespace SCSI2SD;
  30. namespace
  31. {
  32. template<typename IntType, class WXCTRL> std::pair<IntType, bool>
  33. CtrlGetValue(WXCTRL* ctrl)
  34. {
  35. IntType value;
  36. std::stringstream conv;
  37. conv << ctrl->GetValue();
  38. conv >> value;
  39. return std::make_pair(value, static_cast<bool>(conv));
  40. }
  41. void CtrlGetFixedString(wxTextEntry* ctrl, char* dest, size_t len)
  42. {
  43. memset(dest, ' ', len);
  44. std::string str(ctrl->GetValue().ToAscii());
  45. // Don't use strncpy - we need to avoid NULL's
  46. memcpy(dest, str.c_str(), std::min(len, str.size()));
  47. }
  48. bool CtrlIsAscii(wxTextEntry* ctrl)
  49. {
  50. return ctrl->GetValue().IsAscii();
  51. }
  52. }
  53. BoardPanel::BoardPanel(wxWindow* parent, const BoardConfig& initialConfig) :
  54. wxPanel(parent),
  55. myParent(parent)
  56. {
  57. wxFlexGridSizer *fgs = new wxFlexGridSizer(6, 2, 9, 25);
  58. fgs->Add(new wxStaticText(this, wxID_ANY, wxT("")));
  59. myParityCtrl =
  60. new wxCheckBox(
  61. this,
  62. ID_parityCtrl,
  63. _("Enable Parity"));
  64. myParityCtrl->SetToolTip(_("Enable to require valid SCSI parity bits when receiving data. Some hosts don't provide parity. SCSI2SD always outputs valid parity bits."));
  65. fgs->Add(myParityCtrl);
  66. fgs->Add(new wxStaticText(this, wxID_ANY, wxT("")));
  67. myUnitAttCtrl =
  68. new wxCheckBox(
  69. this,
  70. ID_unitAttCtrl,
  71. _("Enable Unit Attention"));
  72. myUnitAttCtrl->SetToolTip(_("Enable this to inform the host of changes after hot-swapping SD cards. Causes problems with Mac Plus."));
  73. fgs->Add(myUnitAttCtrl);
  74. fgs->Add(new wxStaticText(this, wxID_ANY, wxT("")));
  75. myScsi2Ctrl =
  76. new wxCheckBox(
  77. this,
  78. ID_scsi2Ctrl,
  79. _("Enable SCSI2 Mode"));
  80. myScsi2Ctrl->SetToolTip(_("Enable high-performance mode. May cause problems with SASI/SCSI1 hosts."));
  81. fgs->Add(myScsi2Ctrl);
  82. fgs->Add(new wxStaticText(this, wxID_ANY, wxT("")));
  83. myGlitchCtrl =
  84. new wxCheckBox(
  85. this,
  86. ID_glitchCtrl,
  87. _("Disable glitch filter"));
  88. myGlitchCtrl->SetToolTip(_("Improve performance at the cost of noise immunity. Only use with short cables."));
  89. fgs->Add(myGlitchCtrl);
  90. fgs->Add(new wxStaticText(this, wxID_ANY, wxT("")));
  91. myCacheCtrl =
  92. new wxCheckBox(
  93. this,
  94. ID_cacheCtrl,
  95. _("Enable disk cache (experimental)"));
  96. myCacheCtrl->SetToolTip(_("SD IO commands aren't completed when SCSI commands complete"));
  97. fgs->Add(myCacheCtrl);
  98. fgs->Add(new wxStaticText(this, wxID_ANY, wxT("")));
  99. myDisconnectCtrl =
  100. new wxCheckBox(
  101. this,
  102. ID_disconnectCtrl,
  103. _("Enable SCSI Disconnect"));
  104. myDisconnectCtrl->SetToolTip(_("Release the SCSI bus while waiting for SD card writes to complete. Must also be enabled in host OS."));
  105. fgs->Add(myDisconnectCtrl);
  106. wxBoxSizer* hbox = new wxBoxSizer(wxHORIZONTAL);
  107. hbox->Add(fgs, 1, wxALL | wxEXPAND, 15);
  108. this->SetSizer(hbox);
  109. Centre();
  110. setConfig(initialConfig);
  111. }
  112. BoardConfig
  113. BoardPanel::getConfig() const
  114. {
  115. BoardConfig config;
  116. // Try and keep unknown/unused fields as-is to support newer firmware
  117. // versions.
  118. memcpy(&config, &myConfig, sizeof(config));
  119. config.flags =
  120. (myParityCtrl->IsChecked() ? CONFIG_ENABLE_PARITY : 0) |
  121. (myUnitAttCtrl->IsChecked() ? CONFIG_ENABLE_UNIT_ATTENTION : 0) |
  122. (myScsi2Ctrl->IsChecked() ? CONFIG_ENABLE_SCSI2 : 0) |
  123. (myGlitchCtrl->IsChecked() ? CONFIG_DISABLE_GLITCH : 0) |
  124. (myCacheCtrl->IsChecked() ? CONFIG_ENABLE_CACHE: 0) |
  125. (myDisconnectCtrl->IsChecked() ? CONFIG_ENABLE_DISCONNECT: 0);
  126. return config;
  127. }
  128. void
  129. BoardPanel::setConfig(const BoardConfig& config)
  130. {
  131. memcpy(&myConfig, &config, sizeof(config));
  132. myParityCtrl->SetValue(config.flags & CONFIG_ENABLE_PARITY);
  133. myUnitAttCtrl->SetValue(config.flags & CONFIG_ENABLE_UNIT_ATTENTION);
  134. myScsi2Ctrl->SetValue(config.flags & CONFIG_ENABLE_SCSI2);
  135. myGlitchCtrl->SetValue(config.flags & CONFIG_DISABLE_GLITCH);
  136. myCacheCtrl->SetValue(config.flags & CONFIG_ENABLE_CACHE);
  137. myDisconnectCtrl->SetValue(config.flags & CONFIG_ENABLE_DISCONNECT);
  138. }