Skip to content

Commit

Permalink
Use stepping instead of branching using modulus
Browse files Browse the repository at this point in the history
Modulus operations are very costly and generally should be avoided.
They also take a few bytes.

This version is actually a quite faster.
  • Loading branch information
JuantAldea authored and egzumer committed Dec 9, 2023
1 parent cfc4763 commit 1203fdf
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions app/spectrum.c
Original file line number Diff line number Diff line change
Expand Up @@ -944,14 +944,14 @@ static void RenderStill() {

const uint8_t METER_PAD_LEFT = 3;

for (int i = 0; i < 121; i++) {
if (i % 10 == 0) {
gFrameBuffer[2][i + METER_PAD_LEFT] = 0b01110000;
} else if (i % 5 == 0) {
gFrameBuffer[2][i + METER_PAD_LEFT] = 0b00110000;
} else {
gFrameBuffer[2][i + METER_PAD_LEFT] = 0b00010000;
}
memset(&gFrameBuffer[2][METER_PAD_LEFT], 0b00010000, 121);

for (int i = 0; i < 121; i+=5) {
gFrameBuffer[2][i + METER_PAD_LEFT] = 0b00110000;
}

for (int i = 0; i < 121; i+=10) {
gFrameBuffer[2][i + METER_PAD_LEFT] = 0b01110000;
}

uint8_t x = Rssi2PX(scanInfo.rssi, 0, 121);
Expand Down

0 comments on commit 1203fdf

Please sign in to comment.