Skip to content

Commit

Permalink
fix: fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
YarikRevich committed Apr 7, 2024
1 parent 673e3a9 commit bad3a4e
Show file tree
Hide file tree
Showing 9 changed files with 485 additions and 123 deletions.
312 changes: 243 additions & 69 deletions Core/External/Proto/Generated/Content/settings.h

Large diffs are not rendered by default.

52 changes: 51 additions & 1 deletion Core/External/Proto/Helper/proto_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,57 @@ bool ProtoHelper::is_settings_bus_request_content_of_set_gain_settings_type(
return content.settingsType() == light_detector::SettingsType::SetGain;
}

bool ProtoHelper::is_settings_bus_request_content_of_set_gain_settings_type_of_low_type(
const light_detector::SettingsBusRequestContent &content) {
return content.get_setGainValue() == light_detector::SetGrainSettingType::Low;
}

bool ProtoHelper::is_settings_bus_request_content_of_set_gain_settings_type_of_medium_type(
const light_detector::SettingsBusRequestContent &content) {
return content.get_setGainValue() == light_detector::SetGrainSettingType::Medium;
}

bool ProtoHelper::is_settings_bus_request_content_of_set_gain_settings_type_of_high_type(
const light_detector::SettingsBusRequestContent &content) {
return content.get_setGainValue() == light_detector::SetGrainSettingType::High;
}

bool ProtoHelper::is_settings_bus_request_content_of_set_gain_settings_type_of_max_type(
const light_detector::SettingsBusRequestContent &content) {
return content.get_setGainValue() == light_detector::SetGrainSettingType::Max;
}

bool ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type(
const light_detector::SettingsBusRequestContent &content) {
return content.settingsType() == light_detector::SettingsType::SetIntegralTime;
}
}

bool ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type_of_first_type(
const light_detector::SettingsBusRequestContent &content) {
return content.get_setIntegralTimeValue() == light_detector::SetIntegralTimeSettingType::First;
}

bool ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type_of_second_type(
const light_detector::SettingsBusRequestContent &content) {
return content.get_setIntegralTimeValue() == light_detector::SetIntegralTimeSettingType::Second;
}

bool ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type_of_third_type(
const light_detector::SettingsBusRequestContent &content) {
return content.get_setIntegralTimeValue() == light_detector::SetIntegralTimeSettingType::Third;
}

bool ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type_of_forth_type(
const light_detector::SettingsBusRequestContent &content) {
return content.get_setIntegralTimeValue() == light_detector::SetIntegralTimeSettingType::Forth;
}

bool ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type_of_fifth_type(
const light_detector::SettingsBusRequestContent &content) {
return content.get_setIntegralTimeValue() == light_detector::SetIntegralTimeSettingType::Fifth;
}

