Пример #1
0
int16_t main(void) {
    int led2_on;
    int led3_on;

    led2_on = 0;
    led3_on = 1;
    init_clock();
    init_ui();
    init_timer();

    led_on(&led1);
    timer_setPeriod(&timer2, 0.1);
    timer_start(&timer2);

    while (1) {
        if (timer_flag(&timer2)) {
            timer_lower(&timer2);
            led_toggle(&led1);
        }

        if(!sw_read(&sw2)){
            timer_setPeriod(&timer2, 0.5);
            timer_start(&timer2);
            led2_on = 1;
            led3_on = 0;
        } else if(!sw_read(&sw3)){
            timer_setPeriod(&timer2, 0.1);
            timer_start(&timer2);
            led2_on = 0;
            led3_on = 1;
        }
        led_write(&led2, led2_on);
        led_write(&led3, led3_on);
    }
}
Пример #2
0
int main() {
    led_init();
    while (1) {
        int i;
        led_write(0);
        for (i = 0; i < 10000; ++i);
        led_write(1);
        for (i = 0; i < 10000; ++i);
    }
}
Пример #3
0
void led_init(void) {
	palSetPadMode(GPIOE, 0,
			PAL_MODE_OUTPUT_PUSHPULL |
			PAL_STM32_OSPEED_HIGHEST);
	palSetPadMode(GPIOE, 1,
			PAL_MODE_OUTPUT_PUSHPULL |
			PAL_STM32_OSPEED_HIGHEST);

	led_write(LED_RED, 0);
	led_write(LED_GREEN, 0);
}
Пример #4
0
/* スレッドからの要求を処理する */
static int display_cmdproc(char *p)
{
  int cmd = p[0];
  switch (cmd) {
  case DISPLAY_CMD_LCD_CLEAR:
    NTLEVT_START(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_CLEAR);
    sg12232c_clear();
    NTLEVT_END(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_CLEAR);
    break;
  case DISPLAY_CMD_LCD_DRAW_BOX:
    NTLEVT_START(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_DRAWBOX);
    sg12232c_draw_box(p[1], p[2], p[3], p[4], p[5]);
    NTLEVT_END(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_DRAWBOX);
    break;
  case DISPLAY_CMD_LCD_DRAW_LOGO:
    NTLEVT_START(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_DRAWLOGO);
    draw_logo(p[1], p[2], p[3]);
    NTLEVT_END(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_DRAWLOGO);
    break;
  case DISPLAY_CMD_LCD_DRAW_TEXT:
    NTLEVT_START(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_DRAWTEXT);
    sg12232c_draw_string(p[1], p[2], &p[3], 0);
    NTLEVT_END(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_DRAWTEXT);
    break;
  case DISPLAY_CMD_LCD_DRAW_PBAR:
    NTLEVT_START(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_DRAWPROG);
    sg12232c_draw_progressbar(
            p[1], p[2], p[3], p[4], p[5], p[6], p[7], 0);
    NTLEVT_END(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_DRAWPROG);
    break;
  case DISPLAY_CMD_LED_ON:
    NTLEVT_START(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_LEDON);
    led_write(p[1] - '0', LedOn);
    NTLEVT_END(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_LEDON);
    break;
  case DISPLAY_CMD_LED_OFF:
    NTLEVT_START(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_LEDOFF);
    led_write(p[1] - '0', LedOff);
    NTLEVT_END(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_LEDOFF);
    break;
  case DISPLAY_CMD_LED_TOGGLE:
    NTLEVT_START(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_LEDTOGGLE);
    led_toggle(p[1] - '0');
    NTLEVT_END(NTLUSR_TRACK_DISPLAY, NTLUSR_EVENT_DISPLAY_LEDTOGGLE);
    break;
  default:
    break;
  }
  kz_kmfree(p);

  return 0;
}
Пример #5
0
// Display a blank output on the LED (useful for modes outside of the game mode)
void led_display_blank() {
	for(int y = 0; y < 8; y++) {
		for(int x = 0; x < 8; x++) {
			led_current_pattern[y][x] = BLACK;
		}
	}
	
	led_write(&led_current_pattern);
}
Пример #6
0
// Copy the game's pattern to the LED pattern
void led_display_game() {
	// Copy pattern (from game.h) into led_current_pattern
	for(int x = 0; x < 8; x++) {
		for(int y = 0; y < 8; y++) {
			if(pattern[x][y] == 1)
				led_current_pattern[x][y] = ORANGE;
			else
				led_current_pattern[x][y] = BLACK;
		}
	}
	
	led_write(&led_current_pattern);
}
Пример #7
0
// Copy the game's map to the LED pattern
void led_display_game() {
	// Convert game_map tiles into appropriate colored tiles and set into led_current_pattern
	for(int y = 0; y < 8; y++) {
		for(int x = 0; x < 8; x++) {
			if(game_map[y][x] == MAP_WALL)
				led_current_pattern[y][x] = GREEN;
			else if(game_map[y][x] == MAP_PLAYER)
				led_current_pattern[y][x] = ORANGE;
			else if(game_map[y][x] == MAP_GHOST)
				led_current_pattern[y][x] = RED;
			else {
				led_current_pattern[y][x] = BLACK; // MAP_EMPTY
			}
		}
	}
	
	led_write(&led_current_pattern);
}
Пример #8
0
int16_t main(void) {
    init_clock();
    init_ui();
    init_timer();

    led_on(&led1);
    timer_setPeriod(&timer2, 1.0);
    timer_start(&timer2);

    while (1) {
        if (timer_flag(&timer2)) {
            timer_lower(&timer2);
            led_toggle(&led1);
            led_toggle(&led2);
        }
        led_write(&led3, !sw_read(&sw3));
    }
}
Пример #9
0
/*
 * Routine: board_init
 * Description: Early hardware init.
 */
