Ejemplo n.º 1
0
void write_time(time_t *sometime, char *line) {
  	unsigned hrs, ds;
	
	LOCK_CLOCK();
	hrs = sometime->hours;
	ds = sometime->deci_seconds;
	UNLOCK_CLOCK();
	
	int_to_ascii(hrs, line, '0', 3);
	line[2] = ':';
	int_to_ascii(ds / 600, line + 3, '0', 3);
	line[5] = ':';
	int_to_ascii( (ds % 600) / 10, line + 6, '0', 3);
	line[8] = ' ';
}
Ejemplo n.º 2
0
void syscalls_install(void)
{
	char syscall_ascii[2] = "";
	int_to_ascii(num_syscalls, syscall_ascii);
	kprint("\n[+] Initializing syscall table with ", 0x07);
	kprint(syscall_ascii, 0x08);
	kprint(" functions\n", 0x07);
}
Ejemplo n.º 3
0
Archivo: rtc.c Proyecto: nis/EMP
INT8U get_ascii_char_at(INT8U pos)
/*****************************************************************************
*   Function : See module specification (.h-file).
*****************************************************************************/
{
	INT8U return_value = 0x00;
	
	switch ( pos )
	{
		case 0:
			return_value = int_to_ascii(seconds % 10);
			break;
		case 1:
			return_value = int_to_ascii(seconds / 10);
			break;
		case 2:
			return_value = int_to_ascii(minutes % 10);
			break;
		case 3:
			return_value = int_to_ascii(minutes / 10);
			break;
		case 4:
			return_value = int_to_ascii(hours % 10);
			break;
		case 5:
			return_value = int_to_ascii(hours / 10);
			break;
		default:
			return_value = int_to_ascii(0);
	}
	
	return return_value;
}
Ejemplo n.º 4
0
/* Handle showing the clock. */
void show_clock_display( char *a, char *b ){
	strcpy(a, "Press 0 for menu" );
	
	write_time(&time, b);
	
	int_to_ascii(temperature, b + 11, ' ', 4);
	b[14] = ' ';
	b[15] = 'F';
}
Ejemplo n.º 5
0
void isr_handler(registers_t *r) {
    kprint("received interrupt: ");
    char s[3];
    int_to_ascii(r->int_no, s);
    kprint(s);
    kprint("\n");
    kprint(exception_messages[r->int_no]);
    kprint("\n");
}
Ejemplo n.º 6
0
void show_stopwatch( char *a, char *b ){
	unsigned ds; 
    strcpy(a, "1:On 2:Off 3:Clr");
	
	LOCK_CLOCK();
	ds = stopwatch.deci_seconds;
	UNLOCK_CLOCK();
	
	write_time(&stopwatch, b);
	b[8] = '.';
	int_to_ascii((ds % 600) % 10, b + 9, ' ', 2);
}
Ejemplo n.º 7
0
void check_i2c_interface(void){
	if (i2c_get_received_data(i2c_buf)){
		if (i2c_buf[0]=='i'){
			if (i2c_buf[1]=='=' && i2c_buf[2]!='\0'){
				set_val[0]=atoi(&i2c_buf[2]);
				if(set_val[0]>I_MAX){
					set_val[0]=I_MAX;
				}
				if(set_val[0]<0){
					set_val[0]=0;
				}
				i2c_send_data("ok");
			}else{
				int_to_ascii(measured_val[0],i2c_buf,2,0);
				strcat(i2c_buf,"A");
				i2c_send_data(i2c_buf);
			}
		}else if (i2c_buf[0]=='s'){
			store_permanent();
			i2c_send_data("ok");
		}else if (i2c_buf[0]=='u'){
			if (i2c_buf[1]=='=' && i2c_buf[2]!='\0'){
				set_val[1]=atoi(&i2c_buf[2]);
				if(set_val[1]>U_MAX){
					set_val[1]=U_MAX;
				}
				if(set_val[1]<0){
					set_val[1]=0;
				}
				i2c_send_data("ok");
			}else{
				int_to_ascii(measured_val[1],i2c_buf,1,0);
				strcat(i2c_buf,"V");
				i2c_send_data(i2c_buf);
			}
		}else{
			i2c_send_data("err");
		}
	}
}
Ejemplo n.º 8
0
void put_time_to_string(char* timeString)
{
    time_t currentTime = (time_t)get_seconds_count();
    struct tm *rtc = localtime(&currentTime);
//    strftime(timeString, sizeof timeString, "%FT%TZ", rtc);
    char buffer[10];
    int_to_ascii(rtc->tm_year+1900, timeString);
    string_append(timeString,"-");
    if (rtc->tm_mon < 9) string_append(timeString,"0");
    int_to_ascii(rtc->tm_mon+1, buffer);
    string_append(timeString,buffer);
    string_append(timeString,"-");
    if (rtc->tm_mday < 10) string_append(timeString,"0");
    int_to_ascii(rtc->tm_mday, buffer);
    string_append(timeString,buffer);
    string_append(timeString,"T");
    if (rtc->tm_hour < 10) string_append(timeString,"0");
    int_to_ascii(rtc->tm_hour, buffer);
    string_append(timeString,buffer);
    string_append(timeString,":");
    if (rtc->tm_min < 10) string_append(timeString,"0");
    int_to_ascii(rtc->tm_min, buffer);
    string_append(timeString,buffer);
    string_append(timeString,":");
    if (rtc->tm_sec < 10) string_append(timeString,"0");
    int_to_ascii(rtc->tm_sec, buffer);
    string_append(timeString,buffer);
}
Ejemplo n.º 9
0
void update_display(void) {
  char buffer[6];
  const unsigned int seconds = uptime_seconds; // Ensure we have a consistent copy
                                               // of uptime_seconds (ex. it could
										       // change between the two conversions.)
											   
  moveLCDCursor(LCD_LINE_1);
  
  // Update the speed.
  LoadStrLCD("RPS  ");
  
  int_to_ascii(rps, buffer, ' ', 4);
  LoadStrLCD(buffer);
  
  // Update the CCS.
  LoadStrLCD(" CCS:");
  LoadStrLCD(ON_OR_OFF(ccs_enabled));
  
  moveLCDCursor(LCD_LINE_2);
  
  // Update the heat display.
  LoadStrLCD("H:");
  LoadStrLCD(ON_OR_OFF(heat_enabled));
  LoadStrLCD(" ");
  
  // Update the clock.
  int_to_ascii(seconds / 60, buffer, '0', 3);
  LoadStrLCD(buffer);
	
  LoadStrLCD(":");
	
  int_to_ascii(seconds % 60, buffer, '0', 3);
  LoadStrLCD(buffer);
  
  // Update the temperature.
  LoadStrLCD("T:");
  int_to_ascii(temperature, buffer, ' ', 4);
  LoadStrLCD(buffer);
}
Ejemplo n.º 10
0
void show_timer( char *a, char *b ){
    if (set_timer_position == 0 && timer.hours != MAX_HOURS) {
	  time_t difference;
	  
	  LOCK_CLOCK();
	  difference.hours = timer.hours - time.hours;
  	  difference.deci_seconds = timer.deci_seconds - time.deci_seconds;
	  UNLOCK_CLOCK();
	  
	  strcpy(a, "Time left:");
	
      write_time(&difference, b);
      b[8] = '.';
      int_to_ascii((difference.deci_seconds % 600) % 10, b + 9, ' ', 2);
	} else {
      show_time_prompt("New Timer MM:SS", a, b, set_timer_buffer);
	}
}
Ejemplo n.º 11
0
int main(void)
{
	char out_buf[20+1];
	measured_val[0]=0;
	measured_val[1]=0;
	init_dac();
	lcd_init(LCD_DISP_ON);
	init_kbd();
	set_val[0]=15;set_val[1]=50; // 150mA and 5V
	if (eeprom_read_byte((uint8_t *)0x0) == 19){
		// ok magic number matches accept values
		set_val[1]=eeprom_read_word((uint16_t *)0x04);
		set_val[0]=eeprom_read_word((uint16_t *)0x02);
	}
	// I2C also called TWI
	i2c_init(3,1,0);
	sei();
	i2c_send_data("on");
	init_analog();
	while (1) {

		// current
		measured_val[0]=adc_i_to_disp(getanalogresult(0));
		set_val_adcUnits[0]=disp_i_to_adc(set_val[0]);
		set_target_adc_val(0,set_val_adcUnits[0]);
		// voltage
		measured_val[1]=adc_u_to_disp(getanalogresult(1),measured_val[0]);
		set_val_adcUnits[1]=disp_u_to_adc(set_val[1])+disp_i_to_u_adc_offset(measured_val[0]);
		set_target_adc_val(1,set_val_adcUnits[1]);

		// voltage
		lcd_clrscr();
		int_to_ascii(measured_val[1],out_buf,1,1);
		lcd_puts(out_buf);
		lcd_puts("V ");
		int_to_ascii(set_val[1],out_buf,1,1);
		lcd_putc('[');
		lcd_puts(out_buf);
		lcd_putc(']');
		if (!is_current_limit()){
			// put a marker to show which value is currenlty limiting
			lcd_puts("<-");
		}

		// current
		lcd_gotoxy(0,1);
		int_to_ascii(measured_val[0],out_buf,2,0);
		lcd_puts(out_buf);
		lcd_puts("A ");
		int_to_ascii(set_val[0],out_buf,2,0);
		lcd_putc('[');
		lcd_puts(out_buf);
		lcd_putc(']');
		if (is_current_limit()){
			// put a marker to show which value is currenlty limiting
			lcd_puts("<-");
		}
		//dbg
		//int_to_ascii(is_dacval(),out_buf,0,0);
		//lcd_puts(out_buf);
		check_i2c_interface();

		// the buttons must be responsive but they must not 
		// scroll too fast if pressed permanently
		if (check_buttons()==0){
			// no buttons pressed
			delay_ms(100);
			bpress=0;
			check_i2c_interface();
			check_buttons();
			delay_ms(150);
		}else{
			// button press
			if (bpress > 11){
				// somebody pressed permanetly the button=>scroll fast
				delay_ms(10);
				check_i2c_interface();
				delay_ms(40);
			}else{
				bpress++;
				delay_ms(100);
				check_i2c_interface();
				delay_ms(150);
			}
		}
	}
	return(0);
}
Ejemplo n.º 12
0
void	write_climate_and_pc ()