bool ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type_of_sixth_type(
const light_detector::SettingsBusRequestContent &content) {
return content.get_setIntegralTimeValue() == light_detector::SetIntegralTimeSettingType::Sixth;
}
90 changes: 90 additions & 0 deletions Core/External/Proto/Helper/proto_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,42 @@ class ProtoHelper {
static bool is_settings_bus_request_content_of_set_gain_settings_type(
const light_detector::SettingsBusRequestContent &content);

/**
* Checks if the given settings bus request content of set gain settings type of low type.
*
* @param content - given settings bus request content.
* @return result of the check.
*/
static bool is_settings_bus_request_content_of_set_gain_settings_type_of_low_type(
const light_detector::SettingsBusRequestContent &content);

/**
* Checks if the given settings bus request content of set gain settings type of medium type.
*
* @param content - given settings bus request content.
* @return result of the check.
*/
static bool is_settings_bus_request_content_of_set_gain_settings_type_of_medium_type(
const light_detector::SettingsBusRequestContent &content);

/**
* Checks if the given settings bus request content of set gain settings type of high type.
*
* @param content - given settings bus request content.
* @return result of the check.
*/
static bool is_settings_bus_request_content_of_set_gain_settings_type_of_high_type(
const light_detector::SettingsBusRequestContent &content);

/**
* Checks if the given settings bus request content of set gain settings type of max type.
*
* @param content - given settings bus request content.
* @return result of the check.
*/
static bool is_settings_bus_request_content_of_set_gain_settings_type_of_max_type(
const light_detector::SettingsBusRequestContent &content);

/**
* Checks if the given settings bus request content of set integral time settings type.
*
Expand All @@ -156,6 +192,60 @@ class ProtoHelper {
*/
static bool is_settings_bus_request_content_of_set_integral_time_settings_type(
const light_detector::SettingsBusRequestContent &content);

/**
* Checks if the given settings bus request content set integral time of settings type of first type.
*
* @param content - given settings bus request content.
* @return result of the check.
*/
static bool is_settings_bus_request_content_of_set_integral_time_settings_type_of_first_type(
const light_detector::SettingsBusRequestContent &content);

/**
* Checks if the given settings bus request content set integral time of settings type of second type.
*
* @param content - given settings bus request content.
* @return result of the check.
*/
static bool is_settings_bus_request_content_of_set_integral_time_settings_type_of_second_type(
const light_detector::SettingsBusRequestContent &content);

/**
* Checks if the given settings bus request content set integral time of settings type of third type.
*
* @param content - given settings bus request content.
* @return result of the check.
*/
static bool is_settings_bus_request_content_of_set_integral_time_settings_type_of_third_type(
const light_detector::SettingsBusRequestContent &content);

/**
* Checks if the given settings bus request content set integral time of settings type of forth type.
*
* @param content - given settings bus request content.
* @return result of the check.
*/
static bool is_settings_bus_request_content_of_set_integral_time_settings_type_of_forth_type(
const light_detector::SettingsBusRequestContent &content);

/**
* Checks if the given settings bus request content set integral time of settings type of fifth type.
*
* @param content - given settings bus request content.
* @return result of the check.
*/
static bool is_settings_bus_request_content_of_set_integral_time_settings_type_of_fifth_type(
const light_detector::SettingsBusRequestContent &content);

/**
* Checks if the given settings bus request content set integral time of settings type of sixth type.
*
* @param content - given settings bus request content.
* @return result of the check.
*/
static bool is_settings_bus_request_content_of_set_integral_time_settings_type_of_sixth_type(
const light_detector::SettingsBusRequestContent &content);
};

#endif //LIGHT_DETECTOR_PROTO_HELPER_H
50 changes: 44 additions & 6 deletions Core/External/Scheduler/Handler/scheduler_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,18 +340,26 @@ int SchedulerHandler::process_settings_bus_request_content_response(
if (ProtoHelper::is_settings_bus_request_content_of_reset_settings_type(
settings_bus_request_content)) {

return SchedulerHandler::process_settings_bus_request_content_of_reset_settings_type_response();
if (SchedulerHandler::process_settings_bus_request_content_of_reset_settings_type_response() != EXIT_SUCCESS) {
return EXIT_FAILURE;
}
} else if (ProtoHelper::is_settings_bus_request_content_of_set_gain_settings_type(
settings_bus_request_content)) {

return SchedulerHandler::process_settings_bus_request_content_of_set_gain_settings_type_response(content);
if (SchedulerHandler::process_settings_bus_request_content_of_set_gain_settings_type_response(content) != EXIT_SUCCESS) {
return EXIT_FAILURE;
}
} else if (ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type(
settings_bus_request_content)) {

return SchedulerHandler::process_settings_bus_request_content_of_set_integral_time_settings_type_response(
content);
if (SchedulerHandler::process_settings_bus_request_content_of_set_integral_time_settings_type_response(
content) != EXIT_SUCCESS) {
return EXIT_FAILURE;
}
}

Indicator::toggle_action_success();

return EXIT_SUCCESS;
}

