Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor Code Cleanups #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 15 additions & 18 deletions firmware/focuser_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,27 @@ using namespace FS;
/////////////////////////////////////////////////////////////////////////

Focuser::Focuser(
std::unique_ptr<NetInterface> netArg,
std::unique_ptr<HWI> hardwareArg,
std::unique_ptr<DebugInterface> debugArg,
const BuildParams params
) : buildParams{ params }
std::shared_ptr<NetInterface> netArg,
std::shared_ptr<HWI> hardwareArg,
std::shared_ptr<DebugInterface> debugArg,
const BuildParams params
) : net { netArg },
hardware { hardwareArg },
debugLog { debugArg },
buildParams { params },
dir { Dir::FORWARD },
motorState { MotorState::OFF},
focuserPosition { 0 },
isSynched { false },
time { 0 },
uSecRemainder { 0 },
timeLastInterruptingCommandOccured { 0 }
{
focuserPosition = 0;
isSynched = false;
time = 0;
uSecRemainder = 0;
timeLastInterruptingCommandOccured = 0;
motorState = MotorState::OFF;

std::swap( net, netArg );
std::swap( hardware, hardwareArg );
std::swap( debugLog, debugArg );

DebugInterface& dlog = *debugLog;
dlog << "Bringing up net interface\n";

// Bring up the interface to the controlling computer

net->setup( dlog );
WifiDebugOstream log( debugLog.get(), net.get() );

//
Expand All @@ -86,7 +84,6 @@ Focuser::Focuser(
//
setMotor( log, MotorState::ON );

dir = Dir::FORWARD;
hardware->DigitalWrite( HWI::Pin::DIR, HWI::PinState::DIR_FORWARD);
hardware->DigitalWrite( HWI::Pin::STEP, HWI::PinState::STEP_INACTIVE );

Expand Down
12 changes: 6 additions & 6 deletions firmware/focuser_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,9 @@ class Focuser
/// @param[in] params - Hardware Parameters
///
Focuser(
std::unique_ptr<NetInterface> netArg,
std::unique_ptr<HWI> hardwareArg,
std::unique_ptr<DebugInterface> debugArg,
std::shared_ptr<NetInterface> netArg,
std::shared_ptr<HWI> hardwareArg,
std::shared_ptr<DebugInterface> debugArg,
const BuildParams params
);

Expand Down Expand Up @@ -395,9 +395,9 @@ class Focuser
void doDebugOff( CommandParser::CommandPacket );
void doError( CommandParser::CommandPacket );

std::unique_ptr<NetInterface> net;
std::unique_ptr<HWI> hardware;
std::unique_ptr<DebugInterface> debugLog;
std::shared_ptr<NetInterface> net;
std::shared_ptr<HWI> hardware;
std::shared_ptr<DebugInterface> debugLog;

const BuildParams buildParams;

Expand Down
12 changes: 6 additions & 6 deletions firmware/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ void loop() {
}

void setup() {
std::unique_ptr<NetInterface> wifi( new WifiInterfaceEthernet );
std::unique_ptr<HWI> hardware( new HardwareESP8266 );
std::unique_ptr<DebugInterface> debug( new DebugESP8266 );
auto debug = std::make_shared<DebugESP8266>();
auto wifi = std::make_shared<WifiInterfaceEthernet>( *(debug.get()) );
auto hardware = std::make_shared<HardwareESP8266>();
FS::BuildParams params( FS::Build::LOW_POWER_HYPERSTAR_FOCUSER );
focuser = std::unique_ptr<FS::Focuser>(
new FS::Focuser(
std::move(wifi),
std::move(hardware),
std::move(debug),
wifi,
hardware,
debug,
params )
);
}
12 changes: 11 additions & 1 deletion firmware/net_esp8266.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
#include "wifi_ostream.h"
#include "wifi_debug_ostream.h"

void WifiInterfaceEthernet::setup( DebugInterface& log ) {
WifiInterfaceEthernet::WifiInterfaceEthernet( DebugInterface& log )
: m_lastSlotAllocated{0},
m_kickout{0},
m_nextToKick{m_connections.begin()}
{
reset();
delay(10);

log << "Init Wifi\n";
Expand Down Expand Up @@ -39,6 +44,11 @@ void WifiInterfaceEthernet::setup( DebugInterface& log ) {
//wifi_set_sleep_type(LIGHT_SLEEP_T);
}

WifiInterfaceEthernet::~WifiInterfaceEthernet()
{
reset();
}

bool WifiInterfaceEthernet::getString( WifiDebugOstream& log, std::string& string )
{
handleNewConnections( log );
Expand Down
13 changes: 4 additions & 9 deletions firmware/net_esp8266.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,12 @@ class WifiConnectionEthernet: public NetConnection {
class WifiInterfaceEthernet: public NetInterface {
public:

WifiInterfaceEthernet() : m_lastSlotAllocated{0}, m_kickout{0}, m_nextToKick{m_connections.begin()}
{
reset();
}
~WifiInterfaceEthernet()
{
reset();
}
WifiInterfaceEthernet( DebugInterface& log);
WifiInterfaceEthernet() = delete;
WifiInterfaceEthernet(const WifiInterfaceEthernet& ) = delete;
~WifiInterfaceEthernet();

void reset( void );
void setup( DebugInterface& debugLog ) override;

bool getString( WifiDebugOstream &log, std::string& string ) override;
std::streamsize write( const char_type* s, std::streamsize n ) override;
Expand Down
4 changes: 1 addition & 3 deletions firmware/net_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ class NetInterface {
struct category : public beefocus_tag {};
using char_type = char;

NetInterface()
NetInterface( void )
{
}
virtual ~NetInterface()
{
}

virtual void setup( DebugInterface &debugLog ) = 0;

virtual bool getString( WifiDebugOstream &log, std::string& string ) = 0;
virtual std::streamsize write( const char_type* s, std::streamsize n ) = 0;
virtual void flush() = 0;
Expand Down
4 changes: 0 additions & 4 deletions firmware_sim/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ class NetInterfaceSim: public NetInterface {
struct category: virtual beefocus_tag {};
using char_type = char;

void setup( DebugInterface& debugLog ) override
{
debugLog << "Simulator Net Interface Init\n";
}
bool getString( WifiDebugOstream& log, std::string& input ) override
{
fd_set readfds;
Expand Down
8 changes: 1 addition & 7 deletions unit_tests/test_mock_net.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef __TEST_MOCK_NET_H__
#define __TEST_MOCK_NET_H__

#include <algorithm> // for std::copy_if
#include "net_interface.h"
#include "test_mock_event.h"

Expand Down Expand Up @@ -78,13 +79,6 @@ class NetMockSimpleTimed: public NetInterface
NetMockSimpleTimed( const HWMockTimed& ) = delete;
NetMockSimpleTimed& operator=( const NetMockSimpleTimed& ) = delete;

///
/// @brief Implement setup required by NetInterface. Does nothing.
///
void setup( DebugInterface& debugLog ) override
{
}

///
/// @brief Get input from the net interface
/// @param[in] log - Debug Log (ignored)
Expand Down