Exemplo n.º 1
0
/*
 * Updates the report by scanning all keys, and sending key all currently up keys.  The OS
 * takes care of repeat rates, etc.
 */
void update_report(){
	//Init rebortBuffer back aato 0
	for (uint8_t i = 0; i < 8; i++){
		report_buffer[i] = 0x00;
	}

	uint8_t buffer_index = 2;
	uint16_t columns = 0x0000;

	for (uint8_t row = 0; row < 8; row++){	
		set_row(row);
		_delay_us(10);
		columns = read_columns();
	
		if (columns != 0x00){
			for (uint8_t col = 0; col < 16; col++){
				if (_BV(col) & columns){
//					report_buffer[2] = 0x04;	//Hard coded to A; TODO Remove
					uchar key = 0;
					uchar mod = 0;

					lookup_qwerty(row, col, &key, &mod);
					if (key != 0) report_buffer[buffer_index] = key;
					if (mod != 0) report_buffer[0] |= mod;
					
					//At most we have 6 keys (byte 0 in report_buffer is mods; 1 is unused; 2..7 are keys)
					buffer_index++;
					if (buffer_index >= 8) return;
				}
			}
		}	
	}
}
Exemplo n.º 2
0
int read_block(int rows, int columns, FILE *f, double *target, regex_t *comment){
  int l;
  int bsize=1024;
  char buffer[bsize];

  for (l=0;l<rows;l++){ 
    do{
      fgets(buffer,bsize,f);
      //printf("%s (is comment: %i)\n",buffer,regexec(comment,buffer,0,NULL,0)==0 || strlen(buffer)<2);
    } while (regexec(comment,buffer,0,NULL,0)==0 || strlen(buffer)<2);
    //printf("⟨");
    read_columns(buffer,&target[l*columns],columns);
    //printf("⟩");
  }
  return EXIT_SUCCESS;
}
Exemplo n.º 3
0
time_series_t *read_data(char *file, int n_var, char **var)
{
    int i;
    char *name;

    int n_data;      /* number of relevant data columns */
    int *col;        /* positions of relevant columns in data file */
    int *index;      /* corresponding indices in variable list */

    int n_time;      /* number of data rows */

    time_series_t *ts;

    /* alloc mem */
    ASSIGN_NEW_MEMORY_BLOCK(ts, 1, time_series_t, NULL);

    /* alloc mem for index lists */
    ts->n_var = n_var;
    ASSIGN_NEW_MEMORY_BLOCK(ts->var,   n_var, char *,   NULL);
    ASSIGN_NEW_MEMORY_BLOCK(ts->data,  n_var, double *, NULL); 
    ASSIGN_NEW_MEMORY_BLOCK(ts->data2, n_var, double *, NULL);    

    /* initialize index lists */
    for ( i=0; i<n_var; i++ )
	{
	    ASSIGN_NEW_MEMORY_BLOCK(name, strlen(var[i])+1, char , NULL);
	    strcpy(name, var[i]);
	    ts->var[i]   = name;
	    ts->data[i]  = NULL;
	    ts->data2[i] = NULL;
	}

    /* alloc temp mem for column info */
    ASSIGN_NEW_MEMORY_BLOCK(col,   n_var, int, NULL);
    ASSIGN_NEW_MEMORY_BLOCK(index, n_var, int, NULL);

    /* read header line */
    n_data = read_header_line(file, n_var, var, col, index);
    ts->n_data = n_data;
	
    /* count number of lines */
    n_time = read_columns(file, 0, NULL, NULL, NULL);
    ts->n_time = n_time;

    /* alloc mem for data */
    for ( i=0; i<n_data; i++ )
	{
	    ASSIGN_NEW_MEMORY_BLOCK(ts->data[index[i]],  n_time, double, NULL);
	    ASSIGN_NEW_MEMORY_BLOCK(ts->data2[index[i]], n_time, double, NULL);
	}
    ASSIGN_NEW_MEMORY_BLOCK(ts->time,  n_time, double, NULL);

    /* read data */
    read_columns(file, n_data, col, index, ts);

    /* free temp mem */
    free(col);
    free(index);

    /* initialize interpolation type */
    ts->type = 3;
    /* calculate second derivatives */
    for ( i=0; i<n_var; i++ )
	if ( ts->data[i] != NULL )
	    {
		if ( spline(ts->n_time, ts->time, ts->data[i], ts->data2[i]) != 1 )
		    return NULL; /* ran out of memory during spline routine */
	    }

    ts->last = 0;
    
    /* alloc mem for warnings */
    ASSIGN_NEW_MEMORY_BLOCK(ts->mess, 2, char *, NULL);
    ASSIGN_NEW_MEMORY_BLOCK(ts->warn, 2, int,    NULL);   

    /* initialize warnings */
    ts->mess[0] = "argument out of range (left) ";
    ts->mess[1] = "argument out of range (right)";
    for ( i=0; i<2; i++ )
	ts->warn[i] = 0;  

    return ts;
    
}