Expand Down Expand Up @@ -392,7 +400,19 @@ int SchedulerHandler::process_settings_bus_request_content_of_set_gain_settings_
if (TSL2591X::is_available()) {
settings_bus_response_content.set_deviceId(TSL2591X::get_device_id());

TSL2591X::set_gain(content.get_settingsBus().get_value());
if (ProtoHelper::is_settings_bus_request_content_of_set_gain_settings_type_of_low_type(
content.settingsBus())) {
TSL2591X::set_gain(LOW_AGAIN);
} else if (ProtoHelper::is_settings_bus_request_content_of_set_gain_settings_type_of_medium_type(
content.settingsBus())) {
TSL2591X::set_gain(MEDIUM_AGAIN);
} else if (ProtoHelper::is_settings_bus_request_content_of_set_gain_settings_type_of_high_type(
content.settingsBus())) {
TSL2591X::set_gain(HIGH_AGAIN);
} else if (ProtoHelper::is_settings_bus_request_content_of_set_gain_settings_type_of_max_type(
content.settingsBus())) {
TSL2591X::set_gain(MAX_AGAIN);
}

settings_bus_response_content.set_result(true);
} else {
Expand All @@ -419,7 +439,25 @@ int SchedulerHandler::process_settings_bus_request_content_of_set_integral_time_
if (TSL2591X::is_available()) {
settings_bus_response_content.set_deviceId(TSL2591X::get_device_id());

TSL2591X::set_integral_time(content.get_settingsBus().get_value());
if (ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type_of_first_type(
content.settingsBus())) {
TSL2591X::set_integral_time(ATIME_100MS);
} else if (ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type_of_second_type(
content.settingsBus())) {
TSL2591X::set_integral_time(ATIME_200MS);
} else if (ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type_of_third_type(
content.settingsBus())) {
TSL2591X::set_integral_time(ATIME_300MS);
} else if (ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type_of_forth_type(
content.settingsBus())) {
TSL2591X::set_integral_time(ATIME_400MS);
} else if (ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type_of_fifth_type(
content.settingsBus())) {
TSL2591X::set_integral_time(ATIME_500MS);
} else if (ProtoHelper::is_settings_bus_request_content_of_set_integral_time_settings_type_of_sixth_type(
content.settingsBus())) {
TSL2591X::set_integral_time(ATIME_600MS);
}

settings_bus_response_content.set_result(true);
} else {
Expand Down
16 changes: 0 additions & 16 deletions Core/External/Tools/Indicator/indicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@ void Indicator::toggle_action_success() {
HAL_Delay(2000);
};

void Indicator::toggle_action_failure() {
for (int i = 0; i < 4; i++) {
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
HAL_Delay(200);
}

HAL_Delay(1000);
};

void Indicator::toggle_invalid_request() {
for (int i = 0; i < 2; i++) {
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
Expand All @@ -53,10 +44,3 @@ void Indicator::toggle_invalid_response() {

HAL_Delay(2000);
}

void Indicator::toggle_n(uint8_t n) {
for (int i = 0; i < n; i++) {
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
HAL_Delay(200);
}
}
10 changes: 0 additions & 10 deletions Core/External/Tools/Indicator/indicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ class Indicator {
*/
static void toggle_initialization_success();

/**
* Indicated initialization process success.
*/
static void toggle_n(uint8_t n);

/**
* Indicated initialization process failure.
*/
Expand All @@ -28,11 +23,6 @@ class Indicator {
*/
static void toggle_action_success();

/**
* Indicated operation action failure.
*/
static void toggle_action_failure();

/**
* Indicated invalid incoming request.
*/
Expand Down
20 changes: 10 additions & 10 deletions Resources/Proto/Container/Content/settings.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ enum SettingsType {
// Represents all the available set grain value presets, which can be used with settings bus.
enum SetGrainSettingType {
SetGrainSettingNone = 0; // Stub enum to handle serialization.
LOW = 1;
MEDIUM = 2;
HIGH = 3;
MAX = 4;
Low = 1;
Medium = 2;
High = 3;
Max = 4;
}

// Represents all the available set integral time value presets, which can be used with settings bus.
enum SetIntegralTimeSettingType {
SetIntegralTimeSettingNone = 0; // Stub enum to handle serialization.
100MS = 1;
200MS = 2;
300MS = 3;
400MS = 4;
500MS = 5;
600MS = 6;
First = 1;
Second = 2;
Third = 3;
Forth = 4;
Fifth = 5;
Sixth = 6;
}

// Represents settings bus request content send from the client to the board.
Expand Down
18 changes: 11 additions & 7 deletions Scripts/cli/src/proto/Content/settings_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bad3a4e

Please sign in to comment.