summaryrefslogtreecommitdiff
path: root/project/Core/Src/Project/project.c
blob: 77e1e1c366e93a40110b3752fd8e05bd2ff3aa1a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * project.c
 *
 *  Created on: Jan 8, 2023
 *      Author: bruce
 */

#include <player.h>
#include <string.h>
#include <stdint.h>
#include <stdio.h>
#include <stm32l4xx.h>
#include "project.h"
#include "hw4.h"
#include "local_control.h"
#include "remote_control.h"
#include "GPIO.h"
#include "project.h"
#include "systick.h"

static uint8_t mode = REMOTE_MODE;

/**
 * Returns the mode to other files
 */
uint8_t project_get_mode() {
	return mode;
}

/**
 * Runs the project
 */
void project_run() {
	init_systick();
	local_control_init();
	remote_control_init();

	GPIO_Init();
	NVIC_EnableIRQ(EXTI15_10_IRQn);

	for (;;) {
		switch (mode) {
		case REMOTE_MODE:
			remote_control_loop(); break;
		case LOCAL_MODE:
			local_control_loop(); break;
		}
		player_loop();
	}
}

/**
 * Listen for blue button presses
 */
void EXTI15_10_IRQHandler() {
    if (~EXTI->PR1 & EXTI_PR1_PIF13)
    	return;

    EXTI->PR1 |= EXTI_PR1_PIF13;

	mode = !mode;
	switch (mode) {
	case REMOTE_MODE:
		puts("\r\n***REMOTE MODE ACTIVE***\r"); break;
	case LOCAL_MODE:
		puts("\r\n***MANUAL OVERRIDE MODE ACTIVE***\r"); break;
	}
}