{

	char	fn [70],
			lfs [7];

	int	i, j,
	
			jj = 0,
			
			lf;

	if (global_monitor)
		monitor_leaf(1, "write_climate_and_pc");

	write_esd();

	printf("    Writing:  Climate and Plant Community description. \n");

	open_files(0);

	for (i = 0; i < n_lats; i++)
	{
		for (j = 0; j < n_lons; j++)
		{
			if (earth[i][j] == '1')
			{
				read_data(jj);

				write_climate();

				write_pc();

				++jj;
			}
			else
				zero_data(1);
		}

		zero_data(0);
	}

	close_files();

	printf("    Writing:  LF FCs. \n");

	for (lf = 1; lf <= num_lf; lf++)
	{
		printf("              LF = %3d \n", lf);

		strcpy(fn, "Test/eco_leaf/lf_");

		if (lf < 10)
			strcat(fn, "00");
		else
			if (lf < 100)
				strcat(fn, "0");

		int_to_ascii(lf, lfs);
		strcat(fn, lfs);

		write_lf(lf, fn);
	}

	if (global_monitor)
		monitor_leaf(0, "write_climate_and_pc");

}
Ejemplo n.º 13
0
void	read_climate_and_pc ()

{

	char	fn  [77],
			fnp [77],
			lfs [7];

	int	i, j,

			jj = 0,

			lf;

	if (global_monitor)
		monitor_leaf(1, "read_climate_and_pc");

	read_esd();

	open_files(1);

	printf("    Reading:  Climate and Plant Community description. \n\n");

	for (i = 0; i < n_lats; i++)
	{
		for (j = 0; j < n_lons; j++)
		{
			if (earth[i][j] == '1')
			{
				read_climate();

				read_pc();

				set_constants(jj);

				int2str(eco[jj].iflpn, (jj + 1), 6, 0);

				++jj;
			}
			else
				skip_data(1);
		}

		skip_data(0);
	}

	close_files(0);

	printf("    Reading:  LF FCs. \n");

	strcpy(fnp, global_directory);
	strcat(fnp, "/lf_");

	for (lf = 1; lf <= num_lf; lf++)
	{
		printf("              LF = %3d \n", lf);

		strcpy(fn, fnp);

		if (lf < 10)
			strcat(fn, "00");
		else
			if (lf < 100)
				strcat(fn, "0");

		int_to_ascii(lf, lfs);
		strcat(fn, lfs);

		read_lf(lf, fn);
	}

	printf("\n");

	if (global_monitor)
		monitor_leaf(0, "read_climate_and_pc");

}
Ejemplo n.º 14
0
 void write_json_int(Writer& out, const char* name, int value) {
     char buf[20];
     write_quoted_string(out, name);
     write_char(out, ':');
     out.write(int_to_ascii(value, buf, 20));
 }
