static void
serial_handler(
	int			fd,
	void *			user_arg
)
{

	char			line[ 256 ];
	int			    len;

    if (serial_fd==0) 
        return;

	if( !read_char_line( serial_fd, line, sizeof(line) ) )
	{
		perror( "read_char" );
		return;
	}

	len = strlen( line );
	line[len++] = '\n';
	line[len] = '\0';

    if (gui->pause_raw_output->value()!=1) {
        gui->raw_serial_output->insert(line);
        Fl_Text_Buffer *textBuffer = gui->raw_serial_output->buffer();
        int numLines = textBuffer->count_lines(0, textBuffer->length());
        gui->raw_serial_output->scroll(numLines, 0);

        // ugly way to keep the buffer from growing unchecked
        if (numLines > 1000) {
            textBuffer->remove(0, (textBuffer->length()-100));
        }
    }

	if( strncmp( line, "$GPADC", 6 ) == 0 )
	{
	    imu_samples++;
        update_adc(line);
	} else

	if( strncmp( line, "$GPPPM", 6 ) == 0 )
	{
        update_ppm(line);
	} else

    {
		// Ignore the line for now
	}

}
Exemplo n.º 2
0
void text_editor::cb_save(Fl_Widget *widget, void *v)
{
	extern std::list<std::string> whitelist;

	text_editor *editor = (text_editor*)v;
	Fl_Text_Buffer *buffer = editor->buffer;
	
	int buff_length = buffer->length();
	int buff_lines = buffer->count_lines(0, buff_length);
	
	if (buff_lines > 0)
	{
		int pos = 0;
		whitelist.clear();
		
		for (int i = 0; i <= buff_lines; i++)
		{
			char* line_text = buffer->line_text(pos);
			std::string line(line_text);
			free(line_text);

			if(line.length() > 3)
				whitelist.push_back(line);

			pos = min(buffer->line_end(pos) + 1, buff_length);
		}
	}

	editor->hide();
}
Exemplo n.º 3
0
void ModelViewController::ConvertToGCode()
{
	string GcodeTxt;

	Fl_Text_Buffer* buffer = gui->GCodeResult->buffer();
	buffer->remove(0, buffer->length());

	buffer = gui->GCodeStart->buffer();
	char* pText = buffer->text();
	string GCodeStart(pText);
	buffer = gui->GCodeLayer->buffer();
	free(pText);
	pText = buffer->text();
	string GCodeLayer(pText);
	buffer = gui->GCodeEnd->buffer();
	free(pText);
	pText = buffer->text();
	string GCodeEnd(pText);
	free(pText);

	ProcessControl.ConvertToGCode(GcodeTxt, GCodeStart, GCodeLayer, GCodeEnd);
	buffer = gui->GCodeResult->buffer();

	GcodeTxt += "\0";
	buffer->append( GcodeTxt.c_str() );
	redraw();
}
Exemplo n.º 4
0
void ModelViewController::Print()
{
	if( !serial->isConnected() )
	{
		fl_alert ("Not connected to printer.\nCannot start printing");
		return;
	}

	gui->ContinueButton->value(0);
	gui->ContinueButton->activate();
	gui->ContinueButton->label("Pause");
	gui->PrintButton->value(1);
	gui->PrintButton->label("Print");
	gui->PrintButton->deactivate();

	// Snack one line at a time from the Gcode view, and buffer it.
/*
	if(gui->PrintButton->value() == 0)	// Turned off print, cancel buffer and flush
	{
		m_bPrinting = false;
		return;
	}
*/
	serial->Clear();	// resets line nr and buffer
	serial->m_bPrinting = false;
	serial->SetDebugMask();
	serial->SetLineNr(-1);	// Reset LineNr Count
	gui->CommunationLog->clear();
	Fl_Text_Buffer* buffer = gui->GCodeResult->buffer();
	char* pText = buffer->text();
	uint length = buffer->length();

	uint pos = 2;
	while(pos < length)
		{
		char* line = buffer->line_text(pos);
		if(line[0] == ';')
			{
			pos = buffer->line_end(pos)+1;	// skip newline
			continue;
			}
		serial->AddToBuffer(line);
		pos = buffer->line_end(pos)+1;	// find end of line
		}

	gui->ProgressBar->maximum(serial->Length());
	gui->ProgressBar->label("Printing");
	gui->ProgressBar->value(0);
	free(pText);
	serial->StartPrint();
}
Exemplo n.º 5
0
static void
style_update(int		pos,			// I - Position of update
			 int		nInserted,		// I - Number of inserted chars
			 int		nDeleted,		// I - Number of deleted chars
			 int		/*nRestyled*/,	// I - Number of restyled chars
			 const char * /*deletedText*/,// I - Text that was deleted
			 void		*cbArg) {		// I - Callback data
  int	start,							// Start of text
		end;							// End of text
  char	last,							// Last style on line
		*style,							// Style data
		*text;							// Text data

  SchemeEditor *editor = (SchemeEditor*)cbArg;
  Fl_Text_Buffer *textbuf = editor->buffer();
  Fl_Text_Buffer *stylebuf = editor->style_buffer();

  // If this is just a selection change, just unselect the style buffer...
  if (nInserted == 0 && nDeleted == 0) {
	stylebuf->unselect();
	return;
  }

  // Track changes in the text buffer...
  if (nInserted > 0) {
	// Insert characters into the style buffer...
	style = new char[nInserted + 1];
	memset(style, 'A', nInserted);
	style[nInserted] = '\0';

	stylebuf->replace(pos, pos + nDeleted, style);
	delete[] style;
  } else {
	// Just delete characters in the style buffer...
	stylebuf->remove(pos, pos + nDeleted);
  }

  // Select the area that was just updated to avoid unnecessary
  // callbacks...
  stylebuf->select(pos, pos + nInserted - nDeleted);

  // Re-parse the changed region; we do this by parsing from the
  // beginning of the previous line of the changed region to the end of
  // the line of the changed region...	Then we check the last
  // style character and keep updating if we have a multi-line
  // comment character...
  start = textbuf->line_start(pos);
//	if (start > 0) start = textbuf->line_start(start - 1);
  end	= textbuf->line_end(pos + nInserted);
  text	= textbuf->text_range(start, end);
  style = stylebuf->text_range(start, end);
  if (start==end)
	last = 0;
  else
	last  = style[end - start - 1];

//	printf("start = %d, end = %d, text = \"%s\", style = \"%s\", last='%c'...\n",
//		   start, end, text, style, last);

  style_parse(text, style, end - start);

//	printf("new style = \"%s\", new last='%c'...\n",
//		   style, style[end - start - 1]);

  stylebuf->replace(start, end, style);
  editor->redisplay_range(start, end);

  if (start==end || last != style[end - start - 1]) {
//	  printf("Recalculate the rest of the buffer style\n");
	// Either the user deleted some text, or the last character
	// on the line changed styles, so reparse the
	// remainder of the buffer...
	free(text);
	free(style);

	end	  = textbuf->length();
	text  = textbuf->text_range(start, end);
	style = stylebuf->text_range(start, end);

	style_parse(text, style, end - start);

	stylebuf->replace(start, end, style);
	editor->redisplay_range(start, end);
  }

  free(text);
  free(style);
}
Exemplo n.º 6
0
void ModelViewController::ClearGcode()
{
	Fl_Text_Buffer* buffer = gui->GCodeResult->buffer();
	buffer->remove(0, buffer->length());
}
Exemplo n.º 7
0
void populate_psg(int pid_no)
{
    rapidxml::xml_node<> *passage_data=node->first_node();
    char cur_img_file_name[16];
    int cur_pid=atoi(get_attr_value(passage_data,"pid"));
    if(cur_pid<pid_no)
    {
        while(cur_pid!=pid_no)
        {
            passage_data=passage_data->next_sibling();
            cur_pid=atoi(get_attr_value(passage_data,"pid"));
        }
    }
    else if(cur_pid>pid_no)
    {
        while(cur_pid!=pid_no)
        {
            passage_data=passage_data->previous_sibling();
            cur_pid=atoi(get_attr_value(passage_data,"pid"));
        }
    }
    pid=pid_no;
    //so at this point i should have the right pid
    char temp[4];
    sprintf(temp,"%d",(pid+1)); // as the pids go from 0 to n while we count from 1 to n+1
    p_no->value(temp);
    rapidxml::xml_node<> *p_data=passage_data->first_node();
    Fl_Text_Buffer* buf;
    buf=new Fl_Text_Buffer();
    buf->text(get_attr_value(p_data,"txt"));
    unsigned char *pixels;
    int w,h;

    gen_random(cur_img_file_name,10);
    char *file_path=NULL;
    file_path = (char*)malloc((strlen(current_path)+16)*sizeof(char));
    strcpy(file_path,current_path);
    strcat(file_path,"line_no.gif");
    #ifdef __APPLE__
    pixels = stbi_load(file_path, &w, &h, 0, 3);
    #else
    pixels = stbi_load("line_no.gif", &w, &h, 0, 3);
    #endif
    if (pixels == 0)
    {
        fprintf(stderr, "Couldn't open input file '%s'\n", "line_no.gif");
        exit(1);
    }
    strcpy(file_path,current_path);
    strcat(file_path,cur_img_file_name);
    #ifdef __APPLE__
    stbi_write_png(file_path, w, (int)(buf->length()/1.6), 3, pixels, w*3);
    #else
    stbi_write_png(cur_img_file_name, w, (int)(buf->length()/1.6), 3, pixels, w*3);
    #endif

    buf->text("<body><table width='378' cellspacing=0 cellpadding=0 border=0><tr><td width='100' valign='top'><img src='");
    #ifdef __APPLE__
    buf->append(file_path);
    #else
    buf->append(cur_img_file_name);
    #endif
    buf->append("'></td><td><font face='courier' size=5>");
    buf->append(get_attr_value(p_data,"txt"));
    buf->append("</font></p></td></tr></table><table>");
    p->value(buf->text());
    //free(questions);
    questions=p_data->next_sibling();
    rapidxml::xml_node<> *temp_node=questions->last_node();
    totalq=atoi(get_attr_value(temp_node,"qid"));
    cur_progress *o1 = (cur_progress*)obj_progress;
    free(o1->circle_data);
    o1->circle_data = (int*)malloc((totalq+1)*sizeof(int));
    for(int i=0;i<=totalq;i++)  //1 = wrong, 2=right, 3=not asked
        o1->circle_data[i]=3;
    o1->num_circles=totalq+1;
    o1->redraw();
    populate_question(0);
    count_sec=0;
    count_min=0;
    enable_timer=1;
    #ifdef __APPLE__
    unlink(file_path);
    #else
    unlink(cur_img_file_name);
    #endif
}