BoardPanel.cc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. }
  42. BoardPanel::BoardPanel(wxWindow* parent, const BoardConfig& initialConfig) :
  43. wxPanel(parent),
  44. myParent(parent),
  45. myDelayValidator(new wxIntegerValidator<uint8_t>)
  46. {
  47. wxFlexGridSizer *fgs = new wxFlexGridSizer(8, 2, 9, 25);
  48. fgs->Add(new wxStaticText(this, wxID_ANY, _("Startup Delay (seconds)")));
  49. myStartDelayCtrl =
  50. new wxTextCtrl(
  51. this,
  52. ID_startDelayCtrl,
  53. "0",
  54. wxDefaultPosition,
  55. wxDefaultSize,
  56. 0,
  57. *myDelayValidator);
  58. myStartDelayCtrl->SetToolTip(_("Extra delay on power on, normally set to 0"));
  59. fgs->Add(myStartDelayCtrl);
  60. fgs->Add(new wxStaticText(this, wxID_ANY, _("SCSI Selection Delay (ms, 255 = auto)")));
  61. mySelDelayCtrl =
  62. new wxTextCtrl(
  63. this,
  64. ID_selDelayCtrl,
  65. "255",
  66. wxDefaultPosition,
  67. wxDefaultSize,
  68. 0,
  69. *myDelayValidator);
  70. mySelDelayCtrl->SetToolTip(_("Delay before responding to SCSI selection. SCSI1 hosts usually require 1ms delay, however some require no delay"));
  71. fgs->Add(mySelDelayCtrl);
  72. fgs->Add(new wxStaticText(this, wxID_ANY, wxT("")));
  73. myParityCtrl =
  74. new wxCheckBox(
  75. this,
  76. ID_parityCtrl,
  77. _("Enable Parity"));
  78. myParityCtrl->SetToolTip(_("Enable to require valid SCSI parity bits when receiving data. Some hosts don't provide parity. SCSI2SD always outputs valid parity bits."));
  79. fgs->Add(myParityCtrl);
  80. fgs->Add(new wxStaticText(this, wxID_ANY, wxT("")));
  81. myUnitAttCtrl =
  82. new wxCheckBox(
  83. this,
  84. ID_unitAttCtrl,
  85. _("Enable Unit Attention"));
  86. myUnitAttCtrl->SetToolTip(_("Enable this to inform the host of changes after hot-swapping SD cards. Causes problems with Mac Plus."));
  87. fgs->Add(myUnitAttCtrl);
  88. fgs->Add(new wxStaticText(this, wxID_ANY, wxT("")));
  89. myScsi2Ctrl =
  90. new wxCheckBox(
  91. this,
  92. ID_scsi2Ctrl,
  93. _("Enable SCSI2 Mode"));
  94. myScsi2Ctrl->SetToolTip(_("Enable high-performance mode. May cause problems with SASI/SCSI1 hosts."));
  95. fgs->Add(myScsi2Ctrl);
  96. fgs->Add(new wxStaticText(this, wxID_ANY, wxT("")));
  97. myGlitchCtrl =
  98. new wxCheckBox(
  99. this,
  100. ID_glitchCtrl,
  101. _("Disable glitch filter"));
  102. myGlitchCtrl->SetToolTip(_("Improve performance at the cost of noise immunity. Only use with short cables."));
  103. fgs->Add(myGlitchCtrl);
  104. fgs->Add(new wxStaticText(this, wxID_ANY, wxT("")));
  105. myCacheCtrl =
  106. new wxCheckBox(
  107. this,
  108. ID_cacheCtrl,
  109. _("Enable disk cache (experimental)"));
  110. myCacheCtrl->SetToolTip(_("SD IO commands aren't completed when SCSI commands complete"));
  111. fgs->Add(myCacheCtrl);
  112. fgs->Add(new wxStaticText(this, wxID_ANY, wxT("")));
  113. myDisconnectCtrl =
  114. new wxCheckBox(
  115. this,
  116. ID_disconnectCtrl,
  117. _("Enable SCSI Disconnect"));
  118. myDisconnectCtrl->SetToolTip(_("Release the SCSI bus while waiting for SD card writes to complete. Must also be enabled in host OS."));
  119. fgs->Add(myDisconnectCtrl);
  120. wxBoxSizer* hbox = new wxBoxSizer(wxHORIZONTAL);
  121. hbox->Add(fgs, 1, wxALL | wxEXPAND, 15);
  122. this->SetSizer(hbox);
  123. Centre();
  124. setConfig(initialConfig);
  125. }
  126. BoardConfig
  127. BoardPanel::getConfig() const
  128. {
  129. BoardConfig config;
  130. // Try and keep unknown/unused fields as-is to support newer firmware
  131. // versions.
  132. memcpy(&config, &myConfig, sizeof(config));
  133. config.flags =
  134. (myParityCtrl->IsChecked() ? CONFIG_ENABLE_PARITY : 0) |
  135. (myUnitAttCtrl->IsChecked() ? CONFIG_ENABLE_UNIT_ATTENTION : 0) |
  136. (myScsi2Ctrl->IsChecked() ? CONFIG_ENABLE_SCSI2 : 0) |
  137. (myGlitchCtrl->IsChecked() ? CONFIG_DISABLE_GLITCH : 0) |
  138. (myCacheCtrl->IsChecked() ? CONFIG_ENABLE_CACHE: 0) |
  139. (myDisconnectCtrl->IsChecked() ? CONFIG_ENABLE_DISCONNECT: 0);
  140. config.startupDelay = CtrlGetValue<unsigned int>(myStartDelayCtrl).first;
  141. config.selectionDelay = CtrlGetValue<unsigned int>(mySelDelayCtrl).first;
  142. return config;
  143. }
  144. void
  145. BoardPanel::setConfig(const BoardConfig& config)
  146. {
  147. memcpy(&myConfig, &config, sizeof(config));
  148. myParityCtrl->SetValue(config.flags & CONFIG_ENABLE_PARITY);
  149. myUnitAttCtrl->SetValue(config.flags & CONFIG_ENABLE_UNIT_ATTENTION);
  150. myScsi2Ctrl->SetValue(config.flags & CONFIG_ENABLE_SCSI2);
  151. myGlitchCtrl->SetValue(config.flags & CONFIG_DISABLE_GLITCH);
  152. myCacheCtrl->SetValue(config.flags & CONFIG_ENABLE_CACHE);
  153. myDisconnectCtrl->SetValue(config.flags & CONFIG_ENABLE_DISCONNECT);
  154. {
  155. std::stringstream conv;
  156. conv << static_cast<unsigned int>(config.startupDelay);
  157. myStartDelayCtrl->ChangeValue(conv.str());
  158. }
  159. {
  160. std::stringstream conv;
  161. conv << static_cast<unsigned int>(config.selectionDelay);
  162. mySelDelayCtrl->ChangeValue(conv.str());
  163. }
  164. }