Skip to content

Commit

Permalink
implemented a primitive log, fixed a bug in lcd clearArea method
Browse files Browse the repository at this point in the history
  • Loading branch information
zukaitis committed Mar 30, 2020
1 parent 4696400 commit cdc9a9d
Show file tree
Hide file tree
Showing 17 changed files with 292 additions and 3 deletions.
1 change: 1 addition & 0 deletions Firmware/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"**.html": true,
"**.gcov": true,
".settings": true,
"Debug/": true,
"output/" : true,
"unit_tests/objects/" : true,
"submodules/etl/*.*": true,
Expand Down
6 changes: 5 additions & 1 deletion Firmware/build.ninja
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ build output/src/lcd/Lcd.o: cxx src/lcd/Lcd.cpp
build output/src/lcd/84x48_mono/LcdContainer.o: cxx $
src/lcd/84x48_mono/LcdContainer.cpp
build output/src/lcd/84x48_mono/Pcd8544.o: cxx src/lcd/84x48_mono/Pcd8544.cpp
build output/src/log/Log.o: cxx src/log/Log.cpp
build output/src/log/LogContainer.o: cxx src/log/LogContainer.cpp
build output/src/log/LogThread.o: cxx src/log/LogThread.cpp
build output/src/rotary_controls/RotaryControls.o: cxx $
src/rotary_controls/RotaryControls.cpp
build output/src/testing/Testing.o: cxx src/testing/Testing.cpp
Expand Down Expand Up @@ -272,7 +275,8 @@ build $target: link output/startup/startup_stm32f411xe.o $
output/src/grid/LedOutput.o output/src/grid/PulsingLeds.o $
output/src/lcd/backlight/Backlight.o output/src/lcd/Lcd.o $
output/src/lcd/84x48_mono/LcdContainer.o $
output/src/lcd/84x48_mono/Pcd8544.o $
output/src/lcd/84x48_mono/Pcd8544.o output/src/log/Log.o $
output/src/log/LogContainer.o output/src/log/LogThread.o $
output/src/rotary_controls/RotaryControls.o $
output/src/testing/Testing.o output/src/usb/UsbMidi.o output/src/main.o $
output/src/system/GlobalInterrupts.o output/src/system/System.o $
Expand Down
3 changes: 3 additions & 0 deletions Firmware/build_settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ cxx_source_files:
- src/lcd/Lcd.cpp
- src/lcd/84x48_mono/LcdContainer.cpp
- src/lcd/84x48_mono/Pcd8544.cpp
- src/log/Log.cpp
- src/log/LogContainer.cpp
- src/log/LogThread.cpp
- src/rotary_controls/RotaryControls.cpp
- src/testing/Testing.cpp
- src/usb/UsbMidi.cpp
Expand Down
3 changes: 3 additions & 0 deletions Firmware/src/application/grid_test/GridTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "usb/UsbMidi.hpp"
#include "lcd/LcdInterface.h"
#include "application/images.h"
#include "log/info.h"

#include <freertos/ticks.hpp>

Expand Down Expand Up @@ -54,6 +55,8 @@ void GridTest::handleGridButtonEvent( const grid::ButtonEvent& event )
if (ButtonAction::PRESSED == event.action)
{
color = getRandomColor();
log::info << "yo dis is log";
log::info << "respect it";
}
grid_.setLed( event.coordinates, color );
}
Expand Down
2 changes: 1 addition & 1 deletion Firmware/src/application/startup/Startup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void Startup::run( ApplicationThread& thread )
{
}

switchApplication( ApplicationIndex_LAUNCHPAD );
switchApplication( ApplicationIndex_GRID_TEST );
}

void Startup::displayUsbConnecting()
Expand Down
2 changes: 1 addition & 1 deletion Firmware/src/lcd/Lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void Lcd::clear()

void Lcd::clearArea( const uint8_t x1, const uint8_t y1, const uint8_t x2, const uint8_t y2 )
{
driver_.clearArea( x1, y1, x1, x2 );
driver_.clearArea( x1, y1, x2, y2 );
}

void Lcd::displayImage( const uint8_t x, const uint8_t y, const Image& image )
Expand Down
58 changes: 58 additions & 0 deletions Firmware/src/log/Log.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "log/Log.h"

namespace log
{

Log::Log( LogThreadInterface* logThread ):
logThread_( *logThread ),
mode_( DisplayMode::UNTIMED ),
timeout_( 0 )
{
}

Log::~Log() = default;

void Log::operator<<( const etl::string_view& message ) const
{
logThread_.append( message );
display();
}

void Log::operator<<( const char* message ) const
{
logThread_.append( message );
display();
}

void Log::setDisplayTimeout( uint32_t timeoutMs )
{

}

void Log::disableDisplayTimeout()
{

}

void Log::disableDisplay()
{

}

void Log::display() const
{
switch (mode_)
{
case DisplayMode::TIMED:
logThread_.displayFor( timeout_ );
break;
case DisplayMode::UNTIMED:
logThread_.display();
break;
case DisplayMode::OFF:
default:
break;
}
}

} // namespace log
40 changes: 40 additions & 0 deletions Firmware/src/log/Log.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once

#include "log/LogInterface.h"
#include "log/LogThreadInterface.h"

#include <etl/string_view.h>

