Skip to content

Commit

Permalink
Merge pull request #148 from electux/dev
Browse files Browse the repository at this point in the history
[microhil] Updated microhildesk serial port controlling, updated docs
  • Loading branch information
vroncevic committed Oct 2, 2023
2 parents 007839b + 4814669 commit 6e9b842
Show file tree
Hide file tree
Showing 381 changed files with 2,453 additions and 1,513 deletions.
2 changes: 2 additions & 0 deletions sw/microhil_base/src/channel/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "io_config.h"
#include "channel.h"

#define VERBOSE

////////////////////////////////////////////////////////////////////////////
/// @brief Marks private functions
#define MICROHIL_PRIVATE
Expand Down
1 change: 1 addition & 0 deletions sw/microhildesk/build/sources.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ SOURCES = \
../com/microhil_serial_com_utils.cc \
../com/microhil_serial_com.cc \
../model/microhil_model.cc \
../view/microhil_view_signals.cc \
../view/microhil_view_slots.cc \
../view/microhil_view_map.cc \
../view/microhil_view.cc \
Expand Down
28 changes: 26 additions & 2 deletions sw/microhildesk/com/microhil_serial_com.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,44 @@ void MHSerialCom::close()

void MHSerialCom::setup(const MHString &device, const MHVecUInt &params)
{
if (m_serialPort->IsOpen())
{
m_serialPort->Close();
}

////////////////////////////////////////////////////////////////////////
/// Sets serial port device path
m_device = device;

open();

////////////////////////////////////////////////////////////////////////
/// Sets serial port parameters
m_serialPort->SetBaudRate(uintToBaudRate(params[0]));
m_serialPort->SetCharacterSize(uintToDataBits(params[1]));
m_serialPort->SetParity(uintToParity(params[2]));
m_serialPort->SetStopBits(uintToStopBits(params[3]));
m_device = device;
}

void MHSerialCom::setup(const MHString &device, const MHSerialParams &params)
{
if (m_serialPort->IsOpen())
{
m_serialPort->Close();
}

////////////////////////////////////////////////////////////////////////
/// Sets serial port device path
m_device = device;

open();

////////////////////////////////////////////////////////////////////////
/// Sets serial port parameters
m_serialPort->SetBaudRate(params.baudRate);
m_serialPort->SetCharacterSize(params.dataBits);
m_serialPort->SetParity(params.parity);
m_serialPort->SetStopBits(params.stopBits);
m_device = device;
}

void MHSerialCom::read(MHVecByte &data, size_t len, size_t timeout)
Expand Down
5 changes: 2 additions & 3 deletions sw/microhildesk/config/microhil_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ namespace
}

