/*
 * project.c
 *
 *  Created on: Jan 8, 2023
 *      Author: bruce
 */

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

#define LOCAL_MODE (1)
#define REMOTE_MODE (2)

static uint8_t state = STOPPED_STATE;

uint8_t *project_get_state() {
	return &state;
}

void project_run() {
	int mode = LOCAL_MODE;
	local_control_start();
//	remote_control_start();

	GPIO_Init();
	NVIC_EnableIRQ(EXTI15_10_IRQn);

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

		if (state == PAUSED_STATE)
			pause_loop();
	}
}

void EXTI15_10_IRQHandler() {
    if (~EXTI->PR1 & EXTI_PR1_PIF13)
    	return;

    EXTI->PR1 |= EXTI_PR1_PIF13;

	int status = !(GPIOC->IDR & GPIO_PIN_13);
	printf("%i\r\n", status);
}



