Ejemplo n.º 1
0
void update_lcd(void)
{
  if(show_settings_time) //Einstellungen anzeigen
  {
    lcd_clrscr();
    lcd_gotoxy(0,0);
    lcd_puts(font_name);
    char buf[3];
    itoa(font_size,buf,10);
    lcd_puts(buf);
  }
  else //normaler Editor
  {
    lcd_command(LCD_DISP_ON);
    lcd_gotoxy(0,0);
    //_delay_us(30);
    uint8_t x;
    uint8_t cx, cy, vx, vy;
    get_viewport(&vx, &vy);
    get_cursor(&cx, &cy);
    for(x=0;x<LCD_WIDTH;x++)
      lcd_putc(get_text_buffer(vy)[vx+x]);
    for(x=0;x<LCD_WIDTH;x++)
      lcd_putc(get_text_buffer(vy+1)[vx+x]);
    lcd_gotoxy(cx-vx,cy-vy);
    lcd_command(LCD_DISP_ON_CURSOR);
  }
}
Ejemplo n.º 2
0
int
new_descriptor (int s)
{
  int desc;
  struct sockaddr_in sock;
  DESCRIPTOR_DATA *newd, *td;
  char ip[MAX_STRING_LENGTH];
  struct hostent *from = NULL;

  socklen_t size;

  size = sizeof (sock);

  if ((desc = accept (s, (struct sockaddr *) &sock, &size)) < 0)
    {
      perror ("Accept");
      return (-1);
    }

  nonblock (desc);
  if ((maxdesc + 1) >= avail_descs)
    {
      write (desc, "The game is full.  Try later.\n\r", 31);
      close (desc);
      return (0);
    }
  else if (desc > maxdesc)
    maxdesc = desc;

  newd = new struct descriptor_data;

  init_descriptor (newd, desc);

  *ip = '\0';
  strcpy (ip, inet_ntoa (sock.sin_addr));

  newd->strClientIpAddr = str_dup (ip);
  newd->strClientHostname = str_dup (ip);

  std::string resolved_hostname = resolved_host (newd->strClientHostname);
  if (resolved_hostname.empty ())
    {
      from = gethostbyaddr ((char *) &sock.sin_addr,
			    sizeof ((char *) & sock.sin_addr), 
			    AF_INET);
      if (from && *from->h_name != '-')
	{
	  mysql_safe_query ("INSERT INTO resolved_hosts "
			    "VALUES ('%s', '%s', %d)", 
			    ip, from->h_name, (int) time (0));
	  mem_free (newd->strClientHostname);
	  newd->strClientHostname = str_dup (from->h_name);
	}
      else
	{
	  mysql_safe_query
	    ("INSERT INTO resolved_hosts VALUES ('%s', '%s', %d)", ip, ip,
	     (int) time (0));
	}
    }
  else
    {
      mem_free (newd->strClientHostname);
      newd->strClientHostname = str_dup (resolved_hostname.c_str ());
      newd->resolved = 1;
    }

  if (!descriptor_list)
    descriptor_list = newd;
  else
    for (td = descriptor_list; td; td = td->next)
      {
	if (!td->next)
	  {
	    newd->next = NULL;
	    td->next = newd;
	    break;
	  }
      }

  if (connected > MAX_CONNECTIONS)
    {
      SEND_TO_Q ("\r\n"
		 "We apologize for the inconvenience, but the MUD is currently full.\r\n"
		 "\r\n"
		 "Please try back again later. Thank you.\r\n" "\r\n", newd);
      newd->connected = CON_PENDING_DISC;
      return (0);
    }

  if (!maintenance_lock)
    SEND_TO_Q (get_text_buffer (NULL, text_list, "greetings"), newd);
  else
    SEND_TO_Q (get_text_buffer (NULL, text_list, "greetings.maintenance"),
	       newd);
  SEND_TO_Q ("Your Selection: ", newd);
  newd->connected = CON_LOGIN;

  return (0);
}
Ejemplo n.º 3
0
/*
 *      //~ uart_puts_P("G21\n");
        //~ get_grbl_response();
        //~ uart_puts_P("G90\n");
        //~ get_grbl_response();
        //~ uart_puts_P("G94\n");
        //~ get_grbl_response();
        //~ uart_puts_P("G17\n");
        //~ get_grbl_response();
        //~ uart_puts_P("M3 S1000\n");
        //~ get_grbl_response();
        //~ uart_puts_P("F800.00\n");
        //~ get_grbl_response();
        //~ uart_puts_P("G0 Z1.00\n");
        //~ get_grbl_response();
        //~ uart_puts_P("G0 X15 Y15\n");
        //~ get_grbl_response();
        //~ uart_puts_P("G1 Z-1\n");
        //~ get_grbl_response();
        //~ uart_puts_P("G2 X25 Y25 I10\n");
        //~ get_grbl_response();
        //~ uart_puts_P("G0 Z1\n");
        //~ get_grbl_response();
        //~ uart_puts_P("G0 X35 Y15\n");
        //~ get_grbl_response();
        //~ uart_puts_P("G1 Z-1\n");
        //~ get_grbl_response();
        //~ uart_puts_P("G2 X25 Y5 I-10\n");
        //~ get_grbl_response();
        //~ uart_puts_P("G0 Z1\n");
        //~ get_grbl_response();
        //~ uart_puts_P("G0 X15 Y15\n");
        //~ get_grbl_response();
        //~ uart_puts_P("M5\n");
        //~ get_grbl_response();
        //~ uart_puts_P("M30\n");
*/
int main(void)
{
  stdout = &mystdout;
  //uart_init(UART_BAUD_SELECT_DOUBLE_SPEED(UART_BAUD_RATE,F_CPU));
  uart_init(UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU));
  lcd_init(LCD_DISP_ON_CURSOR);
  lcd_clrscr();
  lcd_gotoxy(0,0);
  lcd_puts_P("Needler v0.7\n");
  lcd_gotoxy(0,1);
  lcd_puts_P(__DATE__" aw");

  //Delay for Splash
  for(uint8_t i=0;i<160;++i)
    _delay_ms(15);

  //PD2: IN : Z_DIR
  //PD3: IN : Enable/FEED HOLD. 0=betätigt
  //PD6: OUT: Relais Pneumatikventil. 1=EIN
  DDRD  |= _BV(PD6);
  PORTD |= _BV(PD2) | _BV(PD3) | _BV(PD4) | _BV(PD5) | _BV(PD7);

  //PB1: IN: Z_STEP
  PORTB |= _BV(PB1);

  lcd_clrscr();
  clr_text_buffer();
  strncpy(font_name,"rowmans",10);

  /*** TIMER0 ***/
  OCR0=250;
  //CTC = Clear Timer on Compare match S.80
  //Normal port operation, OC0 disconnected
  //Prescaler=64 -> clk=250kHz
  TCCR0 = _BV(WGM01) | _BV(CS01) | _BV(CS00);
  //On Compare match Interrupt Enable for timer 0
  TIMSK |= _BV(OCIE0);

  /** TIMER1 **/
  //PWM Phase correct 10bit
  //Set OC1A+OC1B on match when upcounting (page 108)
  //TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(COM1A0) | _BV(COM1B0) | _BV(WGM11) | _BV(WGM10);
  //Prescaler = 1 (page 110)
  //TCCR1B = _BV(CS10);

  /** TIMER1 **/
  //External clock source on T1 pin. Clock on rising edge.
  TCCR1B = _BV(CS12) | _BV(CS11) | _BV(CS10);
  //OCR1x=5;

  /** External Interrupt INT0 PD2 **/
  //Any logical change on INT0 generates an interrupt request.
  MCUCR = _BV(ISC00);
  GICR = _BV (INT0);

  //enable global interrupts
  sei();
  uint8_t debounce_key=0, last_key=0;
  uint8_t key, event=0;
  for (;;)    /* main event loop */
    {
      key=key_get();
      if(key==last_key)
        debounce_key++;
      else
        debounce_key=0;
      if(debounce_key>50)
      {
        event=process_menu(key);
        debounce_key=0;
      }
      last_key=key;

      if(do_update_lcd || event)
      {
        update_lcd();
        do_update_lcd=0;
      }

      if (bit_is_clear(PIND,3) && !running)
      {
        grbl_num_err=0;
        grbl_num_ok=0;
        //empty read
        while(uart_getc()!=UART_NO_DATA);
        running=1;
        update_status_lcd();
        uart_puts_P("$X\n");
        get_grbl_response();
        strncpy(grbl_error_msg, "$H:Referenzfahrt",17);
        update_status_lcd();
        uart_puts_P("$H\n");
        get_grbl_response();
        strncpy(grbl_error_msg, "Gravur laeuft...",17);
        update_status_lcd();

       //int init_get_gcode_line ( char *font, char *text, double X0, double Y0, double Z_up, double Z_down, double yinc, double scale,
       //double feed, int precision, char verbose, char align, char use_inch);

        //int r = init_get_gcode_line("rowmans", "Hello world!", 1, 1, 1, -1, 7, 0.3, 1100, 3, 0, 'l', 0);
        uint8_t line_nr;
        double scale=font_size*0.047619;
        double x0, y0;
        char line[BUFFER_WIDTH];
        for(line_nr=0; line_nr<BUFFER_HEIGHT; line_nr++)
        {
          strncpy(line, get_text_buffer(line_nr), BUFFER_WIDTH);
          //Leerzeichen am Ende mit 0 füllen
          int8_t len = BUFFER_WIDTH-1;
          while(len>=0 && line[len]==' ') line[len--]=0;

          //Positionsberechnung
          //Die Alukärtchen haben 85x54mm
          x0 = 7; //10mm vorerst fix, wie einstellbar?
          y0 = 50 - (line_nr+1) * (font_size*1.7);  //70% der Zeichenhöhe als Zeilenabstand

          //~ uart_puts_P("-");
          //~ uart_puts(line);
          //~ uart_puts_P("-");
          //~ char xtemp[5];
          //~ itoa(len,xtemp,10);
          //~ uart_puts(xtemp);
          //~ uart_puts_P("----");

          if(len>=0)
          {
            init_get_gcode_line(font_name, line, x0, y0, 1, -1, 0, scale, 1300, 2, 0, 'l', 0);
            char buf[200];
            while((g_line = get_gcode_line (buf, 200))!=-1)
            {
              uart_puts(buf);
              uart_putc('\n');
              get_grbl_response();
            }
          }
        }
        strncpy(grbl_error_msg, "*** BEENDET  ***",17);
        update_status_lcd();
        PORTD &= (uint8_t) ~_BV(PD6);
        uart_puts_P("G0X1Y1\n");
        uart_puts_P("M30\n");
        //empty read
        while(uart_getc()!=UART_NO_DATA);
        //BEENDET etwas stehen lassen
        for(uint8_t i=0;i<200;++i)
          _delay_ms(10);
        grbl_error_msg[0]=0;
        do_update_lcd=1;
        running=0;
      }
    }
    return 0;
}