MHConfig::MHConfig()
:
m_homePath{Glib::get_home_dir() + kHomeDirName},
m_configFilePath{m_homePath + kConfigFileName}
: m_homePath{Glib::get_home_dir() + kHomeDirName},
m_configFilePath{m_homePath + kConfigFileName}
{
////////////////////////////////////////////////////////////////////////
/// Pre-validation of configuration path
Expand Down
11 changes: 5 additions & 6 deletions sw/microhildesk/controller/microhil_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
#include "microhil_controller.h"

MHController::MHController(MHSPtr<IMHModel> model, MHSPtr<IMHView> view)
:
m_model{model},
m_view{view},
m_config{MHmakeSPtr<MHConfig>()},
m_log{MHmakeSPtr<MHLog>()},
m_serial{MHmakeSPtr<MHSerialCom>()}
: m_model{model},
m_view{view},
m_config{MHmakeSPtr<MHConfig>()},
m_log{MHmakeSPtr<MHLog>()},
m_serial{MHmakeSPtr<MHSerialCom>()}
{
////////////////////////////////////////////////////////////////////////
/// Maps views and backend (signals and slots)
Expand Down
5 changes: 5 additions & 0 deletions sw/microhildesk/controller/microhil_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ class MHController : public IMHController
/// @param params represents set of serial parameters
void onSerialSettingsLoaded(MHString &dev, MHVecUInt &params) final;

////////////////////////////////////////////////////////////////////////
/// @brief Slot for processing serial port changes
/// @param state true for enable port, else false
void onSerialControlChanged(bool state) final;

private:
////////////////////////////////////////////////////////////////////////
/// @brief Enable/Disable state of controller
Expand Down
6 changes: 6 additions & 0 deletions sw/microhildesk/controller/microhil_controller_map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,10 @@ void MHController::mapping()
m_view->getSerialSettings()->serialSetupChanged().connect(
sigc::mem_fun(*this, &MHController::onSerialSettingsChanged)
);

////////////////////////////////////////////////////////////////////////
/// Maps view signal and controller slot
m_view->serialControlChanged().connect(
sigc::mem_fun(*this, &MHController::onSerialControlChanged)
);
}
29 changes: 24 additions & 5 deletions sw/microhildesk/controller/microhil_controller_slots.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void MHController::onLogSettingsChanged(MHString &path, int level)
m_config->setLogPath(path);
m_config->setLogLevel(level);

if(!m_config->store())
if (!m_config->store())
{
// TODO
// Emit signal for error handler
Expand Down Expand Up @@ -59,19 +59,19 @@ void MHController::onSerialSettingsChanged(MHString &dev, MHVecUInt &params)
m_config->setParity(static_cast<int>(params[2]));
m_config->setStopBits(static_cast<int>(params[3]));

if(!m_config->store())
if (!m_config->store())
{
// TODO
// Emit signal for error handler

// TODO
// logging
}

////////////////////////////////////////////////////////////////////////
/// Updates serial handler
m_serial->close();
// m_serial->setup(device, params);
// m_serial->open();
m_serial->setup(dev, params);

// TODO
// logging
}
Expand All @@ -80,3 +80,22 @@ void MHController::onSerialSettingsLoaded(MHString &dev, MHVecUInt &params)
{
m_view->getSerialSettings()->serialSettingsLoaded(dev, params);
}

void MHController::onSerialControlChanged(bool state)
{
if (state)
{
MHVecUInt serialParams{};
serialParams.push_back(m_config->getBaudRate());
serialParams.push_back(m_config->getDataBits());
serialParams.push_back(
m_config->parityUnicodeStringToInt(m_config->getParity())
);
serialParams.push_back(m_config->getStopBits());
m_serial->setup(m_config->getDevice(), serialParams);
}
else
{
m_serial->close();
}
}
5 changes: 5 additions & 0 deletions sw/microhildesk/controller/microhil_icontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,9 @@ class IMHController
/// @param dev represents file path for serial device
/// @param params represents set of serial parameters
virtual void onSerialSettingsLoaded(MHString &dev, MHVecUInt &params) = 0;

////////////////////////////////////////////////////////////////////////
/// @brief Slot for processing serial port changes
/// @param state true for enable port, else false
virtual void onSerialControlChanged(bool state) = 0;
};
4 changes: 4 additions & 0 deletions sw/microhildesk/view/home/microhil_view_home.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,8 @@ MHViewHome::MHViewHome(BaseObjectType *object, MHRPtr<Gtk::Builder> const &ui)
{
disableChannel(static_cast<Channel>(i));
}

////////////////////////////////////////////////////////////////////////
/// Disables Serial settings (enabled if serial port is active)
m_serialSettings->set_sensitive(false);
}
6 changes: 6 additions & 0 deletions sw/microhildesk/view/home/microhil_view_home_slots.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,17 @@ void MHViewHome::onToggleTimerChanged(Channel id)
void MHViewHome::onConnectClicked()
{
m_actionViewTriggered.emit(ViewId::MICROHIL_CONNECT);
m_connect->set_sensitive(false);
m_disconnect->set_sensitive(true);
m_serialSettings->set_sensitive(true);
}

void MHViewHome::onDisconnectClicked()
{
m_actionViewTriggered.emit(ViewId::MICROHIL_DISCONNECT);
m_connect->set_sensitive(true);
m_disconnect->set_sensitive(false);
m_serialSettings->set_sensitive(true);
}

void MHViewHome::onQuitClicked()
Expand Down
9 changes: 9 additions & 0 deletions sw/microhildesk/view/microhil_iview.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#include "settings/serial/microhil_view_serial.h"
#include "../utils/microhil_types.h"

////////////////////////////////////////////////////////////////////////
/// @brief Signal type for enable/disable serial communication channel
using SigSerialControl = sigc::signal<void(bool)>;

////////////////////////////////////////////////////////////////////////////
/// @brief IMHView class is interface set for view
class IMHView
Expand All @@ -32,6 +36,11 @@ class IMHView
/// @brief IMHView destructor
virtual ~IMHView() = default;

////////////////////////////////////////////////////////////////////////
/// @brief Signal for controling serial port
/// @return Signal for clicked Connect/Disconnect
virtual SigSerialControl serialControlChanged() = 0;

////////////////////////////////////////////////////////////////////////
/// @brief Gets home view
/// @return Home view instance
Expand Down
13 changes: 11 additions & 2 deletions sw/microhildesk/view/microhil_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,19 @@
#include "microhil_iview.h"