namespace log
{

class Log : public LogInterface
{
public:
explicit Log( LogThreadInterface* log );
~Log() override;

void operator<<( const etl::string_view& message ) const override;
void operator<<( const char* message ) const override;

void setDisplayTimeout( uint32_t timeoutMs ) override;
void disableDisplayTimeout() override;
void disableDisplay() override;

private:
void display() const;

LogThreadInterface& logThread_;

enum class DisplayMode
{
OFF,
TIMED,
UNTIMED
};

DisplayMode mode_;
uint32_t timeout_;
};

} // namespace log
28 changes: 28 additions & 0 deletions Firmware/src/log/LogContainer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "log/LogThread.h"
#include "log/info.h"

#include "main.hpp"

namespace log
{

LogInterface& info = Main::getInstance().getLogContainer().getInfo();

LogContainer::LogContainer( lcd::LcdInterface* lcdInterface ):
logThread_( lcdInterface ),
info_( &logThread_ ),
error_( &logThread_ )
{
}

LogInterface& LogContainer::getInfo()
{
return info_;
}

LogInterface& LogContainer::getError()
{
return error_;
}

} // namespace log
25 changes: 25 additions & 0 deletions Firmware/src/log/LogContainer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include "lcd/LcdInterface.h"
#include "log/Log.h"
#include "log/LogThread.h"

namespace log
{

class LogContainer
{
public:
explicit LogContainer( lcd::LcdInterface* lcdInterface );

LogInterface& getInfo();
LogInterface& getError();

private:
LogThread logThread_;

Log info_;
Log error_;
};

} // namespace log
22 changes: 22 additions & 0 deletions Firmware/src/log/LogInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <cstdint>
#include <etl/string_view.h>

namespace log
{

class LogInterface
{
public:
virtual ~LogInterface() = default;

virtual void operator<<( const etl::string_view& message ) const = 0;
virtual void operator<<( const char* message ) const = 0;

virtual void setDisplayTimeout( uint32_t timeoutMs ) = 0;
virtual void disableDisplayTimeout() = 0;
virtual void disableDisplay() = 0;
};

}
36 changes: 36 additions & 0 deletions Firmware/src/log/LogThread.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "log/LogThread.h"

namespace log
{

LogThread::LogThread( lcd::LcdInterface* lcd ):
Thread( "Log", 256, 3 ),
lcd_( *lcd ),
lineNumber_( 0 )
{
}

LogThread::~LogThread() = default;

void LogThread::append( const etl::string_view& message )
{
lcd_.clearArea( 0, lineNumber_ * 8, 83, lineNumber_ * 8 + 7 );
lcd_.print( message.begin(), 0, lineNumber_ * 8 );

lineNumber_ = (lineNumber_ + 1) % 6;
}

void LogThread::display()
{
}

void LogThread::displayFor( const uint32_t timeMs )
{
}

void LogThread::Run()
{
}


} // namespace log
30 changes: 30 additions & 0 deletions Firmware/src/log/LogThread.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include "log/LogThreadInterface.h"

#include "lcd/LcdInterface.h"
#include <freertos/thread.hpp>
#include <freertos/semaphore.hpp>

namespace log
{

class LogThread : public LogThreadInterface, private freertos::Thread
{
public:
explicit LogThread( lcd::LcdInterface* lcd );
~LogThread() override;

void append( const etl::string_view& message ) override;
void display() override;
void displayFor( uint32_t timeMs ) override;

void Run() override;

private:
lcd::LcdInterface& lcd_;

uint8_t lineNumber_;
};

} // namespace log
20 changes: 20 additions & 0 deletions Firmware/src/log/LogThreadInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <cstdint>
#include <etl/string_view.h>

namespace log
{

class LogThreadInterface
{
public:
~LogThreadInterface() = default;

virtual void append( const etl::string_view& message ) = 0;
virtual void display() = 0;
virtual void displayFor( uint32_t timeMs ) = 0;

};

} // namespace log
9 changes: 9 additions & 0 deletions Firmware/src/log/info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once
#include "log/LogInterface.h"

namespace log
{

extern LogInterface& info;

}
6 changes: 6 additions & 0 deletions Firmware/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Main::Main() :
backlightDriver_( hardware::lcd::BacklightDriver() ),
lcdContainer_( &lcdSpi_, &backlightDriver_ ),
testing_( &gridDriver_ ),
logContainer_( &lcdContainer_.getLcd() ),
applicationController_( application::ApplicationController(
&additionalButtons_, &gridContainer_.getGrid(), &rotaryControls_, &usbMidi_ ) ),
startup_( applicationController_, gridDriver_, lcdContainer_.getLcd(), system_ ),
Expand All @@ -47,6 +48,11 @@ Main::Main() :
applicationController_.initialize( applicationList );
}

log::LogContainer& Main::getLogContainer()
{
return logContainer_;
}

void Main::run()
{
// globalInterrupts_.disable();
Expand Down
4 changes: 4 additions & 0 deletions Firmware/src/main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "hardware/lcd/Spi.h"
#include "hardware/lcd/BacklightDriver.h"
#include "LcdContainer.h"
#include "log/LogContainer.h"

#include "application/internal_menu/InternalMenu.hpp"
#include "application/launchpad/Launchpad.hpp"
Expand All @@ -32,6 +33,8 @@ class Main
return instance;
}

log::LogContainer& getLogContainer();

void run();
private:
Main();
Expand All @@ -47,6 +50,7 @@ class Main
hardware::lcd::BacklightDriver backlightDriver_;
lcd::LcdContainer lcdContainer_;
testing::Testing testing_;
log::LogContainer logContainer_;
application::ApplicationController applicationController_;
application::Startup startup_;
application::GridTest gridTest_;
Expand Down

0 comments on commit cdc9a9d

Please sign in to comment.