Skip to content

Commit

Permalink
Merge pull request #29 from Sylensky/feature/clang-formatting
Browse files Browse the repository at this point in the history
Feature/clang formatting
  • Loading branch information
Th0MmyS authored Jan 29, 2025
2 parents dd84fea + 083b682 commit 08b1d30
Show file tree
Hide file tree
Showing 23 changed files with 1,222 additions and 1,093 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/formatting-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: OGStarTracker CI
on: [push]
jobs:
formatting-check:
name: Formatting Check
runs-on: ubuntu-24.04
strategy:
matrix:
path:
- check: 'esp32_wireless_control/firmware'
exclude: '(shared)'
steps:
- uses: actions/checkout@v4
- name: Run clang-format style check for C/C++ programs.
uses: jidicula/[email protected]
with:
clang-format-version: '13'
check-path: ${{ matrix.path['check'] }}
exclude-regex: ${{ matrix.path['exclude'] }}
6 changes: 6 additions & 0 deletions esp32_wireless_control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ If you like this work, feel free to connect with me on [Github](https://github.c
## Table of Contents
- [PCB](pcb/README.md)
- [Compiling](docs/compiling.md)
- [Coding Style](docs/coding-style.md)


## Building guide
Expand All @@ -44,3 +45,8 @@ After connection was successful the tracker to actually control it access the **

If the webserver is not enough there is a app available to improve the accessibility even further.
Check out https://github.com/OndraGejdos/OG-star-tracker-App for more details.

## Contributing

When contributing to the project please make sure to follow the [coding style](docs/coding-style.md) prior creating a pull request.
With this we can make sure to keep a clean and tidy codespace.
22 changes: 22 additions & 0 deletions esp32_wireless_control/docs/coding-style.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## Coding style

To keep the source code clean and tidy we use `clangd` in combination with the `.clang-format` configuration file.

### Github Action Format Check

Additionally every push and pull request will trigger a `Github Action` to check the formatting on all the source code.
The output of the action should be `inspected` and the requested changes should be `applied` prior merging.

### Using clangd locally

1. To use `clangd` locally it is preferably installed via `Visual Studio Code Extensions`.
2. Install the extension from the `Extension Marketplace`.

![clangd Extension](img/vscode-clangd-extension.jpg)


3. Configure your IDE to use the clangd formatter properly.
![default formatter](img/vscode-default-formatter.jpg)
![formatting settings](img/vscode-format-settings.jpg)

4. Make your changes to the code and save the file to apply the formatting automatically.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions esp32_wireless_control/firmware/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
BasedOnStyle: LLVM
IndentWidth: 4
TabWidth: 4
UseTab: Never
BreakBeforeBraces: Allman
AllowShortFunctionsOnASingleLine: None
ColumnLimit: 100
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
IndentCaseLabels: true
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: true
SpaceBeforeParens: ControlStatements
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInParentheses: false
Standard: Cpp11
211 changes: 111 additions & 100 deletions esp32_wireless_control/firmware/axis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,130 +6,141 @@ Axis dec_axis(2, AXIS2_DIR, DEC_INVERT_DIR_PIN);
volatile bool ra_axis_step_phase = 0;
volatile bool dec_axis_step_phase = 0;

void IRAM_ATTR stepTimerRA_ISR() {
//ra ISR
ra_axis_step_phase = !ra_axis_step_phase;
digitalWrite(AXIS1_STEP, ra_axis_step_phase); //toggle step pin at required frequency
if (ra_axis.counterActive && ra_axis_step_phase) { //if counter active
if (ra_axis.axisAbsoluteDirection) {
ra_axis.axisCountValue = ra_axis.axisCountValue + 1;
} else if (!ra_axis.axisAbsoluteDirection) {
ra_axis.axisCountValue = ra_axis.axisCountValue - 1;
void IRAM_ATTR stepTimerRA_ISR()
{
// ra ISR
ra_axis_step_phase = !ra_axis_step_phase;
digitalWrite(AXIS1_STEP, ra_axis_step_phase); // toggle step pin at required frequency
if (ra_axis.counterActive && ra_axis_step_phase)
{ // if counter active
int temp = ra_axis.axisCountValue;
ra_axis.axisAbsoluteDirection ? temp++ : temp--;
ra_axis.axisCountValue = temp;
if (ra_axis.goToTarget && ra_axis.axisCountValue == ra_axis.targetCount)
{
ra_axis.goToTarget = false;
ra_axis.stopSlew();
}
}
if (ra_axis.goToTarget && ra_axis.axisCountValue == ra_axis.targetCount) {
ra_axis.goToTarget = false;
ra_axis.stopSlew();
}
}
}

void IRAM_ATTR stepTimerDEC_ISR() {
//dec ISR
dec_axis_step_phase = !dec_axis_step_phase;
digitalWrite(AXIS2_STEP, dec_axis_step_phase); //toggle step pin at required frequency
if (dec_axis_step_phase && dec_axis.counterActive) {
if (dec_axis.axisAbsoluteDirection) {
dec_axis.axisCountValue = dec_axis.axisCountValue + 1;
} else if (!dec_axis.axisAbsoluteDirection) {
dec_axis.axisCountValue = dec_axis.axisCountValue - 1;
} //if counter active
}
void IRAM_ATTR stepTimerDEC_ISR()
{
// dec ISR
dec_axis_step_phase = !dec_axis_step_phase;
digitalWrite(AXIS2_STEP, dec_axis_step_phase); // toggle step pin at required frequency
if (dec_axis_step_phase && dec_axis.counterActive)
{ // if counter active
int temp = dec_axis.axisCountValue;
dec_axis.axisAbsoluteDirection ? temp++ : temp--;
dec_axis.axisCountValue = temp;
}
}

void IRAM_ATTR slewTimeOutTimer_ISR() {
ra_axis.stopSlew();
void IRAM_ATTR slewTimeOutTimer_ISR()
{
ra_axis.stopSlew();
}

HardwareTimer slewTimeOut(2000, &slewTimeOutTimer_ISR);

Axis::Axis(uint8_t axis, uint8_t dirPinforAxis, bool invertDirPin) : stepTimer(40000000)
{
axisNumber = axis;
trackingDirection = c_DIRECTION;
dirPin = dirPinforAxis;
invertDirectionPin = invertDirPin;
trackingRate = TRACKING_SIDEREAL;
switch (axisNumber)
{
case 1:
stepTimer.attachInterupt(&stepTimerRA_ISR);
break;
case 2:
stepTimer.attachInterupt(&stepTimerDEC_ISR);
break;
}

Axis::Axis(uint8_t axis, uint8_t dirPinforAxis, bool invertDirPin)
: stepTimer(40000000) {
axisNumber = axis;
trackingDirection = c_DIRECTION;
dirPin = dirPinforAxis;
invertDirectionPin = invertDirPin;
trackingRate = TRACKING_SIDEREAL;
switch (axisNumber) {
case 1:
stepTimer.attachInterupt(&stepTimerRA_ISR);
break;
case 2:
stepTimer.attachInterupt(&stepTimerDEC_ISR);
break;
}

if (DEFAULT_ENABLE_TRACKING == 1 && axisNumber == 1) {
startTracking(TRACKING_SIDEREAL, trackingDirection);
}
if (DEFAULT_ENABLE_TRACKING == 1 && axisNumber == 1)
{
startTracking(TRACKING_SIDEREAL, trackingDirection);
}
}


void Axis::startTracking(trackingRateS rate, bool directionArg) {
trackingRate = rate;
trackingDirection = directionArg;
axisAbsoluteDirection = directionArg;
setDirection(axisAbsoluteDirection);
trackingActive = true;
stepTimer.stop();
setMicrostep(16);
stepTimer.start(trackingRate, true);

void Axis::startTracking(trackingRateS rate, bool directionArg)
{
trackingRate = rate;
trackingDirection = directionArg;
axisAbsoluteDirection = directionArg;
setDirection(axisAbsoluteDirection);
trackingActive = true;
stepTimer.stop();
setMicrostep(16);
stepTimer.start(trackingRate, true);
}

void Axis::stopTracking() {
trackingActive = false;
stepTimer.stop();
void Axis::stopTracking()
{
trackingActive = false;
stepTimer.stop();
}

void Axis::startSlew(uint64_t rate, bool directionArg) {
stepTimer.stop();
axisAbsoluteDirection = directionArg;
setDirection(axisAbsoluteDirection);
slewActive = true;
setMicrostep(8);
slewTimeOut.start(12000, true);
stepTimer.start(rate, true);
void Axis::startSlew(uint64_t rate, bool directionArg)
{
stepTimer.stop();
axisAbsoluteDirection = directionArg;
setDirection(axisAbsoluteDirection);
slewActive = true;
setMicrostep(8);
slewTimeOut.start(12000, true);
stepTimer.start(rate, true);
}

void Axis::stopSlew() {
slewActive = false;
stepTimer.stop();
slewTimeOut.stop();
if (trackingActive) {
startTracking(trackingRate, trackingDirection);
}
void Axis::stopSlew()
{
slewActive = false;
stepTimer.stop();
slewTimeOut.stop();
if (trackingActive)
{
startTracking(trackingRate, trackingDirection);
}
}

void Axis::setAxisTargetCount(int64_t count) {
targetCount = count;
void Axis::setAxisTargetCount(int64_t count)
{
targetCount = count;
}

void Axis::resetAxisCount() {
axisCountValue = 0;
void Axis::resetAxisCount()
{
axisCountValue = 0;
}

void Axis::setDirection(bool directionArg) {
digitalWrite(dirPin, directionArg ^ invertDirectionPin);
void Axis::setDirection(bool directionArg)
{
digitalWrite(dirPin, directionArg ^ invertDirectionPin);
}

void Axis::setMicrostep(uint8_t microstep) {
switch (microstep) {
case 8:
digitalWrite(MS1, LOW);
digitalWrite(MS2, LOW);
break;
case 16:
digitalWrite(MS1, HIGH);
digitalWrite(MS2, HIGH);
break;
case 32:
digitalWrite(MS1, HIGH);
digitalWrite(MS2, LOW);
break;
case 64:
digitalWrite(MS1, LOW);
digitalWrite(MS2, HIGH);
break;
}
void Axis::setMicrostep(uint8_t microstep)
{
switch (microstep)
{
case 8:
digitalWrite(MS1, LOW);
digitalWrite(MS2, LOW);
break;
case 16:
digitalWrite(MS1, HIGH);
digitalWrite(MS2, HIGH);
break;
case 32:
digitalWrite(MS1, HIGH);
digitalWrite(MS2, LOW);
break;
case 64:
digitalWrite(MS1, LOW);
digitalWrite(MS2, HIGH);
break;
}
}
Loading

0 comments on commit 08b1d30

Please sign in to comment.