static void dio_input( void )
{
    uint8_t di0 = DI_PIN & _BV(DI_1_BIT);
    uint8_t di1 = DI_PIN & _BV(DI_2_BIT);

    dio_in_channel( ee_cfg.di_channel[0], &di0_prev, di0, ee_cfg.di_mode[0] & DI_IS_BUTTON );
    dio_in_channel( ee_cfg.di_channel[1], &di1_prev, di1, ee_cfg.di_mode[1] & DI_IS_BUTTON );


    /*
    uint8_t btn0 = DI_PIN & _BV(0);
    uint8_t btn1 = DI_PIN & _BV(1);
    uint8_t btn2 = DI_PIN & _BV(2);
    uint8_t btn3 = DI_PIN & _BV(3);

    //dio_in_channel( 0, &btn0_prev, btn0, DI_IS_BUTTON );
    //dio_in_channel( 1, &btn1_prev, btn1, DI_IS_BUTTON );
    //dio_in_channel( 2, &btn2_prev, btn2, DI_IS_BUTTON );

    dio_in_channel( 0, &(buttons[0].prev), debounce_button( buttons+0, btn0) , DI_IS_BUTTON );
    dio_in_channel( 1, &(buttons[1].prev), debounce_button( buttons+1, btn1) , DI_IS_BUTTON );
    dio_in_channel( 2, &(buttons[2].prev), debounce_button( buttons+2, btn2) , DI_IS_BUTTON );

    //dio_in_channel( 3, &btn3_prev, btn3, DI_IS_BUTTON );
    dio_in_channel( 3, &(buttons[3].prev), debounce_button( buttons+3, btn3) , DI_IS_BUTTON );
    */

    int i;
    for( i = 0; i < 4; i++ )
    {
        dio_in_channel( i, &(buttons[i].prev), debounce_button( buttons+i, DI_PIN & _BV(i) ) , DI_IS_BUTTON );
    }

}
Beispiel #2
0
// Main function
void main(void) {
	reset_peripheral(); initClock(); initTimer(); initDisplay(); initPin();
	initGPIO(); initADC(); initConsole(); int i = 0;
	//init_password();
	send_data();

	initCircBuf (&speed_buffer, BUF_SIZE); init_set_speed_data(&speed_set_data);

	int screen = 0; int screen_prev = 0; float speed = 0; float buffed_speed = 0;
	int fake_speed = 0; float acc = 0; float max_acc = 0; //float fuel_eco = 0;
	float distance = 0;

	bool fix = 0; uint8_t satillite = 0; float quality = 0; clock time;
	int aim_pos = 0; unsigned long adc = 0; //int error_stepper = 0;

	IntMasterEnable();

	while(1){
		//reading data
		read_data = split_data(UART_char_data_old, read_data); 	// decode data
		speed = read_speed();									//read data into variables
		adc = run_adc()/7;

		//calculations
		aim_pos = speed_feedback(buffed_speed, encoder_1/40, speed_set_data.speed);
		if (speed_set_data.enable == 1){
			step_motor_control(encoder_1/40, aim_pos);
		}

		//sending fake data
		fake_speed = (int)adc;//= random_at_most(100/1.852);
		send_info(fake_speed);//knots

		//storing data
		store_speed(speed);
		buffed_speed = analysis_speed();
		acc = read_acceleration(buffed_speed);
		max_acc = max_acc_func(acc, max_acc);
		time = read_time();
		satillite = read_satillite();
		fix = read_fix();
		quality = read_quality();
		debounce_button();										// debounce buttons
		screen = read_button_screen(screen, fix);
		distance = read_distance();
		select_read();											//need a mosfet for turning power off
																// select adds a an on and off switch yo

		if (screen == 1){
			if(screen_prev != 1 && screen == 1){
				speed_set_data.speed = buffed_speed;
			}
			speed_set_data.speed = set_speed(speed_set_data.speed);					// set the speed to cruise at
		}
		if (screen == 2){ //0 to 100
			acceleration_test(speed);
		}
		// refresh chainging
		if (fix == 1 && speed_set_data.old == speed_set_data.speed && refresh_rate < 4){
			UARTSend((unsigned char *)PMTK_SET_NMEA_UPDATE_5HZ, 18, 0);
			refresh_rate += 1;
		}
		if (i >= 50){
			display(screen, buffed_speed, acc, max_acc, speed_set_data.speed, satillite,
					encoder_1/40, time, distance, quality, UART_char_data_old, aim_pos, adc, acc_times);
			i = 0;
		}
		screen_prev = screen;
		i++;
	}
}