int board_init(void)
{
	led_write(U, B, O, O);

	return 0;
}
Пример #10
0
void led_off(void) {
    led_state_ = 0;
    led_write(led_state_);
}
Пример #11
0
void led_on(void) {
    led_state_ = 1;
    led_write(led_state_);
}
Пример #12
0
void terminal_process_string(char *str) {
	enum { kMaxArgs = 64 };
	int argc = 0;
	char *argv[kMaxArgs];

#if MAIN_MODE == MAIN_MODE_CAR
	static char buffer[256];
#endif

	char *p2 = strtok(str, " ");
	while (p2 && argc < kMaxArgs) {
		argv[argc++] = p2;
		p2 = strtok(0, " ");
	}

	if (argc == 0) {
		commands_printf("No command received\n");
		return;
	}

	if (strcmp(argv[0], "ping") == 0) {
		commands_printf("pong\n");
	} else if (strcmp(argv[0], "mem") == 0) {
		size_t n, size;
		n = chHeapStatus(NULL, &size);
		commands_printf("core free memory : %u bytes", chCoreGetStatusX());
		commands_printf("heap fragments   : %u", n);
		commands_printf("heap free total  : %u bytes\n", size);
	} else if (strcmp(argv[0], "threads") == 0) {
		thread_t *tp;
		static const char *states[] = {CH_STATE_NAMES};
		commands_printf("    addr    stack prio refs     state           name time    ");
		commands_printf("-------------------------------------------------------------");
		tp = chRegFirstThread();
		do {
			commands_printf("%.8lx %.8lx %4lu %4lu %9s %14s %lu",
					(uint32_t)tp, (uint32_t)tp->p_ctx.r13,
					(uint32_t)tp->p_prio, (uint32_t)(tp->p_refs - 1),
					states[tp->p_state], tp->p_name, (uint32_t)tp->p_time);
			tp = chRegNextThread(tp);
		} while (tp != NULL);
		commands_printf(" ");
	}

#if MAIN_MODE == MAIN_MODE_CAR
	else if (strcmp(argv[0], "vesc") == 0) {
		buffer[0] = '\0';
		int ind = 0;
		for (int i = 1;i < argc;i++) {
			sprintf(buffer + ind, " %s", argv[i]);
			ind += strlen(argv[i]) + 1;
		}
		bldc_interface_terminal_cmd(buffer);
	}

#if RADAR_EN
	else if (strcmp(argv[0], "radar_sample") == 0) {
		commands_printf("Sampling radar...");
		radar_setup_measurement_default();
		radar_sample();
	} else if (strcmp(argv[0], "radar_cmd") == 0) {
		buffer[0] = '\0';
		int ind = 0;
		for (int i = 1;i < argc;i++) {
			if (i == 1) {
				sprintf(buffer + ind, "%s", argv[i]);
				ind += strlen(argv[i]);
			} else {
				sprintf(buffer + ind, " %s", argv[i]);
				ind += strlen(argv[i]) + 1;
			}
		}
		radar_cmd(buffer);
	} else if (strcmp(argv[0], "radar_reset") == 0) {
		commands_printf("Resetting radar...");
		radar_reset_setup();
	}
#endif
#endif

	else if (strcmp(argv[0], "reset_att") == 0) {
		pos_reset_attitude();
	} else if (strcmp(argv[0], "reset_enu") == 0) {
		pos_reset_enu_ref();
	} else if (strcmp(argv[0], "cc1120_state") == 0) {
		commands_printf("%s\n", cc1120_state_name());
	} else if (strcmp(argv[0], "cc1120_update_rf") == 0) {
		if (argc != 2) {
			commands_printf("Invalid number of arguments\n");
		} else {
			int set = -1;
			sscanf(argv[1], "%d", &set);

			if (set < 0) {
				commands_printf("Invalid argument\n");
			} else {
				cc1120_update_rf(set);
				commands_printf("Done\n");
			}
		}
	} else if (strcmp(argv[0], "dw_range") == 0) {
		if (argc != 2) {
			commands_printf("Invalid number of arguments\n");
		} else {
			int dest = -1;
			sscanf(argv[1], "%d", &dest);

			if (dest < 0 || dest > 254) {
				commands_printf("Invalid argument\n");
			} else {
				comm_can_set_range_func(range_callback);
				comm_can_dw_range(CAN_DW_ID_ANY, dest, 5);
			}
		}
	} else if (strcmp(argv[0], "zero_gyro") == 0) {
		led_write(LED_RED, 1);
		mpu9150_sample_gyro_offsets(100);
		led_write(LED_RED, 0);
	}

	// The help command
	else if (strcmp(argv[0], "help") == 0) {
		commands_printf("Valid commands are:");
		commands_printf("help");
		commands_printf("  Show this help");

		commands_printf("ping");
		commands_printf("  Print pong here to see if the reply works");

		commands_printf("mem");
		commands_printf("  Show memory usage");

		commands_printf("threads");
		commands_printf("  List all threads");

#if MAIN_MODE == MAIN_MODE_CAR
		commands_printf("vesc");
		commands_printf("  Forward command to VESC");

#if RADAR_EN
		commands_printf("radar_sample");
		commands_printf("  Start radar sampling");

		commands_printf("radar_cmd");
		commands_printf("  Forward command to radar");

		commands_printf("radar_reset");
		commands_printf("  Reset and setup the radar");
#endif
#endif

		commands_printf("reset_att");
		commands_printf("  Re-initialize the attitude estimation");

		commands_printf("reset_enu");
		commands_printf("  Re-initialize the ENU reference on the next GNSS sample");

		commands_printf("cc1120_state");
		commands_printf("  Print the state of the CC1120");

		commands_printf("cc1120_update_rf [rf_setting]");
		commands_printf("  Set one of the cc1120 RF settings");
		int ind = 0;
		commands_printf("  %d: %s", ind++, "CC1120_SET_434_0M_1_2K_2FSK_BW25K_4K");
		commands_printf("  %d: %s", ind++, "CC1120_SET_434_0M_1_2K_2FSK_BW50K_20K");
		commands_printf("  %d: %s", ind++, "CC1120_SET_434_0M_1_2K_2FSK_BW10K_4K");
		commands_printf("  %d: %s", ind++, "CC1120_SET_434_0M_50K_2GFSK_BW100K_25K");
		commands_printf("  %d: %s", ind++, "CC1120_SET_434_0M_100K_4FSK_BW100K_25K");
		commands_printf("  %d: %s", ind++, "CC1120_SET_434_0M_4_8K_2FSK_BW40K_9K");
		commands_printf("  %d: %s", ind++, "CC1120_SET_434_0M_4_8K_2FSK_BW50K_14K");
		commands_printf("  %d: %s", ind++, "CC1120_SET_434_0M_4_8K_2FSK_BW100K_39K");
		commands_printf("  %d: %s", ind++, "CC1120_SET_434_0M_9_6K_2FSK_BW50K_12K");
		commands_printf("  %d: %s", ind++, "CC1120_SET_452_0M_9_6K_2GFSK_BW33K_2_4K");
		commands_printf("  %d: %s", ind++, "CC1120_SET_452_0M_9_6K_2GFSK_BW50K_2_4K");

		commands_printf("dw_range [dest]");
		commands_printf("  Measure the distance to DW module [dest] with ultra wideband.");

		commands_printf("zero_gyro");
		commands_printf("  Zero the gyro bias. Note: The PCB must be completely still when running this command.");

		for (int i = 0;i < callback_write;i++) {
			if (callbacks[i].arg_names) {
				commands_printf("%s %s", callbacks[i].command, callbacks[i].arg_names);
			} else {
				commands_printf(callbacks[i].command);
			}

			if (callbacks[i].help) {
				commands_printf("  %s", callbacks[i].help);
			} else {
				commands_printf("  There is no help available for this command.");
			}
		}

		commands_printf(" ");
	} else {
		bool found = false;
		for (int i = 0;i < callback_write;i++) {
			if (strcmp(argv[0], callbacks[i].command) == 0) {
				callbacks[i].cbf(argc, (const char**)argv);
				found = true;
				break;
			}
		}

		if (!found) {
			commands_printf("Invalid command: %s\n"
					"type help to list all available commands\n", argv[0]);
		}
	}
}