////////////////////////////////////////////////////////////////////////////
/// @brief MHView class is implementation of view
class MHView: public IMHView
/// @brief MHView class is implementation of view
class MHView : public IMHView
{
public:
////////////////////////////////////////////////////////////////////////
/// @brief MHView constructor
MHView();

////////////////////////////////////////////////////////////////////////
/// @brief Signal for controling serial port
/// @return Signal for clicked Connect/Disconnect
SigSerialControl serialControlChanged() final;

////////////////////////////////////////////////////////////////////////
/// @brief Gets home view
/// @return Home view instance
Expand Down Expand Up @@ -61,6 +66,10 @@ class MHView: public IMHView
/// @brief UI builder instance
MHRPtr<Gtk::Builder> m_builder{nullptr};

////////////////////////////////////////////////////////////////////////
/// @brief Signal for Connect/Disconnect the serial port
SigSerialControl m_serialPortChanged{};

////////////////////////////////////////////////////////////////////////
/// @brief Home view instance
MHRPtr<MHViewHome> m_home{nullptr};
Expand Down
24 changes: 24 additions & 0 deletions sw/microhildesk/view/microhil_view_signals.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* -*- Mode: CC; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
* microhil_view_signals.cc
* Copyright (C) 2023 Vladimir Roncevic <elektron.ronca@gmail.com>
*
* microhildesk is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* microhildesk 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.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "microhil_view.h"

SigSerialControl MHView::serialControlChanged()
{
return m_serialPortChanged;
}
18 changes: 18 additions & 0 deletions sw/microhildesk/view/microhil_view_slots.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,31 @@ void MHView::onViewChanged(ViewId id)
{
switch (static_cast<int>(id))
{
case static_cast<int>(ViewId::MICROHIL_CONNECT):
////////////////////////////////////////////////////////////////////
/// Enables and opens the serial port
m_serialPortChanged.emit(true);
break;
case static_cast<int>(ViewId::MICROHIL_DISCONNECT):
////////////////////////////////////////////////////////////////////
/// Disables and closes the serial port
m_serialPortChanged.emit(false);
break;
case static_cast<int>(ViewId::MICROHIL_QUIT):
break;
case static_cast<int>(ViewId::MICROHIL_SERIAL_SETTINGS):
////////////////////////////////////////////////////////////////////
/// Activate serial settings view
m_serial->show();
break;
case static_cast<int>(ViewId::MICROHIL_LOG_SETTINGS):
////////////////////////////////////////////////////////////////////
/// Activate log settings view
m_log->show();
break;
case static_cast<int>(ViewId::MICROHIL_ABOUT):
////////////////////////////////////////////////////////////////////
/// Activate about view
m_about->show();
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,9 @@ void MHViewSerial::onOkSerialTriggered()
/// Emits new serial settings
m_serialSetup.emit(devicePath, serialParams);

////////////////////////////////////////////////////////////////////////
/// Emits signal for disabling Connect menu-item in home view
// TODO

this->hide();
}
2 changes: 1 addition & 1 deletion sw/microhildesk_docs/html/annotated.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated on Sun Oct 1 2023 22:41:06 for microhildesk by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.4 </li>
<li class="footer">Generated on Mon Oct 2 2023 23:24:13 for microhildesk by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.4 </li>
</ul>
</div>
</body>
Expand Down
2 changes: 1 addition & 1 deletion sw/microhildesk_docs/html/classes.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated on Sun Oct 1 2023 22:41:06 for microhildesk by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.4 </li>
<li class="footer">Generated on Mon Oct 2 2023 23:24:13 for microhildesk by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.4 </li>
</ul>
</div>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="../../dir_b2f003339c516cc00c8cadcafbe82f13.html">view</a></li><li class="navelem"><a class="el" href="../../dir_114fe11fb74ba151b2b0aa05d224511f.html">home</a></li><li class="navelem"><a class="el" href="../../d0/d1b/microhil__view__home_8cc.html">microhil_view_home.cc</a></li>
<li class="footer">Generated on Sun Oct 1 2023 22:41:06 for microhildesk by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.4 </li>
<li class="footer">Generated on Mon Oct 2 2023 23:24:13 for microhildesk by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.4 </li>
</ul>
</div>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@
<div class="line"><a id="l00207" name="l00207"></a><span class="lineno"> 207</span> {</div>
<div class="line"><a id="l00208" name="l00208"></a><span class="lineno"> 208</span> <a class="code hl_function" href="../../dc/def/classMHViewHome.html#a85eaeba794f77bfbdd6b0567076689f0">disableChannel</a>(<span class="keyword">static_cast&lt;</span><a class="code hl_enumeration" href="../../de/d3d/microhil__view__home__abstract_8h.html#ad5af43d459a28efceb4158ceb3284109">Channel</a><span class="keyword">&gt;</span>(i));</div>
<div class="line"><a id="l00209" name="l00209"></a><span class="lineno"> 209</span> }</div>
<div class="line"><a id="l00210" name="l00210"></a><span class="lineno"> 210</span>}</div>
<div class="line"><a id="l00210" name="l00210"></a><span class="lineno"> 210</span> </div>
<div class="line"><a id="l00213" name="l00213"></a><span class="lineno"> 213</span> <a class="code hl_variable" href="../../dc/def/classMHViewHome.html#aa853f7e5f5222148b34f69762c0b6d3e">m_serialSettings</a>-&gt;set_sensitive(<span class="keyword">false</span>);</div>
<div class="line"><a id="l00214" name="l00214"></a><span class="lineno"> 214</span>}</div>
<div class="ttc" id="aclassMHViewHome_html_a1259a5c575507dc6bd6e86c0aa5751ee"><div class="ttname"><a href="../../dc/def/classMHViewHome.html#a1259a5c575507dc6bd6e86c0aa5751ee">MHViewHome::m_disconnect</a></div><div class="ttdeci">MHRPtr&lt; Gtk::MenuItem &gt; m_disconnect</div><div class="ttdoc">Application Disconnect menu-item.</div><div class="ttdef"><b>Definition:</b> <a href="../../d0/ddf/microhil__view__home_8h_source.html#l00170">microhil_view_home.h:170</a></div></div>
<div class="ttc" id="aclassMHViewHome_html_a2ca905b5386185a264c9b942434cd444"><div class="ttname"><a href="../../dc/def/classMHViewHome.html#a2ca905b5386185a264c9b942434cd444">MHViewHome::m_toggleTimerChannels</a></div><div class="ttdeci">std::vector&lt; MHRPtr&lt; Gtk::ToggleButton &gt; &gt; m_toggleTimerChannels</div><div class="ttdoc">Toggle button for starting channel timer.</div><div class="ttdef"><b>Definition:</b> <a href="../../d0/ddf/microhil__view__home_8h_source.html#l00206">microhil_view_home.h:206</a></div></div>
<div class="ttc" id="aclassMHViewHome_html_a4ccccb1d79d8b65d11371f6c897606ea"><div class="ttname"><a href="../../dc/def/classMHViewHome.html#a4ccccb1d79d8b65d11371f6c897606ea">MHViewHome::mapping</a></div><div class="ttdeci">void mapping()</div><div class="ttdoc">Maps channels (signals and slots)</div><div class="ttdef"><b>Definition:</b> <a href="../../d5/d63/microhil__view__home__map_8cc_source.html#l00028">microhil_view_home_map.cc:28</a></div></div>
Expand All @@ -287,7 +289,7 @@
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="../../dir_b2f003339c516cc00c8cadcafbe82f13.html">view</a></li><li class="navelem"><a class="el" href="../../dir_114fe11fb74ba151b2b0aa05d224511f.html">home</a></li><li class="navelem"><a class="el" href="../../d0/d1b/microhil__view__home_8cc.html">microhil_view_home.cc</a></li>
<li class="footer">Generated on Sun Oct 1 2023 22:41:06 for microhildesk by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.4 </li>
<li class="footer">Generated on Mon Oct 2 2023 23:24:13 for microhildesk by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.4 </li>
</ul>
</div>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated on Sun Oct 1 2023 22:41:06 for microhildesk by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.4 </li>
<li class="footer">Generated on Mon Oct 2 2023 23:24:13 for microhildesk by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.4 </li>
</ul>
</div>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="../../dir_b2f003339c516cc00c8cadcafbe82f13.html">view</a></li><li class="navelem"><a class="el" href="../../dir_114fe11fb74ba151b2b0aa05d224511f.html">home</a></li><li class="navelem"><a class="el" href="../../d0/d59/microhil__view__home__signals_8cc.html">microhil_view_home_signals.cc</a></li>
<li class="footer">Generated on Sun Oct 1 2023 22:41:06 for microhildesk by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.4 </li>
<li class="footer">Generated on Mon Oct 2 2023 23:24:13 for microhildesk by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.4 </li>
</ul>
</div>
</body>
Expand Down

0 comments on commit 6e9b842

Please sign in to comment.