Skip to content

Commit

Permalink
Emulator: adjusted for corrctly initial state of pins
Browse files Browse the repository at this point in the history
  • Loading branch information
bcsanches committed Nov 1, 2024
1 parent d7b16ef commit 0a5ac2b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
31 changes: 23 additions & 8 deletions src/ArduinoLib/Arduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ namespace ArduinoLib
{
public:
ArduinoPin() :
//default mode is with pullup resistor
m_eMode(INPUT_PULLUP),
m_eVoltage(HIGH)
//default mode is INPUT LOW
m_eMode(INPUT),
m_eVoltage(LOW)
{
//empty
}
Expand All @@ -58,18 +58,28 @@ namespace ArduinoLib
{
m_eMode = mode;

if (mode != INPUT_PULLUP)
if (mode == INPUT_PULLUP)
m_eVoltage = HIGH;
else if (mode == INPUT)
m_eVoltage = LOW;
}

void digitalWrite(VoltageModes mode)
void digitalWrite(VoltageModes voltage)
{
m_eVoltage = mode;
if (m_eMode != OUTPUT)
{
//writing HIGH to input pin turn on PULLUP
setPinMode(voltage == HIGH ? INPUT_PULLUP : INPUT);
}
else
{
m_eVoltage = voltage;
}
}

int digitalRead()
{
return m_eVoltage;
return m_eMode == INPUT_PULLUP ? (m_eVoltage == HIGH ? LOW : HIGH) : m_eVoltage;
}

void setDigitalVoltage(VoltageModes mode)
Expand Down Expand Up @@ -124,7 +134,7 @@ namespace ArduinoLib
DynamicLibrary g_ModuleLib;
std::string g_strModuleName;

void Setup(std::string moduleName, dcclite::Logger_t log)
void Setup(std::string moduleName, dcclite::Logger_t log, const char *projectPath)
{
dcclite::LogReplace(log);

Expand All @@ -135,6 +145,11 @@ namespace ArduinoLib
g_pfnSetup = reinterpret_cast<ArduinoProc_t>(g_ModuleLib.GetSymbol("setup"));
g_pfnLoop = reinterpret_cast<ArduinoProc_t>(g_ModuleLib.GetSymbol("loop"));

if (projectPath)
{

}

g_Clock = dcclite::Clock();

detail::RomSetupModule(g_strModuleName);
Expand Down
2 changes: 1 addition & 1 deletion src/ArduinoLib/ArduinoLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace ArduinoLib
{
typedef void(*ArduinoProc_t)();

ARDUINO_API void Setup(std::string moduleName, dcclite::Logger_t log);
ARDUINO_API void Setup(std::string moduleName, dcclite::Logger_t log, const char *projectPath);

ARDUINO_API void Finalize();

Expand Down
4 changes: 2 additions & 2 deletions src/Emulator/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static bool ConsoleCtrlHandler(dcclite::ConsoleEvent event)
return true;
}

int main(int, char **)
int main(int argc, char **argv)
{
dcclite::LogInit("Emulator.log");

Expand All @@ -121,7 +121,7 @@ int main(int, char **)

dcclite::PathUtils::InitAppFolders("Emulator");

ArduinoLib::Setup("LiteDecoderLib.dll", dcclite::LogGetDefault());
ArduinoLib::Setup("LiteDecoderLib.dll", dcclite::LogGetDefault(), argc > 1 ? argv[1] : nullptr);

TerminalService terminalService;

Expand Down

0 comments on commit 0a5ac2b

Please sign in to comment.