Skip to content

Commit

Permalink
Fixed pulse width bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
Onwrikbaar committed Dec 7, 2024
1 parent 4ea2737 commit a32ff35
Show file tree
Hide file tree
Showing 7 changed files with 1,463 additions and 1,472 deletions.
2,915 changes: 1,454 additions & 1,461 deletions firmware/build/neodk_g071.hex

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion firmware/inc/pattern_iter.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ typedef struct {
bool PatternIterator_checkPattern(uint8_t const pattern[][2], uint16_t nr_of_elcons);

// Instance methods.
void PatternIterator_init(PatternIterator *, PatternDescr const *, uint8_t pulse_width);
void PatternIterator_init(PatternIterator *, PatternDescr const *);
bool PatternIterator_done(PatternIterator *);
bool PatternIterator_getNextPulseTrain(PatternIterator *, PulseTrain *);

Expand Down
1 change: 1 addition & 0 deletions firmware/maolib/inc/matter.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ extern "C" {
#endif

uint16_t Matter_encodeUnsignedInteger(uint8_t dst[], uint8_t const *src, uint8_t nr_of_octets);
uint16_t Matter_encodedStringLength(char const *str);
uint16_t Matter_encodeString(uint8_t dst[], char const *str);
uint16_t Matter_encodedStringArrayLength(char const *strings[], uint8_t nr_of_strings);
uint16_t Matter_encodeStringArray(uint8_t dst[], char const *strings[], uint8_t nr_of_strings);
Expand Down
Binary file modified firmware/maolib/libmao.a
Binary file not shown.
2 changes: 1 addition & 1 deletion firmware/src/bsp_stm32g071.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ void BSP_init()

char const *BSP_firmwareVersion()
{
return "v0.40-beta";
return "v0.41-beta";
}


Expand Down
3 changes: 1 addition & 2 deletions firmware/src/pattern_iter.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,10 @@ bool PatternIterator_checkPattern(uint8_t const pattern[][2], uint16_t nr_of_elc
}


void PatternIterator_init(PatternIterator *me, PatternDescr const *pd, uint8_t pulse_width)
void PatternIterator_init(PatternIterator *me, PatternDescr const *pd)
{
me->pattern_descr = pd;
me->nr_of_reps = pd->nr_of_reps;
me->pulse_width_micros = pulse_width;
me->elcon_nr = 0;
M_ASSERT(pd->nr_of_steps != 0);
me->step_nr = 0;
Expand Down
12 changes: 5 additions & 7 deletions firmware/src/sequencer.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ struct _Sequencer {
uint8_t nr_of_patterns;
uint8_t pattern_index;
uint8_t intensity_percent;
uint8_t pulse_width;
uint8_t play_state;
};

Expand Down Expand Up @@ -187,7 +186,7 @@ static void selectPatternByName(Sequencer *me, char const *name, EventSize len)
static void setPulseWidth(Sequencer *me, uint8_t width_µs)
{
BSP_logf("Setting pulse width to %hhu µs\n", width_µs);
me->pulse_width = width_µs;
me->pi.pulse_width_micros = width_µs;
}


Expand All @@ -197,18 +196,18 @@ static void setIntensityPercentage(Sequencer *me, uint8_t perc)
me->intensity_percent = perc;
// TODO Ramp up to the previous intensity?
Sequencer_notifyIntensity(me);
BSP_setPrimaryVoltage_mV(perc * 100);
setPulseWidth(me, 40 + perc);
BSP_setPrimaryVoltage_mV(perc * 80);
setPulseWidth(me, 50 + perc + perc / 2);
}


static void switchPattern(Sequencer *me)
{
PatternDescr const *pd = &me->pattern_descr[me->pattern_index];
CLI_logf("Switching to '%s'\n", pd->name);
PatternIterator_init(&me->pi, pd);
setIntensityPercentage(me, DEFAULT_INTENSITY_PERCENT);
Sequencer_notifyPattern(me);
PatternIterator_init(&me->pi, pd, me->pulse_width);
}


Expand Down Expand Up @@ -284,7 +283,7 @@ static void *stateIdle(Sequencer *me, AOEvent const *evt)
break;
case ET_TOGGLE_PLAY_PAUSE:
case ET_PLAY:
PatternIterator_init(&me->pi, &me->pattern_descr[me->pattern_index], me->pulse_width);
PatternIterator_init(&me->pi, &me->pattern_descr[me->pattern_index]);
CLI_logf("Starting '%s'\n", me->pi.pattern_descr->name);
return &statePulsing; // Transition.
case ET_BURST_EXPIRED:
Expand Down Expand Up @@ -427,7 +426,6 @@ Sequencer *Sequencer_init(Sequencer *me)
void Sequencer_start(Sequencer *me)
{
checkAllPatterns(me);
PatternIterator_init(&me->pi, &me->pattern_descr[me->pattern_index], me->pulse_width);
me->state = stateIdle;
me->state(me, AOEvent_newEntryEvent());
setIntensityPercentage(me, DEFAULT_INTENSITY_PERCENT);
Expand Down

0 comments on commit a32ff35

Please sign in to comment.