Ejemplo n.º 15
0
// Parser fuer Komandoeingabe
// Syntax: <Befehl><Geraet>:[Subbefehl]<Parameter>
// Befehl "!" setzt Parameter
// Befehl "?" liest Parameter
// Ausgaben des mc werden mit "#" eingeleitet
// Gerät "An" ADC An (n=0..7)
// Gerät "S" Systemzeit, "Ln" LEDn, "V" Version
// !A0:1 --> ADC0 gibt im Sekundenrythmus Werte aus; !A0:0 stopped den ADC0
// !L2:t100 --> LED2 blinkt im 100ms Rhytmus
void parser(unsigned char* p_p)
{
   switch(*p_p) {

      // Parameter setzen mit "!"
      case '!':
      switch(*(++p_p)){    

         case 'A':                   // ADC Analog Digitalwandler *******************************
	 ++p_p;
	 if('0'<=*p_p && *p_p<='7'){                 // 0 <= n <=7
            ADMUX &= 0xF0;                           // MUX0..3 loeschen
            ADMUX |= (*p_p - 0x30);                  // AD-Wandler Nr. n (0..7) wählen
	    ++p_p;		                     // nächste Zeichen (:) ignorieren
            switch(*(++p_p)){
               case '0':
	       status_ADC='0';                       // ADC sperren
	       break;
               case '1':
               status_ADC='1';                       // ADC freigeben
               break;
	       default:
               buffer_write_s(put_bp, (unsigned char*)"#!:Error\n> ");
               beeps(100,2);
            }
	    buffer_write_s(put_bp, (unsigned char*)"#!:OK\n");
            beeps(100,1);
	 }
	 else{   
            buffer_write_s(put_bp, (unsigned char*)"#!:Error\n> ");
            beeps(100,2);
         }
	 break;                       // ende ADC

	 // LED setzen *********************************************
         case 'L':
           switch(*(++p_p)){
             case '2':                // LED2 -->
             ++p_p;                   // nächste Zeichen (:) ignorieren
             switch(*(++p_p)){

                case '0':
                PORTD &= ~(1<<PD6);   // LED2 aus
                status_LED2='0';
                break;

                case '1':
                PORTD |= 1<<PD6;      // LED2 an
                status_LED2='1';
                break;

                case 's':
                PORTD |= 1<<PD6;      // LED2 singleshot
                status_LED2='s';
                delay = ascii_to_int(++p_p);
                break;

                case 't':
                PORTD |= 1<<PD6;      // LED2 toggle
                status_LED2='t';
                delay = ascii_to_int(++p_p);
                break;

                default:
                buffer_write_s(put_bp, (unsigned char*)"#?:Error\n> ");
                beeps(100,2);
                break;
             }
             buffer_write_s(put_bp, (unsigned char*)"#!:OK\n> ");
             beeps(100,1);
	  }
	  break;
	  
	  // Systemzeit setzen *************************************
	  case 's':
          sekunden = ascii_to_int(++p_p);
          buffer_write_s(put_bp, (unsigned char*)"#!:OK\n> ");
          beeps(100,1);
          break;
          default:
          buffer_write_s(put_bp, (unsigned char*)"#: Error\n> ");
          beeps(100,2);
       }
       break;

       // Parameter abfragen
       case '?': switch(*(++p_p)){

	  // Systemzeit auslesen ***********************************
          case 's':
          buffer_write_s(put_bp, (unsigned char*)"#s: ");
	  unsigned char timestring[11];
          buffer_write_s(put_bp, int_to_ascii(sekunden, timestring));
          buffer_write_s(put_bp, (unsigned char*)"\n> ");
          beeps(100,1);
	  break;
             
	  // Soft- Hardwareversion auslesen
          case 'v':
          buffer_write_s(put_bp, (unsigned char*)"#v: ");
          buffer_write_s(put_bp, version);
          buffer_write_s(put_bp, (unsigned char*)"\n> ");
          beeps(100,1);
	  break;

	  // Hilfe ausgeben
	  case 'h':
          buffer_write_s(put_bp, (unsigned char*)"#h: <command><device><number>:<subcommand>[parameter]\n> ");
          beeps(100,1);
	  break;

	  default:
          buffer_write_s(put_bp, (unsigned char*)"#: Error\n> ");
          beeps(100,2);
       }
       break;

       case '0': buffer_write_s(put_bp, (unsigned char*)"Taste 0 wurde gedrückt - LED2 1000ms\n> ");
       beep(100);
       buffer_write_s(put_bp, (unsigned char*)"Ausgabe über Interruptserviceroutine\n> ");
       break;
       
       case '1': buffer_write_s(put_bp, (unsigned char*)"Taste 1 wurde gedrückt - LED2 100ms\n> ");
       beep(100);
       delay=100;
       break;
       
       // Hilfe ausgeben (mit ?h zusammenführen)
       case 'h':
       case 0:
       buffer_write_s(put_bp, (unsigned char*)"#h: <command><device><number>:<subcommand>[parameter]\n> ");
       beeps(100,2);
       break;
       
       default:
       buffer_write_s(put_bp, (unsigned char*)"#: unbekantes Zeichen: ");
       buffer_write(put_bp,*p_p);
       buffer_write_s(put_bp, (unsigned char*)"\n");
       beeps(100,2);
    }
}