Skip to content

Commit

Permalink
lights loop with patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
tiandahuang committed Apr 29, 2023
1 parent 6c0c209 commit 9524f3e
Showing 1 changed file with 25 additions and 33 deletions.
58 changes: 25 additions & 33 deletions Tests/Test_BSP_Lights.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,36 @@

void delay(void) {
// Random delay loop
for(volatile int i = 0; i < 50000; i++);
for (volatile int i = 0; i < 100000; i++);
}

int pattern1[10 * 2] = {1, 1, 1, 1, 1, 0, 0, 0, 0, 0};
int pattern2[10 * 2] = {1, 0, 0, 1, 0, 0, 1, 0, 0, 0};
int *patterns[] = {pattern1, pattern2};

int lights_lut[10] = {FAULT, RUN, UVOLT, OVOLT, OTEMP, OCURR, WIRE, WDOG, CAN, EXTRA};

void light_map(int *ptr) {
for (int i = 0; i < 10; i++) {
ptr[i] ? BSP_Light_On(lights_lut[i]) : BSP_Light_Off(lights_lut[i]);
}
}

int main() {

BSP_Lights_Init();
for (int i = 0; i < (sizeof(patterns) / sizeof(*patterns)); i++) {
memcpy(patterns[i] + 10, patterns[i], 10 * sizeof(int));
}

int off[10] = {0};
light_map(off);

BSP_Light_Off(RUN);
BSP_Light_Off(UVOLT);
BSP_Light_Off(OVOLT);
BSP_Light_Off(OTEMP);
BSP_Light_Off(OCURR);
BSP_Light_Off(WDOG);
BSP_Light_Off(CAN);
BSP_Light_Off(EXTRA);
BSP_Light_Off(WIRE);
BSP_Light_Off(FAULT);

while(1) {
BSP_Light_Toggle(FAULT);
delay();
BSP_Light_Toggle(RUN);
delay();
BSP_Light_Toggle(UVOLT);
delay();
BSP_Light_Toggle(OVOLT);
delay();
BSP_Light_Toggle(OTEMP);
delay();
BSP_Light_Toggle(OCURR);
delay();
BSP_Light_Toggle(WIRE);
delay();
BSP_Light_Toggle(WDOG);
delay();
BSP_Light_Toggle(CAN);
delay();
BSP_Light_Toggle(EXTRA);
delay();
for (int i = 0; ; i = (i + 1) % (sizeof(patterns) / sizeof(*patterns))) {
for (int j = 0; j < 100; j++) {
int light_idx = j % 10;
light_map(&patterns[i][light_idx]);
delay();
}
}
}

0 comments on commit 9524f3e

Please sign in to comment.