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 4, 2024
1 parent 4500e8b commit 4796d26
Show file tree
Hide file tree
Showing 43 changed files with 341 additions and 217 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ Debug/

# Scripts

**/env/
**/env/
**/__pycache__/
78 changes: 65 additions & 13 deletions Core/External/Scheduler/Handler/scheduler_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ int SchedulerHandler::handle_response() {
auto request_container_sequence = State::get_request_container_sequence();

if (!request_container_sequence.is_empty()) {
return request_container_sequence.traverse_with_break([](const light_detector::RequestContainer &content) -> int {
return SchedulerHandler::try_process_response_container(content);
});
return request_container_sequence.traverse_with_break(
[](const light_detector::RequestContainer &content) -> int {
return SchedulerHandler::try_process_response_container(content);
});
}

return EXIT_SUCCESS;
Expand Down Expand Up @@ -233,23 +234,24 @@ int SchedulerHandler::process_settings_bus_request_content_response(
if (ProtoHelper::is_settings_bus_request_content_of_enable_settings_type(
settings_bus_request_content)) {


return SchedulerHandler::process_settings_bus_request_content_of_enable_settings_type_response(content);
} else if (ProtoHelper::is_settings_bus_request_content_of_disable_settings_type(
settings_bus_request_content)) {


return SchedulerHandler::process_settings_bus_request_content_of_disable_settings_type_response(content);
} else 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(content);
} 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);
} 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);
}

return EXIT_SUCCESS;
Expand All @@ -266,10 +268,16 @@ int SchedulerHandler::process_settings_bus_request_content_of_enable_settings_ty
settings_bus_response_content.set_deviceId(TSL2591X::get_device_id());
settings_bus_response_content.set_settingsType(light_detector::SettingsType::Enable);

TSL2591X::enable();
uint8_t value = TSL2591X::get_integral_time();
if (!State::is_device_enabled()) {
TSL2591X::enable();

State::set_device_enabled(true);

settings_bus_response_content.set_result(true);
} else {
settings_bus_response_content.set_result(false);
}

settings_bus_response_content.set_result(true);
settings_bus_response_content.set_nonce(State::allocate_response_nonce());

response_container.set_settingsBus(settings_bus_response_content);
Expand All @@ -279,12 +287,56 @@ int SchedulerHandler::process_settings_bus_request_content_of_enable_settings_ty

int SchedulerHandler::process_settings_bus_request_content_of_disable_settings_type_response(
const light_detector::RequestContainer &content) {
return 0;
light_detector::ResponseContainer response_container;

response_container.set_msgId(content.get_msgId());

light_detector::SettingsBusResponseContent settings_bus_response_content;

settings_bus_response_content.set_deviceId(TSL2591X::get_device_id());
settings_bus_response_content.set_settingsType(light_detector::SettingsType::Disable);

if (State::is_device_enabled()) {
TSL2591X::disable();

State::set_device_enabled(false);

settings_bus_response_content.set_result(true);
} else {
settings_bus_response_content.set_result(false);
}

settings_bus_response_content.set_nonce(State::allocate_response_nonce());

response_container.set_settingsBus(settings_bus_response_content);

return ProtoCodec::encode_response_container(response_container);
}

int SchedulerHandler::process_settings_bus_request_content_of_reset_settings_type_response(
const light_detector::RequestContainer &content) {
return 0;
light_detector::ResponseContainer response_container;

response_container.set_msgId(content.get_msgId());

light_detector::SettingsBusResponseContent settings_bus_response_content;

settings_bus_response_content.set_deviceId(TSL2591X::get_device_id());
settings_bus_response_content.set_settingsType(light_detector::SettingsType::Reset);

if (State::is_device_enabled()) {
TSL2591X::reset();

settings_bus_response_content.set_result(true);
} else {
settings_bus_response_content.set_result(false);
}

settings_bus_response_content.set_nonce(State::allocate_response_nonce());

response_container.set_settingsBus(settings_bus_response_content);

return ProtoCodec::encode_response_container(response_container);
}

