Skip to content

Bootcamp: Daniel Kolev#308

Open
dkolev654 wants to merge 4 commits into
UWARG:masterfrom
dkolev654:master
Open

Bootcamp: Daniel Kolev#308
dkolev654 wants to merge 4 commits into
UWARG:masterfrom
dkolev654:master

Conversation

@dkolev654

Copy link
Copy Markdown

Bootcamp Pull Request for EFS: Daniel Kolev

@EemanAleem EemanAleem left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heyu! Did great on your bootcamp, with only very minor nits to tweak a little and then you're good to go!

{

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_RESET); //Set low
uint8_t tx_data[3] = {0x01, (0x80 | (ADC_CHANNEL << 4)), 0x00};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No magic numbers, such as for 0x01 and 0x08! For code to be understandable as developers iterate upon it in the future, you need to ensure values like this that seem obvious now, but not-so-obvious in a few months or even years should be prescribed a variable first! Otherwise correct values :)


HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_RESET); //Set low
uint8_t tx_data[3] = {0x01, (0x80 | (ADC_CHANNEL << 4)), 0x00};
uint8_t rx_data[3] = {0, 0, 0}; // buffer

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, since tx_data and rx_data do not change in the duration of the while loop, they should be initialized outside of the while loop to prevent constant reinitialization every time the while loop runs.

HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_RESET); //Set low
uint8_t tx_data[3] = {0x01, (0x80 | (ADC_CHANNEL << 4)), 0x00};
uint8_t rx_data[3] = {0, 0, 0}; // buffer
HAL_SPI_TransmitReceive(&hspi1, tx_data, rx_data, 3, HAL_MAX_DELAY);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See first comment about magic numbers for 3.


uint16_t adc_value = ((rx_data[1] & 0x03) << 8) | rx_data[2]; //parse 10-bit

uint32_t pulse = ON_TIME_MIN + (adc_value * (ON_TIME_MAX - ON_TIME_MIN)) / 1023; //map to 50-100 counts = 1-2ms

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This calculation is correct! One minor nit is to make sure that even though most compilers follow BIDMAS (or the equivalent acronym for determing the order of operations for mathematical calculations), make sure your brackets make it unquestionable so it prevents errors as you write the code yourself.

@EemanAleem EemanAleem left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome to WARG!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants