mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-04-21 23:50:31 -04:00
152 lines
4.3 KiB
C++
152 lines
4.3 KiB
C++
|
|
#include <memory>
|
|
#include <list>
|
|
|
|
#include "../module-gui/gui/core/ImageManager.hpp"
|
|
#include "log/log.hpp"
|
|
#include "memory/usermem.h"
|
|
#include "ticks.hpp"
|
|
|
|
//module-applications
|
|
#include "application-clock/ApplicationClock.hpp"
|
|
#include "application-viewer/ApplicationViewer.hpp"
|
|
#include "application-desktop/ApplicationDesktop.hpp"
|
|
|
|
//module-services
|
|
#include "service-gui/ServiceGUI.hpp"
|
|
#include "service-gui/messages/DrawMessage.hpp"
|
|
#include "ServiceEink.hpp"
|
|
#include "service-appmgr/ApplicationManager.hpp"
|
|
#include "service-evtmgr/EventManager.hpp"
|
|
#include "service-db/ServiceDB.hpp"
|
|
#include "service-db/api/DBServiceAPI.hpp"
|
|
|
|
//module-bsp
|
|
#include "bsp.hpp"
|
|
#include "vfs.hpp"
|
|
#include "keyboard/keyboard.hpp"
|
|
|
|
#include "SystemManager/SystemManager.hpp"
|
|
|
|
#include "battery-charger/battery_charger.hpp"
|
|
|
|
class vfs vfs;
|
|
|
|
class BlinkyService : public sys::Service {
|
|
public:
|
|
BlinkyService(const std::string& name)
|
|
: sys::Service(name)
|
|
{
|
|
timer_id = CreateTimer(1000,true);
|
|
ReloadTimer(timer_id);
|
|
}
|
|
|
|
~BlinkyService(){
|
|
}
|
|
|
|
// Invoked upon receiving data message
|
|
sys::Message_t DataReceivedHandler(sys::DataMessage* msgl) override{
|
|
|
|
return std::make_shared<sys::ResponseMessage>( );
|
|
}
|
|
|
|
// Invoked when timer ticked
|
|
void TickHandler(uint32_t id) override{
|
|
LOG_DEBUG("Blinky service tick!");
|
|
|
|
/* uint16_t val;
|
|
bsp::battery_fuelGaugeRead(bsp::batteryChargerRegisters::RepCap_REG, &val);
|
|
LOG_INFO("Current capacity: %d", val);
|
|
bsp::battery_fuelGaugeRead(bsp::batteryChargerRegisters::RepSOC_REG, &val);
|
|
uint16_t percent = val & 0xff00;
|
|
percent = percent >> 8;
|
|
LOG_INFO("Current percent: %d", percent);
|
|
bsp::battery_fuelGaugeRead(bsp::batteryChargerRegisters::VCELL_REG, &val);
|
|
float voltage = (float) val * 0.078125;
|
|
LOG_INFO("Current voltage: %d", (uint32_t)voltage);
|
|
|
|
bsp::battery_chargerTopControllerRead(static_cast<bsp::batteryChargerRegisters>(0x22), &val);
|
|
LOG_INFO("Interupt source: %d", val);
|
|
bsp::battery_fuelGaugeRead(bsp::batteryChargerRegisters::STATUS_REG, &val);
|
|
|
|
LOG_INFO("status reg 0x%x", val);
|
|
|
|
if(val & 0x0080)
|
|
{
|
|
LOG_WARN("Clear status register");
|
|
bsp::battery_fuelGaugeWrite(bsp::batteryChargerRegisters::STATUS_REG, val);
|
|
}
|
|
*/
|
|
//uint32_t pin = GPIO_PinRead(BOARD_BATTERY_CHARGER_INTB_GPIO, BOARD_BATTERY_CHARGER_INTB_PIN);
|
|
// LOG_INFO("INTB pin %d", pin);
|
|
}
|
|
|
|
|
|
// Invoked during initialization
|
|
sys::ReturnCodes InitHandler() override{
|
|
return sys::ReturnCodes::Success;
|
|
}
|
|
|
|
sys::ReturnCodes DeinitHandler() override{
|
|
return sys::ReturnCodes::Success;
|
|
}
|
|
|
|
sys::ReturnCodes WakeUpHandler() override{
|
|
return sys::ReturnCodes::Success;
|
|
}
|
|
|
|
|
|
sys::ReturnCodes SleepHandler() override{
|
|
return sys::ReturnCodes::Success;
|
|
}
|
|
|
|
uint32_t timer_id= 0;
|
|
};
|
|
|
|
|
|
int SystemStart(sys::SystemManager* sysmgr)
|
|
{
|
|
vfs.Init();
|
|
|
|
bool ret;
|
|
ret = sysmgr->CreateService(std::make_shared<sgui::ServiceGUI>("ServiceGUI", 480, 600 ),sysmgr);
|
|
ret |= sysmgr->CreateService(std::make_shared<ServiceEink>("ServiceEink"),sysmgr);
|
|
ret |= sysmgr->CreateService(std::make_shared<EventManager>("EventManager"),sysmgr);
|
|
ret |= sysmgr->CreateService(std::make_shared<ServiceDB>(),sysmgr);
|
|
//ret |= sysmgr->CreateService(std::make_shared<BlinkyService>("Blinky"),sysmgr);
|
|
|
|
//vector with launchers to applications
|
|
std::vector< std::unique_ptr<app::ApplicationLauncher> > applications;
|
|
|
|
//launcher for desktop application
|
|
std::unique_ptr<app::ApplicationLauncher> viewerLauncher = std::unique_ptr<app::ApplicationDesktopLauncher>(new app::ApplicationDesktopLauncher());
|
|
applications.push_back( std::move(viewerLauncher) );
|
|
|
|
//start application manager
|
|
ret |= sysmgr->CreateService(std::make_shared<sapm::ApplicationManager>("ApplicationManager",sysmgr,applications),sysmgr );
|
|
|
|
if(ret){
|
|
return 0;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int main() {
|
|
|
|
|
|
LOG_PRINTF("Launching PurePhone..\n ");
|
|
|
|
bsp::BoardInit();
|
|
|
|
auto sysmgr = std::make_shared<sys::SystemManager>(5000);
|
|
|
|
sysmgr->StartSystem();
|
|
|
|
sysmgr->RegisterInitFunction(SystemStart);
|
|
|
|
cpp_freertos::Thread::StartScheduler();
|
|
|
|
return 0;
|
|
}
|