int SchedulerHandler::process_settings_bus_request_content_of_set_gain_settings_type_response(
Expand Down
8 changes: 0 additions & 8 deletions Core/External/Sensor/tsl2591x.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "tsl2591x.h"

bool TSL2591X::initialized = false;

void TSL2591X::init() {
enable();

Expand All @@ -10,18 +8,12 @@ void TSL2591X::init() {
write_byte(PERSIST_REGISTER, 0x01);

disable();

initialized = true;
}

bool TSL2591X::is_available() {
return HAL_I2C_IsDeviceReady(&hi2c1, TSL2591X_ADDRESS, 1u, 10u) == HAL_OK;
}

bool TSL2591X::is_configured() {
return initialized;
}

bool TSL2591X::get_device_id() {
return read_byte(WHO_AM_I);
};
Expand Down
12 changes: 0 additions & 12 deletions Core/External/Sensor/tsl2591x.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,6 @@ class TSL2591X {
*/
static bool is_available();

/**
* Checks if the device has already been configured.
*
* @return result of the check.
*/
static bool is_configured();

/**
* Retrieves device id of the sensor.
*
Expand Down Expand Up @@ -166,11 +159,6 @@ class TSL2591X {
static uint8_t get_gain();

private:
/**
* Indicated that the device has already been initialized.
*/
static bool initialized;

/**
* Reads value from the zero channel.
*
Expand Down
20 changes: 20 additions & 0 deletions Core/External/State/state.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "state.h"

bool State::device_configured = false;

bool State::device_enabled = false;

int State::amount_of_processed_requests = 0;

int State::current_response_nonce = 0;
Expand All @@ -12,6 +16,22 @@ Sequence<std::function<int()>> State::task_sequence =
Sequence<light_detector::RequestContainer> State::request_container_sequence =
Sequence<light_detector::RequestContainer>();

bool State::is_device_configured() {
return device_configured;
}

void State::set_device_configured(bool value) {
device_configured = true;
}

bool State::is_device_enabled() {
return device_enabled;
}

void State::set_device_enabled(bool value) {
device_enabled = true;
}

int State::get_amount_of_processed_requests() {
return amount_of_processed_requests;
};
Expand Down
38 changes: 38 additions & 0 deletions Core/External/State/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,34 @@
*/
class State {
public:
/**
* Checks if the device is configured.
*
* @return result of the check.
*/
static bool is_device_configured();

/**
* Sets device configured mode with the given value.
*
* @param value - value of the configure mode.
*/
static void set_device_configured(bool value);

/**
* Checks if the device is enabled.
*
* @return result of the check.
*/
static bool is_device_enabled();

/**
* Sets device enabled mode with the given value.
*
* @param value - value of the enabled mode.
*/
static void set_device_enabled(bool value);

/**
* Retrieves amount of processed events.
*
Expand Down Expand Up @@ -48,6 +76,16 @@ class State {
static Sequence<light_detector::RequestContainer>& get_request_container_sequence();

private:
/**
* Represents device configured mode.
*/
static bool device_configured;

/**
* Represents device enabled mode.
*/
static bool device_enabled;

/**
* Represents amount of processed incoming requests.
*/
Expand Down
13 changes: 9 additions & 4 deletions Core/Src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
*/
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
if (GPIO_Pin == GPIO_PIN_13) {
if (!State::get_button_mutex().is_locked()) {
State::get_button_mutex().lock();
if (State::is_device_configured()) {
if (!State::get_button_mutex().is_locked()) {
State::get_button_mutex().lock();

Scheduler::schedule_status_check();
Scheduler::schedule_status_check();
}
}
} else {
__NOP();
Expand Down Expand Up @@ -118,10 +120,13 @@ int main(void) {
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1) {
if (!TSL2591X::is_configured()) {
if (!State::is_device_configured()) {
if (TSL2591X::is_available()) {
TSL2591X::init();

State::set_device_configured(true);
State::set_device_enabled(true);

Indicator::toggle_initialization_success();

HAL_TIM_Base_Start_IT(&htim16);
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ endif

.PHONY: generate
generate: ## Generate ProtocolBuffers files(used mainly for development)
@protoc -I./Resources/Proto/Container --python_out=./Scripts/graph/proto Content/data.proto Content/info.proto Content/settings.proto request.proto response.proto
@protoc -I./Resources/Proto/Container --python_out=./Scripts/cli/src/proto Content/data.proto Content/info.proto Content/settings.proto request.proto response.proto
@protoc --plugin=/Volumes/Files/embedded/university/techno/project/deps/EmbeddedProto -I./Resources/Proto/Container --eams_out=./Core/External/Proto/Generated Content/data.proto Content/info.proto Content/settings.proto request.proto response.proto

.PHONY: build
Expand Down
8 changes: 1 addition & 7 deletions Scripts/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

## General Information

Allows to perform communication with serial connected devices.
Allows to perform operations with serial connected devices.

Includes following features:
* Retrieve latest sensor data(**raw**, **full**, **infrared**, **visible**)
Expand All @@ -30,10 +30,4 @@ If **ProtocolBuffers** files need to be regenerated it's required to execute the
make generate
```

## Scripts

### CLI

Detailed documentation can be found [here](./Scripts/cli/README.md)

# Use cases
30 changes: 0 additions & 30 deletions Scripts/cli/proto/data_pb2.py

This file was deleted.

30 changes: 0 additions & 30 deletions Scripts/cli/proto/info_pb2.py

This file was deleted.

Loading

0 comments on commit 4796d26

Please sign in to comment.