Skip to content

Commit 3601dde

Browse files
SP2FETSP2FET
andauthored
[EGD-4191] added keyReleased handling from service-desktop (#930)
Co-authored-by: SP2FET <[email protected]>
1 parent 2457c4b commit 3601dde

27 files changed

+341
-125
lines changed

changelog.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
# MuditaOS changelog
22

33

4-
### Added
5-
6-
* `[cellular]` Set pin functionality with Action mockup
7-
### Changed
8-
9-
* `[cellular]` Handled properly SIM READY and SIM PIN URC messages with Action mockup
10-
114

125
## Current release
136

147
### Added
15-
* `[messages][db]` File Indexer db Agent
168

9+
* `[messages][db]` File Indexer db Agent
10+
* `[testing]` Added key release simulation through service-desktop developerMode
11+
* `[cellular]` Set pin functionality with Action mockup
1712
### Changed
1813

14+
* `[cellular]` Handled properly SIM READY and SIM PIN URC messages with Action mockup
1915
* `[calendar]` Rework to use database model instead of internal model in day events list.
2016

2117
## [0.44.1 2020-10-30]
@@ -569,4 +565,3 @@
569565
* `[test]` Improved modem testing with modem shutdown detection.
570566
* `[build]` Add support for auto-releases.
571567

572-
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
2+
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
3+
4+
#pragma once
5+
6+
#include <string>
7+
8+
namespace service::name
9+
{
10+
inline const std::string service_desktop = "ServiceDesktop";
11+
};

module-services/service-desktop/ServiceDesktop.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,11 @@
1111
#include "Service/Common.hpp" // for ReturnCodes, ServicePowerMode
1212
#include "Service/Message.hpp" // for Message_t, DataMessage (ptr only), ResponseMessage (ptr only)
1313
#include "Service/Service.hpp" // for Service
14+
#include "Constants.hpp"
1415

1516
class UpdateMuditaOS;
1617
class WorkerDesktop;
1718

18-
namespace service::name
19-
{
20-
const inline std::string service_desktop = "ServiceDesktop";
21-
};
2219

2320
namespace sdesktop
2421
{

module-services/service-desktop/endpoints/developerMode/DeveloperModeEndpoint.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,13 @@ auto DeveloperModeEndpoint::handle(Context &context) -> void
1111
{
1212
switch (context.getMethod()) {
1313
case http::Method::get:
14-
helper->processGetRequest(context);
1514
break;
1615
case http::Method::post:
17-
1816
break;
1917
case http::Method::put:
20-
18+
helper->processPutRequest(context);
2119
break;
2220
case http::Method::del:
23-
2421
break;
2522
}
2623
}

module-services/service-desktop/endpoints/developerMode/DeveloperModeHelper.cpp

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
33

4+
#include <module-sys/Service/Bus.hpp>
5+
#include <module-services/service-evtmgr/Constants.hpp>
6+
#include <module-services/service-desktop/parser/MessageHandler.hpp>
47
#include "DeveloperModeHelper.hpp"
58
#include "ParserUtils.hpp" // for parserFSM
69

@@ -10,7 +13,83 @@ namespace parserFSM
1013
} // namespace parserFSM
1114

1215
using namespace parserFSM;
13-
auto DeveloperModeHelper::processGetRequest(Context &context) -> sys::ReturnCodes
16+
auto DeveloperModeHelper::processPutRequest(Context &context) -> sys::ReturnCodes
1417
{
18+
auto body = context.getBody();
19+
if (body[json::developerMode::keyPressed].is_number()) {
20+
auto keyValue = body[json::developerMode::keyPressed].int_value();
21+
sendKeypress(getKeyCode(keyValue));
22+
MessageHandler::putToSendQueue(context.createSimpleResponse());
23+
}
24+
else {
25+
context.setResponseStatus(http::Code::BadRequest);
26+
MessageHandler::putToSendQueue(context.createSimpleResponse());
27+
}
1528
return sys::ReturnCodes::Unresolved;
1629
}
30+
auto DeveloperModeHelper::getKeyCode(int val) noexcept -> bsp::KeyCodes
31+
{
32+
switch (val) {
33+
case 0:
34+
return bsp::KeyCodes::NumericKey0;
35+
case 1:
36+
return bsp::KeyCodes::NumericKey1;
37+
case 2:
38+
return bsp::KeyCodes::NumericKey2;
39+
case 3:
40+
return bsp::KeyCodes::NumericKey3;
41+
case 4:
42+
return bsp::KeyCodes::NumericKey4;
43+
case 5:
44+
return bsp::KeyCodes::NumericKey5;
45+
case 6:
46+
return bsp::KeyCodes::NumericKey6;
47+
case 7:
48+
return bsp::KeyCodes::NumericKey7;
49+
case 8:
50+
return bsp::KeyCodes::NumericKey8;
51+
case 9:
52+
return bsp::KeyCodes::NumericKey9;
53+
case '*':
54+
return bsp::KeyCodes::NumericKeyAst;
55+
case '#':
56+
return bsp::KeyCodes::NumericKeyPnd;
57+
case 'a':
58+
return bsp::KeyCodes::JoystickLeft;
59+
case 'd':
60+
return bsp::KeyCodes::JoystickRight;
61+
case 'w':
62+
return bsp::KeyCodes::JoystickUp;
63+
case 's':
64+
return bsp::KeyCodes::JoystickDown;
65+
case '\n':
66+
return bsp::KeyCodes::JoystickEnter;
67+
case 11:
68+
return bsp::KeyCodes::FnLeft;
69+
case 12:
70+
return bsp::KeyCodes::FnRight;
71+
case 13:
72+
return bsp::KeyCodes::VolUp;
73+
case 14:
74+
return bsp::KeyCodes::VolDown;
75+
case 15:
76+
return bsp::KeyCodes::Torch;
77+
case 16:
78+
return bsp::KeyCodes::SSwitchUp;
79+
case 17:
80+
return bsp::KeyCodes::SSwitchDown;
81+
case 18:
82+
return bsp::KeyCodes::SSwitchMid;
83+
default:
84+
LOG_ERROR("invalid keycode");
85+
return bsp::KeyCodes::Undefined;
86+
};
87+
}
88+
void DeveloperModeHelper::sendKeypress(bsp::KeyCodes keyCode)
89+
{
90+
auto message = std::make_shared<sevm::KbdMessage>();
91+
message->key.key_code = keyCode;
92+
message->key.state = RawKey::State::Released;
93+
94+
sys::Bus::SendUnicast(std::move(message), service::name::evt_manager, ownerServicePtr);
95+
}

module-services/service-desktop/endpoints/developerMode/DeveloperModeHelper.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
#pragma once
55

6-
#include <string> // for allocator, string
7-
6+
#include <module-bsp/bsp/keyboard/key_codes.hpp>
7+
#include <module-services/service-evtmgr/messages/KbdMessage.hpp>
88
#include "Common/Query.hpp"
99
#include "Context.hpp"
1010
#include "Service/Service.hpp"
@@ -17,15 +17,16 @@ namespace sys
1717

1818
namespace parserFSM
1919
{
20-
class Context;
2120

2221
class DeveloperModeHelper
2322
{
2423
sys::Service *ownerServicePtr = nullptr;
24+
static auto getKeyCode(int val) noexcept -> bsp::KeyCodes;
25+
void sendKeypress(bsp::KeyCodes keyCode);
2526

2627
public:
2728
DeveloperModeHelper(sys::Service *_ownerServicePtr) : ownerServicePtr(_ownerServicePtr){};
28-
auto processGetRequest(Context &context) -> sys::ReturnCodes;
29+
auto processPutRequest(Context &context) -> sys::ReturnCodes;
2930
};
3031

3132
namespace json::developerMode

module-services/service-evtmgr/EventManager.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include <service-cellular/messages/CellularMessage.hpp> // for CellularTimeNotificationMessage, RawCommandResp
1414
#include <service-evtmgr/Constants.hpp> // for evt_manager
15+
#include <service-desktop/Constants.hpp> // for ServiceDesktop
1516
#include <cassert> // for assert
1617
#include <list> // for list
1718
#include <tuple> // for tie, tuple
@@ -91,7 +92,8 @@ sys::Message_t EventManager::DataReceivedHandler(sys::DataMessage *msgl, sys::Re
9192
else if (msgl->messageType == MessageType::EVM_GPIO) {
9293
LOG_DEBUG("EVM_GPIO msg");
9394
}
94-
else if (msgl->messageType == MessageType::KBDKeyEvent && msgl->sender == this->GetName()) {
95+
else if (msgl->messageType == MessageType::KBDKeyEvent &&
96+
(msgl->sender == this->GetName() || msgl->sender == service::name::service_desktop)) {
9597

9698
auto *msg = dynamic_cast<sevm::KbdMessage *>(msgl);
9799
assert(msg);

module-utils/taglib

source/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ int main()
102102
ret &= sys::SystemManager::CreateService(std::make_shared<ServiceLwIP>(), sysmgr.get());
103103

104104
ret &= sys::SystemManager::CreateService(std::make_shared<stm::ServiceTime>(), sysmgr.get());
105+
ret &= sys::SystemManager::CreateService(std::make_shared<ServiceDesktop>(), sysmgr.get());
105106

106107
// vector with launchers to applications
107108
std::vector<std::unique_ptr<app::ApplicationLauncher>> applications;

test/harness/uart.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
from harness.common import Serial
55
import logging
66

7+
from interface.CDCSerial import CDCSerial
8+
79
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.DEBUG)
810
log = logging.getLogger(__name__)
911
conn = Serial()
12+
new_conn = CDCSerial()

0 commit comments

Comments
 (0)