Skip to content

Commit

Permalink
FFB led indicates HID FFB state
Browse files Browse the repository at this point in the history
  • Loading branch information
Ultrawipf committed Jul 31, 2024
1 parent 6867c8a commit ca4b05a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
6 changes: 6 additions & 0 deletions Firmware/FFBoard/Inc/ledEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ typedef struct Ledstruct{
int32_t blinks;
GPIO_TypeDef* port;
uint16_t pin;
uint8_t state;
} Ledstruct_t;


Expand All @@ -29,5 +30,10 @@ void blinkClipLed(uint16_t period,uint16_t blinks);
void updateLed(Ledstruct_t* led);
void updateLeds();

void setLed(Ledstruct_t* led,uint8_t on);
void setClipLed(uint8_t on);
void setErrLed(uint8_t on);
void setSysLed(uint8_t on);


#endif /* LEDEFFECTS_H_ */
3 changes: 2 additions & 1 deletion Firmware/FFBoard/Src/EffectsCalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <math.h>
#include "EffectsCalculator.h"
#include "Axis.h"

#include "ledEffects.h"


#define EFFECT_STATE_INACTIVE 0
Expand Down Expand Up @@ -71,6 +71,7 @@ void EffectsCalculator::setActive(bool active)
effects_stats[i].current = {0}; // Reset active effect forces
effects_statslast[i].current = {0};
}
setClipLed(active);
}


Expand Down
29 changes: 23 additions & 6 deletions Firmware/FFBoard/Src/ledEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
#include "main.h"

Ledstruct_t sysled{
0,0,0,LED_SYS_GPIO_Port,LED_SYS_Pin
0,0,0,LED_SYS_GPIO_Port,LED_SYS_Pin,0
};
Ledstruct_t errled{
0,0,0,LED_ERR_GPIO_Port,LED_ERR_Pin
0,0,0,LED_ERR_GPIO_Port,LED_ERR_Pin,0
};
Ledstruct_t clipled{
0,0,0,LED_CLIP_GPIO_Port,LED_CLIP_Pin
0,0,0,LED_CLIP_GPIO_Port,LED_CLIP_Pin,0
};

/**
Expand All @@ -27,12 +27,12 @@ void blinkLed(Ledstruct* led,uint16_t period,uint16_t blinks){
if(period == 0 && blinks == 0){
led->blinks = 0;
led->period = 0;
HAL_GPIO_WritePin(led->port, led->pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(led->port, led->pin, led->state ? GPIO_PIN_SET : GPIO_PIN_RESET);
}else{
led->blinks = (blinks * 2) -1;
led->period = period;
led->tick = HAL_GetTick();
HAL_GPIO_WritePin(led->port, led->pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(led->port, led->pin, led->state ? GPIO_PIN_RESET : GPIO_PIN_SET);
}
}

Expand Down Expand Up @@ -62,12 +62,29 @@ void blinkClipLed(uint16_t period,uint16_t blinks){
blinkLed(&clipled, period, blinks);
}

void setLed(Ledstruct_t* led,uint8_t on){
led->state = on;
HAL_GPIO_WritePin(led->port, led->pin, led->state ? GPIO_PIN_SET : GPIO_PIN_RESET);
}

void setClipLed(uint8_t on){
setLed(&clipled,on);
}

void setErrLed(uint8_t on){
setLed(&errled,on);
}

void setSysLed(uint8_t on){
setLed(&sysled,on);
}


void updateLed(Ledstruct* led){
// If led has an effect (period != 0) and time is up do something
if(led->period != 0 && HAL_GetTick() > led->tick+led->period){
if(led->blinks == 0){ // No blinks left. turn off
HAL_GPIO_WritePin(led->port, led->pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(led->port, led->pin, led->state ? GPIO_PIN_SET : GPIO_PIN_RESET);
led->period = 0;
}else{
led->tick = HAL_GetTick();
Expand Down

0 comments on commit ca4b05a

Please sign in to comment.