M module-apps/Application.cpp => module-apps/Application.cpp +8 -22
@@ 588,30 588,16 @@ namespace app
return AudioServiceAPI::GetSetting(this, audio::Setting::Volume, volume);
}
- void Application::toggleTorch(bsp::torch::ColourTemperature temperature)
+ void Application::toggleTorchOnOff()
{
- using namespace bsp;
-
- auto message = std::make_shared<sevm::TorchStateMessage>(torch::Action::getState);
- auto retGetState = bus.sendUnicast(std::move(message), service::name::evt_manager, pdMS_TO_TICKS(1500));
- if (retGetState.first == sys::ReturnCodes::Success) {
- auto msgGetState = dynamic_cast<sevm::TorchStateResultMessage *>(retGetState.second.get());
- if (msgGetState == nullptr) {
- return;
- }
- auto msgSetState = std::make_shared<sevm::TorchStateMessage>(torch::Action::setState);
+ auto msg = std::make_shared<sevm::ToggleTorchOnOffMessage>();
+ bus.sendUnicast(std::move(msg), service::name::evt_manager);
+ }
- switch (msgGetState->state) {
- case torch::State::off:
- msgSetState->state = torch::State::on;
- msgSetState->colourTemp = temperature;
- break;
- case torch::State::on:
- msgSetState->state = torch::State::off;
- break;
- }
- bus.sendUnicast(msgSetState, service::name::evt_manager);
- }
+ void Application::toggleTorchColor()
+ {
+ auto msg = std::make_shared<sevm::ToggleTorchColorMessage>();
+ bus.sendUnicast(std::move(msg), service::name::evt_manager);
}
void Application::requestAction(sys::Service *sender,
M module-apps/Application.hpp => module-apps/Application.hpp +4 -2
@@ 20,7 20,6 @@
#include <list> // for list
#include <map> // for allocator, map
#include <memory> // for make_shared
-#include <module-bsp/bsp/torch/torch.hpp> // for State, State...
#include <stdint.h> // for uint32_t
#include <string> // for string
#include <utility> // for move, pair
@@ 150,6 149,7 @@ namespace app
/// perform all necessary cleanup and request System Manager to close it.
DEACTIVATING
};
+
/// c_str() function for Application::State
static const char *stateStr(State st);
@@ 290,7 290,9 @@ namespace app
}
audio::RetCode getCurrentVolume(audio::Volume &volume);
- void toggleTorch(bsp::torch::ColourTemperature temperature);
+ void toggleTorchOnOff();
+
+ void toggleTorchColor();
void cancelCallbacks(AsyncCallbackReceiver::Ptr receiver) override;
M module-apps/windows/AppWindow.cpp => module-apps/windows/AppWindow.cpp +2 -2
@@ 162,11 162,11 @@ namespace gui
if (inputEvent.keyCode == KeyCode::KEY_TORCH) {
if (inputEvent.isLongPress()) {
- application->toggleTorch(bsp::torch::ColourTemperature::warmest);
+ application->toggleTorchOnOff();
return true;
}
else if (inputEvent.isShortPress()) {
- application->toggleTorch(bsp::torch::ColourTemperature::coldest);
+ application->toggleTorchColor();
return true;
}
}
M module-bsp/board/linux/torch/torch.cpp => module-bsp/board/linux/torch/torch.cpp +3 -3
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "bsp/torch/torch.hpp"
@@ 15,7 15,7 @@ namespace bsp
namespace torch
{
State state_simulated = State::off;
- ColourTemperature currentColourTemp = warmest;
+ ColourTemperature currentColourTemp = ColourTemperature::warmest;
int32_t init(xQueueHandle qHandle)
{
@@ 38,7 38,7 @@ namespace bsp
bool turn(State state, ColourTemperature colourTemp)
{
state_simulated = state;
- if (colourTemp != no_change) {
+ if (colourTemp != ColourTemperature::noChange) {
currentColourTemp = colourTemp;
}
M module-bsp/board/rt1051/bsp/torch/torch.cpp => module-bsp/board/rt1051/bsp/torch/torch.cpp +3 -3
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "bsp/torch/torch.hpp"
@@ 24,7 24,7 @@ namespace bsp
std::shared_ptr<DriverGPIO> gpio;
const unsigned short max_current_mA = 150;
- ColourTemperature currentColourTemp = warmest;
+ ColourTemperature currentColourTemp = ColourTemperature::warmest;
int32_t init(xQueueHandle qHandle)
{
@@ 95,7 95,7 @@ namespace bsp
};
bool turn(State state, ColourTemperature colourTemp)
{
- if (colourTemp != no_change) {
+ if (colourTemp != ColourTemperature::noChange) {
currentColourTemp = colourTemp;
}
M module-bsp/bsp/torch/torch.hpp => module-bsp/bsp/torch/torch.hpp +24 -34
@@ 12,39 12,29 @@ extern "C"
#include "bsp/common.hpp"
#include <utility>
-namespace bsp
+namespace bsp::torch
{
- namespace torch
+ enum class State
{
- enum class Action
- {
- getState,
- setState,
- toggle,
- };
-
- enum class State
- {
- on,
- off,
- };
-
- enum ColourTemperature // Kelvin
- {
- no_change = 0,
- warmest = 1800,
- coldest = 6500,
- };
-
- int32_t init(xQueueHandle qHandle);
- void deinit();
-
- bool isPresent(void);
-
- bool turn(State state, ColourTemperature = no_change);
- std::pair<bool, State> getState();
- ColourTemperature getColorTemp(); // rather only for cert
- bool toggle();
- bool setCurrent(const unsigned short mA);
- } // namespace torch
-} // namespace bsp
+ on,
+ off,
+ };
+
+ enum class ColourTemperature // Kelvin
+ {
+ noChange = 0,
+ warmest = 1800,
+ coldest = 6500,
+ };
+
+ int32_t init(xQueueHandle qHandle);
+ void deinit();
+
+ bool isPresent(void);
+
+ bool turn(State state, ColourTemperature = ColourTemperature::noChange);
+ std::pair<bool, State> getState();
+ ColourTemperature getColorTemp();
+ bool toggle();
+ bool setCurrent(const unsigned short mA);
+} // namespace bsp::torch
M module-services/service-evtmgr/EventManager.cpp => module-services/service-evtmgr/EventManager.cpp +28 -20
@@ 171,26 171,6 @@ sys::MessagePointer EventManager::DataReceivedHandler(sys::DataMessage *msgl, sy
}
handled = true;
}
- else if (msgl->messageType == MessageType::EVMTorchStateMessage) {
- auto msg = dynamic_cast<sevm::TorchStateMessage *>(msgl);
- if (msg != nullptr) {
- auto message = std::make_shared<sevm::TorchStateResultMessage>(msg->action);
-
- switch (msg->action) {
- case bsp::torch::Action::getState:
- std::tie(message->success, message->state) = bsp::torch::getState();
- message->colourTemp = bsp::torch::getColorTemp();
- break;
- case bsp::torch::Action::setState:
- message->success = bsp::torch::turn(msg->state, msg->colourTemp);
- break;
- case bsp::torch::Action::toggle:
- message->success = bsp::torch::toggle();
- break;
- }
- return message;
- }
- }
else if (msgl->messageType == MessageType::CellularTimeUpdated) {
auto msg = dynamic_cast<CellularTimeNotificationMessage *>(msgl);
if (msg != nullptr) {
@@ 308,6 288,16 @@ sys::ReturnCodes EventManager::InitHandler()
return std::make_shared<sys::ResponseMessage>();
});
+ connect(sevm::ToggleTorchOnOffMessage(), [&](sys::Message *) {
+ toggleTorchOnOff();
+ return std::make_shared<sys::ResponseMessage>();
+ });
+
+ connect(sevm::ToggleTorchColorMessage(), [&](sys::Message *) {
+ toggleTorchColor();
+ return std::make_shared<sys::ResponseMessage>();
+ });
+
// initialize keyboard worker
EventWorker = std::make_unique<WorkerEvent>(this);
@@ 419,3 409,21 @@ bool EventManager::processVibraRequest(bsp::vibrator::Action act, sys::ms Repeti
}
return true;
}
+
+void EventManager::toggleTorchOnOff()
+{
+ auto state = bsp::torch::getState();
+ auto newState = (state.second == bsp::torch::State::off) ? bsp::torch::State::on : bsp::torch::State::off;
+ bsp::torch::turn(newState, bsp::torch::ColourTemperature::coldest);
+}
+
+void EventManager::toggleTorchColor()
+{
+ auto state = bsp::torch::getState();
+ if (state.second == bsp::torch::State::on) {
+ auto color = bsp::torch::getColorTemp();
+ auto newColor = (color == bsp::torch::ColourTemperature::coldest) ? bsp::torch::ColourTemperature::warmest
+ : bsp::torch::ColourTemperature::coldest;
+ bsp::torch::turn(bsp::torch::State::on, newColor);
+ }
+}
M module-services/service-evtmgr/messages/Message.cpp => module-services/service-evtmgr/messages/Message.cpp +3 -1
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include <service-evtmgr/Message.hpp>
@@ 10,4 10,6 @@ namespace sevm
{
Message::Message(MessageType messageType) : DataMessage(messageType)
{}
+
+ Message::Message() = default;
} // namespace sevm
M module-services/service-evtmgr/service-evtmgr/EVMessages.hpp => module-services/service-evtmgr/service-evtmgr/EVMessages.hpp +6 -18
@@ 123,25 123,13 @@ namespace sevm
bsp::cellular::status::value state = bsp::cellular::status::value::INACTIVE;
};
- class TorchStateMessage : public Message
- {
- public:
- TorchStateMessage(bsp::torch::Action direction) : Message(MessageType::EVMTorchStateMessage), action(direction)
- {}
- bsp::torch::Action action;
- bsp::torch::State state = bsp::torch::State::off;
- bsp::torch::ColourTemperature colourTemp = bsp::torch::ColourTemperature::no_change;
- };
+ class ToggleTorchOnOffMessage : public Message
+ {};
- class TorchStateResultMessage : public TorchStateMessage
- {
- public:
- TorchStateResultMessage(bsp::torch::Action direction) : TorchStateMessage(direction)
- {}
- bool success = false;
- };
+ class ToggleTorchColorMessage : public Message
+ {};
- class KeypadBacklightMessage : public sys::Message
+ class KeypadBacklightMessage : public Message
{
public:
explicit KeypadBacklightMessage(bsp::keypad_backlight::Action action) : action(action)
@@ 150,7 138,7 @@ namespace sevm
bsp::keypad_backlight::Action action;
};
- class KeypadBacklightResponseMessage : public sys::Message
+ class KeypadBacklightResponseMessage : public Message
{
public:
KeypadBacklightResponseMessage()
M module-services/service-evtmgr/service-evtmgr/EventManager.hpp => module-services/service-evtmgr/service-evtmgr/EventManager.hpp +2 -0
@@ 32,6 32,8 @@ class EventManager : public sys::Service
void handleMinuteUpdate(time_t timestamp);
bool processKeypadBacklightRequest(bsp::keypad_backlight::Action act);
bool processVibraRequest(bsp::vibrator::Action act, sys::ms RepetitionTime = static_cast<sys::ms>(1000));
+ void toggleTorchOnOff();
+ void toggleTorchColor();
std::shared_ptr<settings::Settings> settings;
std::unique_ptr<sys::Timer> loggerTimer;
M module-services/service-evtmgr/service-evtmgr/Message.hpp => module-services/service-evtmgr/service-evtmgr/Message.hpp +2 -1
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#pragma once
@@ 11,5 11,6 @@ namespace sevm
struct Message : public sys::DataMessage
{
Message(MessageType messageType);
+ Message();
};
}; // namespace sevm
M module-sys/Service/Message.cpp => module-sys/Service/Message.cpp +6 -1
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "Message.hpp"
@@ 54,6 54,11 @@ namespace sys
type = Type::Data;
}
+ DataMessage::DataMessage() : Message()
+ {
+ type = Type::Data;
+ }
+
ResponseMessage::ResponseMessage(ReturnCodes retCode, MessageType responseTo)
: retCode(retCode), responseTo(responseTo)
{
M module-sys/Service/Message.hpp => module-sys/Service/Message.hpp +1 -0
@@ 92,6 92,7 @@ namespace sys
public:
explicit DataMessage(MessageType messageType);
explicit DataMessage(BusChannel channel);
+ DataMessage();
// This field must by provided by the class that inherits DataMessage
MessageType messageType = MessageType::MessageTypeUninitialized;
M source/MessageType.hpp => source/MessageType.hpp +0 -2
@@ 181,8 181,6 @@ enum class MessageType
// rtc messages
EVMMinuteUpdated, ///< This message is send to current focused application on every minute time change.
EVMTimeUpdated, ///< This message is send on every time update.
- // Torch messages
- EVMTorchStateMessage,
// cellular messages
EVMGetBoard,