Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * mn.c
- *
- * Created on: 2017 Sep 05 16:55:50
- * Author: Tobias Gent
- */
- #include "APDS_9660.h"
- #include "Shift.h"
- #include "BCD.h"
- #include <Dave.h>
- volatile int isr_flag = 0;
- uint32_t TimerId,status2;
- int main(void) {
- int input;
- uint8_t data[1];
- uint8_t data2[1];
- uint8_t data3[] = {0xff};
- uint32_t pin_status;
- DAVE_STATUS_t status;
- status = DAVE_Init(); /* Initialization of DAVE APPs */
- if (status != DAVE_STATUS_SUCCESS) {
- /* Placeholder for error handler code. The while loop below can be replaced with an user error handler. */
- XMC_DEBUG("DAVE APPs initialization failed\n");
- while (1U) {
- }
- }
- setupAll();
- while (1U) {
- fsm();
- if(manuell == true){
- manuell();
- APDS_EnableGestureSensor(false);
- }
- if(gesture == true){
- gesture();
- APDS_EnableGestureSensor(true);
- }
- if(voice == true){
- voice();
- APDS_EnableGestureSensor(false);
- }
- }
- }
- void manuell(){
- if(DIGITAL_IO_GetInput(&UP)){
- UART_Transmit(&UART_0, UP, sizeof(UP));
- }
- if(DIGITAL_IO_GetInput(&DOWN)){
- UART_Transmit(&UART_0, DOWN, sizeof(DOWN));
- }
- if(DIGITAL_IO_GetInput(&LEFT)){
- UART_Transmit(&UART_0, LEFT, sizeof(LEFT));
- }
- if(DIGITAL_IO_GetInput(&RIGHT)){
- UART_Transmit(&UART_0, RIGHT, sizeof(RIGHT));
- }
- if(input == LED_WHITE){
- DIGITAL_IO_ToggleOutput(&LED_WHITE);
- UART_Transmit(&UART_0, LED_WHITE_VALUE, sizeof(LED_WHITE_VALUE));
- }
- if(input == LED_RED){
- DIGITAL_IO_ToggleOutput(&LED_RED);
- UART_Transmit(&UART_0, LED_WHITE_VALUE, sizeof(LED_RED_VALUE));
- }
- if(input == LED_GREEN){
- DIGITAL_IO_ToggleOutput(&LED_GREEN);
- UART_Transmit(&UART_0, LED_WHITE_VALUE, sizeof(LED_GREEN_VALUE));
- }
- if(input == LED_BLUE){
- DIGITAL_IO_ToggleOutput(&LED_BLUE);
- UART_Transmit(&UART_0, LED_WHITE_VALUE, sizeof(LED_BLUE_VALUE));
- }
- }
- void setupAll(){
- PIN_INTERRUPT_Enable(&PIN_INTERRUPT_0);
- APDS_Init();
- setupBCD();
- setupShift();
- }
- void gesture(){
- if (isr_flag == 1) {
- PIN_INTERRUPT_Disable(&PIN_INTERRUPT_0);
- handleGesture();
- isr_flag = 0;
- PIN_INTERRUPT_Enable(&PIN_INTERRUPT_0);
- }
- }
- void voice(){
- }
- void fsm(){
- uint8_t* data;
- DIGITAL_IO_SetOutputHigh(&CE);
- DIGITAL_IO_SetOutputHigh(&CP);
- delay(250);
- DIGITAL_IO_SetOutputHigh(&PL);
- DIGITAL_IO_SetOutputLow(&CE);
- input = read(data);
- DIGITAL_IO_SetOutputLow(&PL);
- switch(input){
- case MODE_1:
- manuell = true;
- gesture = false;
- voice = false;
- break;
- case MODE_2:
- gesture = true;
- manuell = false;
- voice = false;
- break;
- case MODE_3:
- gesture = false;
- manuell = false;
- voice = false;
- break;
- }
- }
- void handleGesture() {
- if (APDS_IsGestureAvailable()) {
- switch (APDS9960_ReadGesture()) {
- case DIR_DOWN:
- UART_Transmit(&UART_0, DOWN, sizeof(DOWN));
- break;
- case DIR_LEFT:
- UART_Transmit(&UART_0, LEFT, sizeof(LEFT));
- break;
- case DIR_RIGHT:
- UART_Transmit(&UART_0, RIGHT, sizeof(RIGHT));
- break;
- case DIR_UP:
- UART_Transmit(&UART_0, UP, sizeof(UP));
- break;
- }
- }
- }
- void attachInterrupt(void)
- {
- isr_flag = 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement