Exemple #1
0
int main()                     // run over and over again
{
  while(1) 
  {
    // note that the following line could also be accomplished with:
    // int pot = analogRead(7);
    int pot = read_trimpot();  // determine the trimpot position
    
    // avoid clearing the LCD to reduce flicker
    lcd_goto_xy(0, 0);
    print("pot=");
    print_long(pot);               // print the trim pot position (0 - 1023)
    print("  ");              // overwrite any left over digits
    
    int motorSpeed = (512 - pot) / 2;
    lcd_goto_xy(0, 1);
    print("spd=");
    print_long(motorSpeed);        // print the resulting motor speed (-255 - 255)
    print("   ");
    set_motors(motorSpeed, motorSpeed);  // set speeds of motors 1 and 2

    // all LEDs off
    red_led(0);
    green_led(0);
    // turn green LED on when motors are spinning forward
    if (motorSpeed > 0)
      green_led(1);
    // turn red LED on when motors are spinning in reverse
    if (motorSpeed < 0)
      red_led(1);
    delay_ms(100);
  }
}
Exemple #2
0
int main()
{
  // Initialize the encoders and specify the four input pins.
  encoders_init(IO_C2, IO_C3, IO_C4, IO_C5);

  while(1)
  {
    // Read the counts for motor 1 and print to LCD.
    lcd_goto_xy(0,0);
    print_long(encoders_get_counts_m1());
    print(" ");

    // Read the counts for motor 2 and print to LCD.
    lcd_goto_xy(4,0);
    print_long(encoders_get_counts_m2());
    print(" ");

    // Print encoder errors, if there are any.
    if(encoders_check_error_m1())
    {
      lcd_goto_xy(0,1);
      print("Error 1");
    }
    if(encoders_check_error_m2())
    {
      lcd_goto_xy(0,1);
      print("Error 2");
    }

    delay_ms(50);
  }
}
Exemple #3
0
// Displays the temperature, in C or F.
void temp_test()
{
	static int display_c = 0; // 0 for F, 1 for C
	int temperature;

	if(display_c)
		temperature = read_temperature_c();
	else
		temperature = read_temperature_f();

	// display temperature; it is in tenths of a degree
	print_long(temperature/10);
	print(".");
	print_long(temperature%10);

	// character 0xDF is the degree symbol
	print_character('\xdf');

	if(display_c)
		print_character('C');
	else
		print_character('F');

	// allow the user to switch between modes
	if(button_is_pressed(BUTTON_A))
		display_c = 1;
	if(button_is_pressed(BUTTON_C))
		display_c = 0;

	delay_ms(100);
}
Exemple #4
0
void test()
{
	unsigned char button;

	clear();
	delay(200);
	print("Orangutn");	// print to the top line of the LCD
	delay_ms(400);		// delay 200 ms
	lcd_goto_xy(0, 1);	// go to the start of the second LCD line

#if defined __AVR_ATmega328P__
	print(" LV-328");	// print to the bottom line of the LCD
#elif defined __AVR_ATmega168__
	print(" LV-168");	// print to the bottom line of the LCD
#else
#error "Unrecognized device type"
#endif

	delay_ms(1000);		// delay 700 ms

	clear();			// clear the LCD, move cursor to start of top line

	print("  Temp.");

	do
	{
		// Perform 10-bit analog-to-digital conversions on ADC channel 6.
		// Average ten readings and return the result, which will be one
		// third of the battery voltage when the "ADC6 = VBAT/3" solder
		// bridge is in place on the bottom of the Orangutan PCB
		int Tf = read_temperature_f();	// read temp sensor on ADC6 in 0.1°F
		lcd_goto_xy(1, 1);	// second character of the second LCD line
		print_long(Tf/10);	// display temperature in °F
		print(".");			// print the decimal point
		print_long(Tf - 10*(Tf/10));	// display the tenths digit
		print_character(223);	// display the degree symbol character (°)
		print("F  ");		// display the units
		delay_ms(50);		// delay for 50 ms
		button = button_is_pressed(ALL_BUTTONS);	// check for button press
	}
	while (button == 0);	// loop if no buttons are being pressed


	// *** MAIN LOOP ***

	while (1)	// loop forever
	{
		if (button & TOP_BUTTON)			// if the top button is pressed
			button = melodyTest();	// this func. loops until next button press

		else if (button & MIDDLE_BUTTON)	// if the middle button is pressed
			button = IOTest();		// this func. loops until next button press

		else if (button & BOTTOM_BUTTON)	// if the bottom button is pressed
			button = motorTest();	// this func. loops until next button press
	}
}
Exemple #5
0
void seguir_linea_instante(int posicion_linea, int m_max, int m_moderada, int umbral_zona_moderada ){

	int medio = 2000;
	
	int posicion_linea_centrada = ((int)posicion_linea) - medio; // Si la linea esta en el centro el valor es 0, en los sensores extremos -2000 o 2000.
	
	float pendiente_zona_dastica = ((float)(m_max - m_moderada)/(medio - umbral_zona_moderada)); //
	int b = m_max - pendiente_zona_dastica*medio;
	
	int diferencia_motores = 0; // m1 - m2
	
	int m1 = 0;
	int m2 = 0;
	
	if (posicion_linea_centrada > umbral_zona_moderada)
	{
		diferencia_motores = pendiente_zona_dastica*posicion_linea_centrada + b;
	}
	else if (posicion_linea_centrada < -umbral_zona_moderada)
	{
		diferencia_motores = pendiente_zona_dastica*posicion_linea_centrada - b;
	} else {
		double x = ((double)posicion_linea_centrada)/(umbral_zona_moderada);
		diferencia_motores = m_moderada*x*x*x;
	}
	
	if(diferencia_motores > 0)
	{
		m1 = m_max;
		m2 = m_max - diferencia_motores;
	}
	else if (diferencia_motores < 0)
	{
		m2 = m_max;
		m1 = m_max + diferencia_motores;
	} else
	{
		m1 = m_max;
		m2 = m_max;
	}
	
	clear();
	print_long(m1);
	print("  ");
	print_long(m2);
	lcd_goto_xy(0,1);
	print_long(diferencia_motores);
	
	set_motors(m1,m2);
}
void print_count(float count)
{
  //Some ugly stuff to print out a floating point number.
  lcd_goto_xy(0,1);
  print("Revs: ");
  print_long(count);
  print_character('.');
  int decimal = (count - (int)count) * 100;
  
  if(decimal < 10)
    print_character('0');

  print_long(decimal);
}
int main()
{
	// set up the 3pi
	initialize();
	int last_proximity = 0;
	const int base_speed = 200;
	const int set_point = 100; // what is the set point for?
	// This is the "main loop" - it will run forever.
	while(1)
	{
		// In case it gets stuck: for 1 second every 15 seconds back up
		if (get_ms() % 15000 > 14000) {
			back_up();
			continue;
		}
		// If something is directly in front turn to the right in place
		int front_proximity = analog_read(5);
		if (front_proximity > 200) {
			turn_in_place();
			continue;
		}
		int proximity = analog_read(1); // 0 (far away) - 650 (close)
		int proportional = proximity - set_point;
		int derivative = proximity - last_proximity;
		// Proportional-Derivative Control Signal
		int pd = proportional / 3 + derivative * 20;
		int left_set = base_speed + pd;
		int right_set = base_speed - pd;
		set_motors(left_set, right_set);
		if (TIME_TO_DISPLAY) {
			clear();
			lcd_goto_xy(0,0);
			print_long(proximity);
			lcd_goto_xy(5,0);
			print_long(pd);
			lcd_goto_xy(0,1);
			print_long(left_set);
			lcd_goto_xy(4,1);
			print_long(right_set);
		}
		last_proximity = proximity; // remember last proximity for derivative
	}
	// This part of the code is never reached. 
	while(1)
	{
		set_motors(0,0)
	}
}
int main( void )
{
    /* perform battery check */
    bat_check();
    
    /* display welcome message and  */
    /* seed random number generator */
    clear();
    lcd_goto_xy(0,0);
    print("Welcome!");
    lcd_goto_xy(0,1);
    print("Press B");
    wait_for_button_press(BUTTON_B);   /* button down */
    long seed = 0;
    while(button_is_pressed(BUTTON_B)) /* while button not released */
        seed++;
    srandom(seed);
    
    while(1) 
    {
        clear();
        
        /* obtain random number between 0-9 */
        int val = random() % 10;
        
        /* display number */
        lcd_goto_xy(0,0);
        print_long(val);
        lcd_goto_xy(0,1);
        print("Press B");
        
        /* wait for user to press/release B */
        wait_for_button(BUTTON_B);
    }
}
Exemple #9
0
void pot_test()
{
    long start = get_ms();
    char elapsed_ms;
    int value;

    set_analog_mode(MODE_10_BIT);
    print_long(read_trimpot());
    print("   "); // to clear the display

    while((elapsed_ms = get_ms() - start) < 100)
    {
        value = read_trimpot();
        play_frequency(value, 200, 15);

        if(value < elapsed_ms*10)
        {
            red_led(0);
            green_led(1);
        }
        else
        {
            red_led(1);
            green_led(0);
        }
    }
}
Exemple #10
0
int lg2_status(git_repository *repo, int argc, char *argv[])
{
	git_status_list *status;
	struct opts o = { GIT_STATUS_OPTIONS_INIT, "." };

	o.statusopt.show  = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
	o.statusopt.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
		GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX |
		GIT_STATUS_OPT_SORT_CASE_SENSITIVELY;

	parse_opts(&o, argc, argv);

	if (git_repository_is_bare(repo))
		fatal("Cannot report status on bare repository",
			git_repository_path(repo));

show_status:
	if (o.repeat)
		printf("\033[H\033[2J");

	/**
	 * Run status on the repository
	 *
	 * We use `git_status_list_new()` to generate a list of status
	 * information which lets us iterate over it at our
	 * convenience and extract the data we want to show out of
	 * each entry.
	 *
	 * You can use `git_status_foreach()` or
	 * `git_status_foreach_ext()` if you'd prefer to execute a
	 * callback for each entry. The latter gives you more control
	 * about what results are presented.
	 */
	check_lg2(git_status_list_new(&status, repo, &o.statusopt),
		"Could not get status", NULL);

	if (o.showbranch)
		show_branch(repo, o.format);

	if (o.showsubmod) {
		int submod_count = 0;
		check_lg2(git_submodule_foreach(repo, print_submod, &submod_count),
			"Cannot iterate submodules", o.repodir);
	}

	if (o.format == FORMAT_LONG)
		print_long(status);
	else
		print_short(repo, status);

	git_status_list_free(status);

	if (o.repeat) {
		sleep(o.repeat);
		goto show_status;
	}

	return 0;
}
Exemple #11
0
/*
func: get a valid device
*/
unsigned short getOneValidDevice(void)
{
    unsigned long lbus;
    unsigned long lslot;
    unsigned long lfunc = 0;
    unsigned short device;
    unsigned short vendor;
    unsigned long address;
    unsigned short class_sub;
    unsigned short progif_rev;
    unsigned short pin_line;
    unsigned long base_address;
    unsigned short cmd;
    unsigned short status;

    print_string(" VENDOR  DEVICE  CMD     STATUS CLASS|SUB PROGIF|REV PIN|LINE BASE_ADDR");
    print_return();

    for (lbus =0; lbus < 256; lbus++) {
        for (lslot = 0; lslot < 32; lslot++) {
            for (lfunc = 0; lfunc < 8; lfunc++) {
                PCI_CONFIG_READ_WORD(lbus, lslot, lfunc, 0x00, address, vendor);    
                /*vendor = pciConfigReadWord(bus, slot, 0, 0);*/
                if(vendor != 0xFFFF) {
                    /* device = pciConfigReadWord(bus, slot, 0, 2); */
                    PCI_CONFIG_READ_WORD(lbus, lslot, lfunc, 0x02, address, device);    
                    /* Class code|subclass */
                    PCI_CONFIG_READ_WORD(lbus, lslot, lfunc, 0x0a, address, class_sub);    
                    /* Command */
                    PCI_CONFIG_READ_WORD(lbus, lslot, lfunc, 0x04, address, cmd);    
                    /* Status */
                    PCI_CONFIG_READ_WORD(lbus, lslot, lfunc, 0x06, address, status);    
                    /* Prog IF| Revision ID */
                    PCI_CONFIG_READ_WORD(lbus, lslot, lfunc, 0x08, address, progif_rev);    
                    /* Interrupt PIN | Interrupt Line */
                    PCI_CONFIG_READ_WORD(lbus, lslot, lfunc, 0x3c, address, pin_line);
                    /* base address #0 */
                    PCI_CONFIG_READ_DWORD(lbus, lslot, lfunc, 0x10, address, base_address);
    
                    // netcard: intel e1000
                    if ((vendor == 0x8086) && (device == 0x100F)) {
                        print_short(vendor);
                        print_short(device);
                        print_short(cmd);
                        print_short(status);
                        print_short(class_sub);
                        print_short(progif_rev);
                        print_short(pin_line);
                        print_long(base_address & 0xFFFFFFFC);
                        print_return();
                    }
                }
            }
        }
    }
        
    // print_string(" Today is 20130526, I'm coding for NetCard.");
    return 0;
}
Exemple #12
0
/*-----------------------------------------------------------------------------
 * Function name: bat_check
 * Description: This function checks the voltage on the batteries and
 *              displays a message on the LCD until the user presses B.
 *              The message on the first line cycles between the following:
 *              Bat Chk       [-> descriptive message]
 *              xxxxmV        [-> the battery voltage]
 *              Okay/Replace  [-> whether the batteries should be replaced]
 ----------------------------------------------------------------------------*/
void bat_check( void )
{
    int firstLineType = 0; /* what should be displayed on line 1 */
                           /*  0-19: Bat Chk */
                           /* 20-39: xxxxmV  */
                           /* 40-59: Okay/Replace */
    int bat = 0;           /* last read battery voltage */
    
    /* wait for user to press button B */
    while(!button_is_pressed(BUTTON_B))
    {
        /* clear the lcd */
        clear(); 
        
        /* FIRST LINE */
        /* set lcd position to beginning of first line */
        lcd_goto_xy(0,0); 
        
        /* for first line, alternate between displaying:
         Bat Check
         xxxxmV 
         Okay/Replace */
        
        if (firstLineType < 20)
        {
            print("Bat Chk");
        }
        else if (firstLineType < 40)
        {
            bat = read_battery_millivolts();
            print_long(bat);
            print("mV");
        }
        else if (firstLineType < 60)
        {
            if (bat >= 4500)
            {
                print("Okay"); /* okay */
            }
            else
            {
                print("Replace"); /* replace */
            }
        }
        firstLineType++;
        firstLineType = firstLineType % 60;
        
        /* SECOND LINE */
        /* set lcd position to beginning of second line */
        lcd_goto_xy(0,1); 
        print("Press B");
        
        /* small delay */
        delay_ms(50);
    }
    
    /* once pressed, wait a little bit */
    delay_ms(500);
}
Exemple #13
0
int main()
{
  TCCR0A = 0;         // configure timer0 to run at 78 kHz
  TCCR0B = 0x04;      // and overflow when TCNT0 = 256 (~3 ms)
  play_from_program_space(rhapsody);

  while(1)
  {
    // allow the sequence to keep playing automatically through the following delays
#ifndef ALWAYS_CHECK
    play_mode(PLAY_AUTOMATIC);
#else
    play_mode(PLAY_CHECK);
#endif
    lcd_goto_xy(0, 0);
    print("blink!");
    int i;
    for (i = 0; i < 8; i++)
    {
#ifdef ALWAYS_CHECK
      play_check();
#endif
      red_led(1);
      delay_ms(500);
      red_led(0);
      delay_ms(500);
    }
  
    lcd_goto_xy(0, 0);
    print("timing");
    lcd_goto_xy(0, 1);
    print("        ");    // clear bottom LCD line
    // turn off automatic playing so that our time-critical code won't be interrupted by
    // the buzzer's long timer1 interrupt.  Otherwise, this interrupt could throw off our
    // timing measurements.  Instead, we will now use playCheck() to keep the sequence
    // playing in a way that won't throw off our measurements.
#ifndef ALWAYS_AUTOMATIC
    play_mode(PLAY_CHECK);
#endif
    unsigned char maxTime = 0;
    for (i = 0; i < 8000; i++)
    {
      TCNT0 = 0;
      while (TCNT0 < 20)    // time for ~250 us
        ;
      if (TCNT0 > maxTime)
        maxTime = TCNT0;    // if the elapsed time is greater than the previous max, save it
#ifndef ALWAYS_AUTOMATIC
      play_check();   // check if it's time to play the next note and play it if so
#endif
    }
    lcd_goto_xy(0, 1);
    print("max=");
    print_long((unsigned int)maxTime);
    print(" ");  // overwrite any left over characters
  }
}
Exemple #14
0
// Displays the battery voltage.
void bat_test()
{
    int bat = read_battery_millivolts();

    print_long(bat);
    print("mV");

    delay_ms(100);
}
Exemple #15
0
void print_queue(pok_sched_asynch_event_t* head)
{
	pok_sched_asynch_event_t* current_asynch = head;
	while (current_asynch != POK_NULL){
		print_long(current_asynch->timestamp);
		printf(" -> ");
		current_asynch = current_asynch->next;
	}
	printf("[DEBUG_O1]\t END_QUEUE\n");
}
Exemple #16
0
int main()
{
  // Make SSbar be an output so it does not interfere with SPI communication.
  set_digital_output(IO_B4, LOW);

  // Set the mode to SVP_MODE_ANALOG so we can get analog readings on line D/RX.
  svp_set_mode(SVP_MODE_ANALOG);

  while(1)
  {
    clear(); // Erase the LCD.

    if (usb_configured())
    {
      // Connected to USB and the computer recognizes the device.
      print("USB");
    }
    else if (usb_power_present())
    {
      // Connected to USB.
      print("usb");
    }

    if (usb_suspend())
    {
      // Connected to USB, in the Suspend state.  
      lcd_goto_xy(4,0);
      print("SUS");
    }

    if (dtr_enabled())
    {
      // The DTR virtual handshaking line is 1.
      // This often means that a terminal program is conencted to the
      // Pololu Orangutan SVP USB Communication Port.
      lcd_goto_xy(8,0);
      print("DTR");
    }

    if (rts_enabled())
    {
      // The RTS virtual handshaking line is 1.
      lcd_goto_xy(12,0);
      print("RTS");
    }

    // Display an analog reading from channel D, in millivolts.
    lcd_goto_xy(0,1);
    print("Channel D: ");
    print_long(analog_read_millivolts(CHANNEL_D));

    // Wait for 100 ms, otherwise the LCD would flicker.
    delay_ms(100);
  }
}
Exemple #17
0
void test()
{
	unsigned char button;

	clear();
	delay(200);
	print("Orangutn");	// print to the top line of the LCD
	delay_ms(400);		// delay 200 ms
	lcd_goto_xy(0, 1);	// go to the start of the second LCD line

#if defined __AVR_ATmega328P__
	print(" SV-328");	// print to the bottom line of the LCD
#elif defined __AVR_ATmega168__
	print(" SV-168");	// print to the bottom line of the LCD
#else
#error "Unrecognized device type"
#endif

	delay_ms(1000);		// delay 700 ms

	clear();			// clear the LCD, move cursor to start of top line

	print("  VBAT");

	do
	{
		// Perform 10-bit analog-to-digital conversions on ADC channel 6.
		// Average ten readings and return the result, which will be one
		// third of the battery voltage when the "ADC6 = VBAT/3" solder
		// bridge is in place on the bottom of the Orangutan PCB
		int vbat = analog_read_average(6, 10);	// 10-sample avg of ADC6
		vbat = to_millivolts(vbat) * 3;	// convert reading to bat. voltage (mV)
		lcd_goto_xy(0, 1);	// go to the start of the second LCD line
		print_long(vbat);	// display battery voltage in millivolts
		print(" mV ");		// display the units
		delay_ms(50);		// delay for 50 ms
		button = button_is_pressed(ANY_BUTTON);	// check for button press
	}
	while (button == 0);	// loop if no buttons are being pressed


	// *** MAIN LOOP ***

	while (1)	// loop forever
	{
		if (button & TOP_BUTTON)			// if the top button is pressed
			button = melodyTest();	// this func. loops until next button press

		else if (button & MIDDLE_BUTTON)	// if the middle button is pressed
			button = IOTest();		// this func. loops until next button press

		else if (button & BOTTOM_BUTTON)	// if the bottom button is pressed
			button = motorTest();	// this func. loops until next button press
	}
}
Exemple #18
0
static int print_sysconf(const struct conf_variable *cp, const char *pathname)
{
	long val;

	errno = 0;
	if ((val = sysconf((int)cp->value)) == -1) {
		if (errno != 0) err(EXIT_FAILURE, "sysconf(%ld)", cp->value);
		return -1;
	}
	print_long(cp->name, val);
	return 0;
}
Exemple #19
0
void    check_long(t_mar *mar, int c)
{
  if (mar->str[c + 1] == 'o' && mar->str[c + 2] == 'n'
      && mar->str[c + 3] == 'g'
      && mar->str[c + 4] == ' ' && mar->str[c + 5] != 'l')
    print_long(c + 4, mar);
  else if (mar->str[c + 1] == 'o' && mar->str[c + 2] == 'n'
           && mar->str[c + 3] == 'g' && mar->str[c + 4] == ' '
           && mar->str[c + 5] == 'l' && mar->str[c + 6] == 'o'
           && mar->str[c + 7] == 'n' && mar->str[c + 8] == 'g'
           && mar->str[c + 9] == ' ' && mar->str[c + 10] != 'i')
    print_long(c + 9, mar);
  else if (mar->str[c + 1] == 'o' && mar->str[c + 2] == 'n'
           && mar->str[c + 3] == 'g' && mar->str[c + 4] == ' '
           && mar->str[c + 5] == 'l' && mar->str[c + 6] == 'o'
           && mar->str[c + 7] == 'n' && mar->str[c + 8] == 'g'
           && mar->str[c + 9] == ' ' && mar->str[c + 10] == 'i'
           && mar->str[c + 11] == 'n' && mar->str[c + 12] == 't'
           && mar->str[c + 13] == ' ')
    print_long(c + 12, mar);
}
Exemple #20
0
/* INFO: toplevel udt_clr_serialize */
int clr_serialize (int _gc_in, dk_session_t * ses)
{
  MonoArray *v_args = NULL;
  MonoArray *mono_list;
  int len, inx;
  MonoDomain *domain = virtuoso_domain;
  get_mono_thread ();

  v_args = MAKE_PARAM_ARRAY (domain, 1);

  SET_INT_ARG (domain, v_args, 0, _gc_in);

  QR_RESET_CTX
    {
      mono_list = (MonoArray *) call_mono (VIRTCLR_NAME, "VInvoke:obj_serialize_soap", v_args, domain);
    }
  QR_RESET_CODE
    {
      caddr_t err;
      POP_QR_RESET;
      err = thr_get_error_code (THREAD_CURRENT_THREAD);
      if (ARRAYP (err))
	log_error ("Mono Serialization error : [%s] [%s]", ERR_STATE(err), ERR_MESSAGE (err));
      else
	log_error ("Mono Serialization error : unknown");
      dk_free_tree (err);
      goto no_obj;
    }
  END_QR_RESET;

  len = mono_array_length (mono_list);
  if (len - 1 < 256)
    {
      session_buffered_write_char (DV_BIN, ses);
      session_buffered_write_char (len - 1, ses);
    }
  else
    {
      session_buffered_write_char (DV_LONG_BIN, ses);
      print_long (len - 1, ses);
    }
  for (inx = 1; inx < len; inx++)
    {
      MonoObject *obj = (MonoObject *)mono_array_get (mono_list, gpointer, inx);
      guint8 b = *(guint8 *)((char *)obj + sizeof (MonoObject));
      session_buffered_write_char (b, ses);
    }
  return len;
no_obj:
  session_buffered_write_char (DV_DB_NULL, ses);
  return 1;
}
Exemple #21
0
int main()
{
  set_analog_mode(MODE_10_BIT); // 10-bit analog-to-digital conversions

  while(1)                      // run over and over again
  {
    lcd_goto_xy(0,0);           // LCD cursor to home position (upper-left)
    print_long(to_millivolts(read_trimpot()));  // trimpot output in mV
    print(" mV  ");             // added spaces are to overwrite left over chars

    lcd_goto_xy(0, 1);          // LCD cursor to start of the second line

    unsigned int temp = read_temperature_f();  // get temp in tenths of a degree F
    print_long(temp/10);             // get the whole number of degrees
    print_character('.');            // print the decimal point
    print_long(temp - (temp/10)*10); // print the tenths digit
    print_character(223);       // print a degree symbol
    print("F  ");               // added spaces are to overwrite left over chars

    delay_ms(100);              // wait for 100 ms (otherwise LCD flickers too much)
  } 
}
Exemple #22
0
static int print_pathconf(const struct conf_variable *cp, const char *pathname)
{
	long val;

	errno = 0;
	if ((val = pathconf(pathname, (int)cp->value)) == -1) {
		if (all && errno == EINVAL) return 0;
		if (errno != 0) err(EXIT_FAILURE, "pathconf(%s, %ld)", pathname, cp->value);
		return -1;
	}
	print_long(cp->name, val);
	return 0;
}
Exemple #23
0
void runtime_error (int errnum)
{
    int wasfirst;
    
    if (errnum <= 0 || errnum > ERR_NUM_ERRORS)
	return;

    if (f_setup.err_report_mode == ERR_REPORT_FATAL
	|| (!f_setup.ignore_errors && errnum <= ERR_MAX_FATAL)) {
	flush_buffer ();
	os_fatal (err_messages[errnum - 1]);
	return;
    }

    wasfirst = (error_count[errnum - 1] == 0);
    error_count[errnum - 1]++;
    
    if ((f_setup.err_report_mode == ERR_REPORT_ALWAYS)
	|| (f_setup.err_report_mode == ERR_REPORT_ONCE && wasfirst)) {
	long pc;

	GET_PC (pc);
	print_string ("Warning: ");
	print_string (err_messages[errnum - 1]);
	print_string (" (PC = ");
	print_long (pc, 16);
	print_char (')');
        
	if (f_setup.err_report_mode == ERR_REPORT_ONCE) {
	    print_string (" (will ignore further occurrences)");
	} else {
	    print_string (" (occurence ");
	    print_long (error_count[errnum - 1], 10);
	    print_char (')');
	}
	new_line ();
    }

} /* report_error */
Exemple #24
0
Fichier : lsa.c Projet : daneos/lsa
//-----------------------------------------------------------------------------
int main(int argc, char **argv)
{
	struct stat finfo;
	char fname[PATH_MAX+1];
	int n, i, opts, single_file_mode = 0;
	struct dirent **list;
	config c;

	opts = options(argc, argv, &c);
	if(opts != OPT_OK) return -1;

	// if scandir raises error, switch to single file mode as argument is probably not a directory
	if((n = scandir(c.dir, &list, NULL, alphasort)) < 0)
	{
		perror("main()/scandir(): falling back to single file mode");
		single_file_mode = 1;
		n = 1;
	}

	for(i=0; i < n; i++)
	{
		// prepend file name with directory (needed for dirs other than .)
		if(!single_file_mode) snprintf(fname, sizeof fname, "%s/%s", c.dir, list[i]->d_name);
		
		// get file info
		if(lstat(single_file_mode ? c.dir : fname, &finfo) == -1)
		{
			perror("main()/stat()");
			continue;
		}

		if(!filter_perm(&finfo, &c)) continue;
		// print entry with configured view
		switch(c.view)
		{
			case VIEW_SHORT:
				print_short(&finfo, single_file_mode ? c.dir : fname, single_file_mode ? c.dir : list[i]->d_name);
				break;
			case VIEW_LONG:
				print_long(&finfo, single_file_mode ? c.dir : fname, single_file_mode ? c.dir : list[i]->d_name);
				break;
			case VIEW_MINI:
				print_minimal(&finfo, single_file_mode ? c.dir : fname, single_file_mode ? c.dir : list[i]->d_name);
				break;
			default:
				fprintf(stderr, "main()/c.view: Oops! Something went wrong!\n");
		}
	}
	return 0;
}
Exemple #25
0
void time_test()
{
    static long elapsed_time = 0;
    static long last_read = 0;
    static long is_ticking = 0;
    static char a_is_pressed = 0;
    static char c_is_pressed = 0;
    static char last_seconds = 0;

    long current_time = get_ms();
    if(is_ticking)
        elapsed_time += current_time - last_read;

    last_read = current_time;

    if(button_is_pressed(BUTTON_A) && !a_is_pressed)
    {
        // reset
        a_is_pressed = 1;
        is_ticking = 0;
        elapsed_time = 0;
        if(!is_playing()) // only play once
            play_from_program_space(beep_button_a);
    }

    // find the end of the button press without stopping
    if(!button_is_pressed(BUTTON_A))
        a_is_pressed = 0;

    if(button_is_pressed(BUTTON_C) && !c_is_pressed)
    {
        // start/stop
        c_is_pressed = 1;
        is_ticking = !is_ticking;
        play_from_program_space(beep_button_c);
    }

    // find the end of the button press without stopping
    if(!button_is_pressed(BUTTON_C))
        c_is_pressed = 0;

    print_long((elapsed_time/1000/60/10)%10); // tens of minutes
    print_long((elapsed_time/1000/60)%10); // minutes
    print_character(':');
    print_long((elapsed_time/1000)%60/10); // tens of seconds
    char seconds = ((elapsed_time/1000)%60)%10;
    print_long(seconds); // seconds
    print_character('.');
    print_long((elapsed_time/100)%10); // tenths of seconds
    print_long((elapsed_time/10)%10); // hundredths of seconds

    // beep every second
    if(seconds != last_seconds && elapsed_time != 0 && !is_playing())
        play_from_program_space(timer_tick);
    last_seconds = seconds;
}
int main() {
    setup();
    //displayWelcome();
    displayBattery();
    unsigned char b = lineCalibration();


    int numTurns = 0;
    const int MAX_TURNS = 8;
    char turns[MAX_TURNS+1];

    if (b == BUTTON_B) {
        numTurns = followTrack(turns, MAX_TURNS);

        clear();
        if (numTurns <= MAX_TURNS) {
            //play_from_program_space(success);

            turns[numTurns] = '\0';
            print(turns);
        } else {
            print_long(numTurns);
            print(" turns.");
        }
    } else if (b == BUTTON_A) {
        bool l = false;
        bool r = false;
        bool s = false;
        followSegment(l, r, s);
        clear();
        if (l) {
            lcd_goto_xy(0,1);
            print("L");
        }
        if (s) {
            lcd_goto_xy(4,0);
            print("S");
        }
        if (r) {
            lcd_goto_xy(7,1);
            print("R");
        }
    }
    while (true); // prevent exit from main
    return 0; // dead code
}
Exemple #27
0
int main()
{
	play_from_program_space(PSTR(">g32>>c32"));  // Play welcoming notes.

	while(1)
	{
		// Print battery voltage (in mV) on LCD.
		clear();
		print_long(read_battery_millivolts_sv());

		red_led(1);     // Turn on the red LED.
		delay_ms(200);  // Wait for 200 ms.

		red_led(0);     // Turn off the red LED.
		delay_ms(200);  // Wait for 200 ms.
	}
}
Exemple #28
0
void pok_sched_set_asynch_event(uint32_t thread_id, uint64_t time, pok_event_type_t type)
{
	if ((pok_threads[thread_id].timeout != POK_NULL) && (pok_threads[thread_id].timeout->type == POK_EVENT_DELAYED_START))
	{
		// overwrite of the previously created DELAYED_START event on NORMAL partition mode
		pok_threads[thread_id].timeout-> timestamp = time;
 #ifdef POK_NEEDS_DEBUG_O1
		printf("[DEBUG_O1]\t UPDATED ASYNCH EVENT: thread %d to be activated at time ", thread_id);
		print_long(pok_threads[thread_id].timeout-> timestamp);
		printf("\n");
 #endif
		return;
	}
	uint64_t now = POK_GETTICK();
	pok_sched_asynch_event_t* new_event = POK_CURRENT_PARTITION.head_asynch_empty;
	uint32_t the_mask = (1 << (pok_threads[thread_id].pos - pok_partitions[pok_threads[thread_id].partition].thread_index_low));
	new_event->pos = thread_id;
	new_event->timer = time;
	new_event->timestamp = now + time;
	new_event->mask = the_mask;
	new_event->type = type;
	if (new_event->next != POK_NULL)
		new_event->next->previous = POK_NULL;
	POK_CURRENT_PARTITION.head_asynch_empty = new_event->next;
	// add to temporary queue
	new_event->next = POK_CURRENT_PARTITION.head_asynch_temporary; //insert in head
	if (new_event->next != POK_NULL)
		new_event->next->previous = new_event;
	POK_CURRENT_PARTITION.head_asynch_temporary = new_event;
	pok_threads[thread_id].timeout = new_event;

#ifdef POK_NEEDS_DEBUG_O1
	if (POK_CURRENT_PARTITION.head_asynch_empty != POK_NULL || 
	POK_CURRENT_PARTITION.head_asynch_temporary != POK_NULL || 
	POK_CURRENT_PARTITION.head_asynch_queue != POK_NULL)
	{
		printf("**********************************************************************\n");
		printf("DEBUG_O1::CREATED ASYNCH EVENT: thread %d to be activated at time ",thread_id);print_long(new_event->timestamp);printf("\n");
		printf("** Empty queue: ");print_queue(POK_CURRENT_PARTITION.head_asynch_empty);
		printf("** Temporary queue: ");print_queue(POK_CURRENT_PARTITION.head_asynch_temporary);
		printf("** Actual queue: ");print_queue(POK_CURRENT_PARTITION.head_asynch_queue);
		printf("**********************************************************************\n");
	}
#endif
}
Exemple #29
0
int main()
{
	play_from_program_space(PSTR(">g32>>c32"));  // Play welcoming notes.

	while(1)
	{
		// Get battery voltage (in mV) from the auxiliary processor
		// and print it on the the LCD.
		clear();
		print_long(read_battery_millivolts_svp());

		red_led(1);     // Turn on the red LED.
		delay_ms(200);  // Wait for 200 ms.

		red_led(0);     // Turn off the red LED.
		delay_ms(200);  // Wait for 200 ms.
	}
}
Exemple #30
0
void pok_sched_service_asynch_events()
{
	uint64_t now = POK_GETTICK();
	pok_sched_asynch_event_t* current_asynch = POK_CURRENT_PARTITION.head_asynch_queue;
	while (current_asynch != POK_NULL && current_asynch->timestamp <= now)
	{
		POK_CURRENT_PARTITION.runnables |= current_asynch->mask;
		POK_CURRENT_PARTITION.head_asynch_queue = current_asynch->next;
		if (pok_threads[current_asynch->pos].timeout->type == POK_EVENT_DELAYED_START)
		{
			current_asynch->next = POK_CURRENT_PARTITION.head_asynch_temporary; //put the event back in the (head of) temporary queue
			if (POK_CURRENT_PARTITION.head_asynch_temporary != POK_NULL)
				POK_CURRENT_PARTITION.head_asynch_temporary->previous = current_asynch;
			POK_CURRENT_PARTITION.head_asynch_temporary = current_asynch;
		}
		else
		{
			current_asynch->next = POK_CURRENT_PARTITION.head_asynch_empty; //put the event in the (head of) empty queue
			if (POK_CURRENT_PARTITION.head_asynch_empty != POK_NULL)
				POK_CURRENT_PARTITION.head_asynch_empty->previous = current_asynch;
			POK_CURRENT_PARTITION.head_asynch_empty = current_asynch;
			pok_threads[current_asynch->pos].timeout = POK_NULL;
			current_asynch->timer =0;
			current_asynch->timestamp =0;
			current_asynch->mask =0;
			current_asynch->pos =0;
		}
 #ifdef POK_NEEDS_DEBUG_O1
		if (POK_CURRENT_PARTITION.head_asynch_empty != POK_NULL || POK_CURRENT_PARTITION.head_asynch_temporary != POK_NULL || POK_CURRENT_PARTITION.head_asynch_queue != POK_NULL)
		{
			printf("**********************************************************************\n");
			printf("DEBUG_O1::SERVICE ASYNCH EVENT: thread %d (to be activated at ");
			print_long(current_asynch->timestamp);printf(") has been activated at time ",current_asynch->pos);print_long(now);printf("\n");
			printf("** Empty queue: ");print_queue(POK_CURRENT_PARTITION.head_asynch_empty);
			printf("** Temporary queue: ");print_queue(POK_CURRENT_PARTITION.head_asynch_temporary);
			printf("** Actual queue: ");print_queue(POK_CURRENT_PARTITION.head_asynch_queue);
			printf("**********************************************************************\n");
		}
 #endif				
		current_asynch = POK_CURRENT_PARTITION.head_asynch_queue;
	}
}