Пример #1
0
/***********************************************
Isolate the button's row:
Assuming Button is still pushed.  
(This has to be done quickly after a detect)
Return : stored in keys[] file scope variable
array[0] 	Front Row
array[1]   Front Row (5)
array[2] 	 	 Row (4)
array[3] 	  	 Row (3)
array[4]   		 Row (2)
************************************************/
void scan_keys( byte* mkeys )
{
  all_rows_high();
  for (int i=0; i<NUM_ROWS; i++)
  {
     set_row( i, 0 );
	 delay(CHARGE_TIME);
	 mkeys[i] = read_switches();		// upper nibble
     set_row( i, 1 );				// restore so not to affect the next row
  }
}
Пример #2
0
void fish_shape(uint8_t xi, uint8_t yi, uint8_t zi, uint16_t intensity)
{
	if(xi > 0) set_row(xi - 1, zi + 1, yi + 1, yi + 4, intensity);

	set_led(xi, yi, zi, intensity);
	set_row(xi, zi, yi + 2, yi + 4, intensity);
	set_row(xi, zi + 1, yi, yi + 5, intensity);
	set_row(xi, zi + 2, yi + 2, yi + 3, intensity);
	set_led(xi, yi, zi + 2, intensity);

	if(xi < LEDS_X - 1) set_row(xi + 1, zi + 1, yi + 1, yi + 4, intensity);
}
Пример #3
0
/***************************************************************
*   void vprintf_tests
*      
*
****************************************************************/
void vprintf_tests() {
    set_col(2); set_row(4);
    vprintf_custom("Esto es una prueba: %x %x %x %x", 1000, 10000, 1000000, 99999999);
    set_col(2); set_row(5);
    vprintf_custom("Esto es una prueba: %d %d %d %d", 1000, 10000, 1000000, 99999999);
    set_col(2); set_row(6);
    vprintf_custom("Esto es una prueba: %x %d %x %d", 1000, 10000, 1000000, 999999);
    set_col(2); set_row(7);
    vprintf_custom("Esto es una prueba: %x %d %s %x", 1000, 10000, "Hello!!", 99999999);
    set_col(2); set_row(10);
    vprintf_custom("Esto es una prueba: %s %s", "dos strings muuuuuuuuuuuy largooooooos", "012345678901234567890123456789001234567890123456789");
    print_vscreen();
}
 void row(
     std::size_t row
   , Values... v
     ) const 
 {
     set_row(row, 0, v...); 
 }
Пример #5
0
cell_reference::cell_reference(const std::string &string)
{
    auto split = split_reference(string, absolute_column_, absolute_row_);
    
    set_column(split.first);
    set_row(split.second);
}
Пример #6
0
int main()
{
	int i;
	int j;
	double a[SIZE][SIZE];
	double b[SIZE];
	for(i = 0; i < SIZE; i++) {
		b[i] = i;
	}
	for(i = 0; i < SIZE; i++) {
		for(j = 0; j < SIZE; j++)
			a[i][j] = 0;
	}
	set_row(a, b, 0, SIZE);
	for(i = 0; i < SIZE; i++) {
		printf("%f ",b[i]);
	}
	printf("\n");
	for(i = 0; i < SIZE; i++) {
		for(j = 0; j < SIZE; j++) {
			printf("%f ",a[i][j]);
		}
		printf("\n");
	}
	return 0;
}
Пример #7
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;
				}
			}
		}	
	}
}
Пример #8
0
void SparseSystem::add_row(const SparseVector& new_row, double new_r) {
  ensure_num_cols(new_row.last()+1);

  append_new_rows(1);
  int row = num_rows() - 1;
  _rhs(row) = new_r;
  set_row(row, new_row);
}
Пример #9
0
static void heart_layer(uint8_t x, uint16_t intensity) {
	set_row(x, 0, 1, 2, intensity);
	set_row(x, 0, 5, 6, intensity);
	set_row(x, 1, 0, 7, intensity);
	set_row(x, 2, 0, 7, intensity);
	set_row(x, 3, 0, 7, intensity);
	set_row(x, 4, 1, 6, intensity);
	set_row(x, 5, 2, 5, intensity);
	set_row(x, 6, 3, 4, intensity);
}
 void set_row(
     std::size_t row
   , std::size_t column
   , Head head
   , Tail... tail
     ) const 
 {
     (*this)(row, column) = head;
     set_row(row, column + 1, tail...);
 }
Пример #11
0
/***************************************************************
* int malloc_custom
*
****************************************************************/
void init_malloc_data() {

    if(system_memory_size == 0) {
        vprintf_custom("System memory size is 0.");
        print_vscreen();
        while(1) {}
    }

    bool show_data = true;
    unsigned int i = 0;
    unsigned int table_size = 0;
    unsigned int check = 0;

    memset_custom((char*)info, sizeof(info), 0);
    
    // Aloco el 10% de mi memoria total para mi 
    // registro de headers de memoria.
    table_size = (unsigned int)(system_memory_size * 0.1);
    malloc_registry = (memory_segment*)SAFE_ADDRESS;

    user_space_start = (byte*)(SAFE_ADDRESS + table_size + sizeof(memory_segment));
    user_memory_size = (unsigned int)(system_memory_size - (unsigned int)user_space_start);

    segments_amount = (unsigned int)(table_size / sizeof(memory_segment));
    minimum_segment_size = (unsigned int)(user_memory_size / segments_amount);

    memset_custom((char*)malloc_registry, table_size, 0);

    // Imprime las características del mapa de memoria.
    if(show_data == true) {
        clear_vscreen();
        set_row(3); set_col(0);
        vprintf_custom("Memory Table Size: %x", table_size);
        set_row(4); set_col(0);
        vprintf_custom("Malloc Registry Start: %x", malloc_registry);
        set_row(5); set_col(0);
        vprintf_custom("Total Memory Size: %x", system_memory_size);
        set_row(6); set_col(0);
        vprintf_custom("User Space Start: %x", user_space_start);
        set_row(7); set_col(0);
        vprintf_custom("User Memory Size: %x", user_memory_size);
        set_row(8); set_col(0);
        vprintf_custom("Number of Table Segments: %d", segments_amount);
        set_row(9); set_col(0);
        vprintf_custom("Minimum Allocable Space: %d(bytes)", minimum_segment_size);
        set_row(10); set_col(0);
        vprintf_custom("Memory Header Size: %x", sizeof(memory_segment));
        print_vscreen();
    }

    q_to_continue(SCREEN_LENGTH - 1, 2, 1);
}
Пример #12
0
/**
  \brief Nacte cast U z matice A
 */
void MTX::get_mtx_U(MTX& A)
{
    long i;
    ROW r;
    initialize(A.get_row_number(),A.get_column_number(),A.get_values_number());

    for(i=0;i<A.get_row_number();i++){
        r = A.get_row(i,i);
        r.values[0]=1;
        set_row(r,i);
    }
}
Пример #13
0
void set_rows(uint16_t data, uint8_t direction) {
    for(uint8_t i=0; i<ROWS; i++) {
        if(((data & (1<<i))>>i) == 1) {
            if(direction == 1) {
                set_row(i,((data & (1<<i))>>i));
                pulse();
                set_row(i,0);
            } else {
                clear_row(i,((data & (1<<i))>>i));
                pulse();
                clear_row(i,0);
            }
        }
Пример #14
0
/**
  \brief Nacte cast D z matice A
 */
void MTX::get_mtx_D(MTX& A)
{
    long i;
    double* d = new double[1];/// pro pouziti do funkce SPARSE::set_row(const double* v,const long* i,const long& l, const long& r)
    long*   ii= new long[1];/// pro pouziti do funkce SPARSE::set_row(const double* v,const long* i,const long& l, const long& r)
    initialize(A.get_row_number(),A.get_column_number(),A.get_values_number());

    for(i=0;i<A.get_row_number();i++){
        d[0] = A.get_diagonal(i);
        ii[0]=i;
        set_row(d,ii,1,i);
    }
}
Пример #15
0
// render and energize the current row, based on bitmap array
void refresh_line()
{
	int c;

	reset_led();
	set_row(current_row);
	
	for (c=0; c<COLS; c++) 
		if (bitmap[current_row][c]) set_column(c);

	/* GARY - Tuesday Sept 26 11:44pm */

	need_refresh_line = 0;
}
Пример #16
0
void row_gradient_green(void)
{

    int y;
    for (y=0; y<HEIGHT; y++)
    {
        //set_row(y,0, 0,(int)(255.0*(float)y/(float)HEIGHT));
        set_row(y, 0,(int)(255.0*(float)y/(float)HEIGHT),0);
        //set_row(y, (int)(255.0*(float)y/(float)HEIGHT),0,0);
        //set_row(y, (int)(255.0*(float)y/(float)HEIGHT),(int)(255.0*(float)y/(float)HEIGHT),0);
    }

    send();
}
Пример #17
0
int main(int argc, char **argv){
  char b[SIZE];
  int **board;
  FILE *f;

  board = calloc(SIZE, sizeof(int));
  int i;
  for(i=0; i<SIZE; i++){
    if (board == NULL) {
      printf("Memory allocation failed\n");
      exit(-1);
    }
    board[i] = calloc(SIZE, sizeof(int));
  }

  f = fopen(argv[1], "r");
  while ( (fgets(b, SIZE , f) != NULL) ){
    char *comm = strtok(b, " ");
    int roc = 0;
    int val = 0;
    if( (strspn(comm, sc) == strlen(sc))){
      roc = atoi(strtok(NULL, " "));
      val = atoi(strtok(NULL, " "));
      set_col(board, roc, val);
    }else if( (strspn(comm, sr)) == strlen(sr) ){
      roc = atoi(strtok(NULL, " "));
      val = atoi(strtok(NULL, " "));
      set_row(board, roc, val);
    }else if( (strspn(comm, qc)) == strlen(qc) ){
      roc = atoi(strtok(NULL, " "));
      printf("%d\n", query_col(board, roc));
    }else if( (strspn(comm, qr)) == strlen(qr) ){
      roc = atoi(strtok(NULL, " "));
      printf("%d\n", query_row(board, roc));
    }

  }

  for(i=0; i<SIZE; i++){
    free(board[i]);
  }
  free(board);
  fclose(f);
}
Пример #18
0
Файл: config.c Проект: rhn/jazda
void config_redraw(const uint8_t force) {
    if (force || module_flags.config_changed) {
        module_flags.config_changed = false;
        upoint_t position = {0, 4};
        upoint_t glyph_size = {8, 8};
        
        // erase old arrows
        erase_module_screen(); // makes screen flicker, but this is not important - not used often
        print_number((uint16_t)config_pulse_distance, position, glyph_size, 1, (number_display_t) {CONFIG_DIGITS, 0});
        if (config_level > 0) {
            position.y += 1;
            position.x = (CONFIG_DIGITS - config_place) * 9;
            set_row(position.y);
            set_column(position.x);
            char stamp = 0b111;
            if (config_level == 2) {
                stamp = 0b1;
            }
            for (uint8_t i = 0; i < 7; i++) {
                send_raw_byte(stamp, true);
            }
        }
    }
}
Пример #19
0
/*
 * This program demonstrates the Cdk matrix widget.
 */
int main (int argc, char **argv)
{
   /* *INDENT-EQLS* */
   CDKSCREEN *cdkscreen = 0;
   CDKMATRIX *courseList = 0;
   WINDOW *cursesWin    = 0;
   const char *title    = 0;
   int rows             = 8;
   int cols             = 5;
   int vrows            = 3;
   int vcols            = 5;

   bool use_coltitles;
   bool use_rowtitles;

   const char *coltitle[MY_COLS];
   const char *rowtitle[MY_COLS];
   const char *mesg[MY_COLS];

   int colwidth[MY_COLS];
   int colvalue[MY_COLS];

   CDK_PARAMS params;

   CDKparseParams (argc, argv, &params, "trcT:" CDK_MIN_PARAMS);

   /* invert, so giving -S causes the shadow to turn off */
   params.Shadow = !params.Shadow;

   /* cancel the default title, or supply a new one */
   if (CDKparamValue (&params, 't', FALSE))
   {
      title = 0;
   }
   else if ((title = CDKparamString (&params, 'T')) == 0)
   {
      title = "<C>This is the CDK\n<C>matrix widget.\n<C><#LT><#HL(30)><#RT>";
   }

   /* allow cancelling of column and/or row titles with -c and/or -r */
   use_coltitles = !CDKparamValue (&params, 'c', FALSE);
   use_rowtitles = !CDKparamValue (&params, 'r', FALSE);

   /* Set up CDK. */
   cursesWin = initscr ();
   cdkscreen = initCDKScreen (cursesWin);

   /* Start CDK Colors. */
   initCDKColor ();

   /* Create the horizontal and vertical matrix labels. */
#define set_col(n, width, string) \
   coltitle[n] = use_coltitles ? string : 0 ;\
   colwidth[n] = width ;\
   colvalue[n] = vUMIXED

   set_col (1, 7, "</B/5>Course");
   set_col (2, 7, "</B/33>Lec 1");
   set_col (3, 7, "</B/33>Lec 2");
   set_col (4, 7, "</B/33>Lec 3");
   set_col (5, 1, "</B/7>Flag");

#define set_row(n, string) \
   rowtitle[n] = use_rowtitles ? "<C></B/6>" string : 0

   set_row (1, "Course 1");
   set_row (2, "Course 2");
   set_row (3, "Course 3");
   set_row (4, "Course 4");
   set_row (5, "Course 5");
   set_row (6, "Course 6");
   set_row (7, "Course 7");
   set_row (8, "Course 8");

   /* Create the matrix object. */
   courseList = newCDKMatrix (cdkscreen,
			      CDKparamValue (&params, 'X', CENTER),
			      CDKparamValue (&params, 'Y', CENTER),
			      rows, cols, vrows, vcols,
			      title,
			      (CDK_CSTRING2) rowtitle,
			      (CDK_CSTRING2) coltitle,
			      colwidth, colvalue,
			      -1, -1, '.',
			      COL, params.Box,
			      params.Box,
			      params.Shadow);

   /* Check to see if the matrix is null. */
   if (courseList == 0)
   {
      /* Clean up. */
      destroyCDKScreen (cdkscreen);
      endCDK ();

      printf ("Cannot create the matrix widget.\n");
      printf ("Is the window too small ?\n");
      ExitProgram (EXIT_FAILURE);
   }

   /* Activate the matrix. */
   activateCDKMatrix (courseList, 0);

   /* Check if the user hit escape or not. */
   if (courseList->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>You hit escape. No information passed back.";
      mesg[1] = "";
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 3);
   }
   else if (courseList->exitType == vNORMAL)
   {
      char temp[80];

      sprintf (temp, "Current cell (%d,%d)", courseList->crow, courseList->ccol);
      mesg[0] = "<L>You exited the matrix normally.";
      mesg[1] = temp;
      mesg[2] = "<L>To get the contents of the matrix cell, you can";
      mesg[3] = "<L>use getCDKMatrixCell():";
      mesg[4] = getCDKMatrixCell (courseList, courseList->crow, courseList->ccol);
      mesg[5] = "";
      mesg[6] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, (CDK_CSTRING2) mesg, 7);
   }

   /* Clean up. */
   destroyCDKMatrix (courseList);
   destroyCDKScreen (cdkscreen);
   endCDK ();
   ExitProgram (EXIT_SUCCESS);
}
Пример #20
0
void	iter_lanczos(ITER *ip, VEC *a, VEC *b, Real *beta2, MAT *Q)
#endif
{
   int	j;
   STATIC VEC	*v = VNULL, *w = VNULL, *tmp = VNULL;
   Real	alpha, beta, c;
   
   if ( ! ip )
     error(E_NULL,"iter_lanczos");
   if ( ! ip->Ax || ! ip->x || ! a || ! b )
     error(E_NULL,"iter_lanczos");
   if ( ip->k <= 0 )
     error(E_BOUNDS,"iter_lanczos");
   if ( Q && ( Q->n < ip->x->dim || Q->m < ip->k ) )
     error(E_SIZES,"iter_lanczos");
   
   a = v_resize(a,(unsigned int)ip->k);	
   b = v_resize(b,(unsigned int)(ip->k-1));
   v = v_resize(v,ip->x->dim);
   w = v_resize(w,ip->x->dim);
   tmp = v_resize(tmp,ip->x->dim);
   MEM_STAT_REG(v,TYPE_VEC);
   MEM_STAT_REG(w,TYPE_VEC);
   MEM_STAT_REG(tmp,TYPE_VEC);
   
   beta = 1.0;
   v_zero(a);
   v_zero(b);
   if (Q) m_zero(Q);
   
   /* normalise x as w */
   c = v_norm2(ip->x);
   if (c <= MACHEPS) { /* ip->x == 0 */
      *beta2 = 0.0;
      return;
   }
   else 
     sv_mlt(1.0/c,ip->x,w);
   
   (ip->Ax)(ip->A_par,w,v);
   
   for ( j = 0; j < ip->k; j++ )
   {
      /* store w in Q if Q not NULL */
      if ( Q ) set_row(Q,j,w);
      
      alpha = in_prod(w,v);
      a->ve[j] = alpha;
      v_mltadd(v,w,-alpha,v);
      beta = v_norm2(v);
      if ( beta == 0.0 )
      {
	 *beta2 = 0.0;
	 return;
      }
      
      if ( j < ip->k-1 )
	b->ve[j] = beta;
      v_copy(w,tmp);
      sv_mlt(1/beta,v,w);
      sv_mlt(-beta,tmp,v);
      (ip->Ax)(ip->A_par,w,tmp);
      v_add(v,tmp,v);
   }
   *beta2 = beta;

#ifdef	THREADSAFE
   V_FREE(v);   V_FREE(w);   V_FREE(tmp);
#endif
}
Пример #21
0
static gpgme_key_t 
fill_clist (struct select_keys_s *sk, const char *pattern, gpgme_protocol_t proto)
{
    GtkCMCList *clist;
    gpgme_ctx_t ctx;
    gpgme_error_t err;
    gpgme_key_t key;
    int running=0;
    int num_results = 0;
    gboolean exact_match = FALSE;
    gpgme_key_t last_key = NULL;
    gpgme_user_id_t last_uid = NULL;
    cm_return_val_if_fail (sk, NULL);
    clist = sk->clist;
    cm_return_val_if_fail (clist, NULL);

    debug_print ("select_keys:fill_clist:  pattern '%s' proto %d\n", pattern, proto);

    /*gtk_cmclist_freeze (select_keys.clist);*/
    err = gpgme_new (&ctx);
    g_assert (!err);

    gpgme_set_protocol(ctx, proto);
    sk->select_ctx = ctx;

    update_progress (sk, ++running, pattern);
    while (gtk_events_pending ())
        gtk_main_iteration ();

    err = gpgme_op_keylist_start (ctx, pattern, 0);
    if (err) {
        debug_print ("** gpgme_op_keylist_start(%s) failed: %s",
                     pattern, gpgme_strerror (err));
        sk->select_ctx = NULL;
        gpgme_release(ctx);
        return NULL;
    }
    update_progress (sk, ++running, pattern);
    while ( !(err = gpgme_op_keylist_next ( ctx, &key )) ) {
	gpgme_user_id_t uid = key->uids;
	if (!key->can_encrypt || key->revoked || key->expired || key->disabled)
		continue;
        debug_print ("%% %s:%d:  insert\n", __FILE__ ,__LINE__ );
        set_row (clist, key, proto ); 
	for (; uid; uid = uid->next) {
		gchar *raw_mail = NULL;

		if (!uid->email)
			continue;
		if (uid->revoked || uid->invalid)
			continue;
		raw_mail = g_strdup(uid->email);
		extract_address(raw_mail);
		if (!strcasecmp(pattern, raw_mail)) {
			exact_match = TRUE;
			last_uid = uid;
			g_free(raw_mail);
			break;
		}
		g_free(raw_mail);
	}
	num_results++;
	last_key = key;
	key = NULL;
        update_progress (sk, ++running, pattern);
        while (gtk_events_pending ())
            gtk_main_iteration ();
    }
 
    if (exact_match == TRUE && num_results == 1) {
	    if (last_key->uids->validity < GPGME_VALIDITY_FULL && 
		!use_untrusted(last_key, last_uid, proto))
		    exact_match = FALSE;
    }

    debug_print ("%% %s:%d:  ready\n", __FILE__ ,__LINE__ );
    if (gpgme_err_code(err) != GPG_ERR_EOF) {
        debug_print ("** gpgme_op_keylist_next failed: %s",
                     gpgme_strerror (err));
        gpgme_op_keylist_end(ctx);
    }
    if (!exact_match || num_results != 1) {
	    sk->select_ctx = NULL;
	    gpgme_release (ctx);
    }
    /*gtk_cmclist_thaw (select_keys.clist);*/
    return (exact_match == TRUE && num_results == 1 ? last_key:NULL);
}
Пример #22
0
/***************************************************************
*   void malloc_command
*       Calcula la cantidad de RAM que tiene la máquina.
*
****************************************************************/
void malloc_command(char* params) {
    char option[20];
    unsigned int size = 0;
    unsigned int i = 0;

    memset_custom(option, sizeof(option), 0);

    sscanf_custom(params, "%s %d", option, &size);

    if( strcmp(option, "get") == 0 ) {
        if( size > minimum_segment_size ) {
            void* ptr = malloc_custom(size, 0);
            newline();
            if(ptr == 0) {
                vprintf_custom("No hay espacio para alocar %d bytes.", size);
            } else {
                for(i = 0; info[i].ptr != 0; i++) {}

                if( i < INFO_TABLE_SIZE ) {
                    vprintf_custom("Se aloco la memoria. Esta en la direccion %x", ptr);

                    info[i].ptr = ptr;
                    info[i].size = size;
                } else {
                    newline();
                    vprintf_custom("No puedes alocar mas memoria porque llenaste la"
                            "tabla que tiene las referencias de las alocaciones, y que"
                            "usa el comando malloc info.");
                }
            }
        } else {
            newline();
            vprintf_custom("Debes pedir %d bytes o mas.", minimum_segment_size);
        }
    } else if( strcmp(option, "info") == 0) {
        clear_vscreen();
        set_col(2); set_row(1);
        vprintf_custom("Los valores de la izquierda son la direcciones "
                "en donde empieza cada segmento, los de la derecha son los "
                "tamanos de los mismos.");
        set_col(2); set_row(3);
        for(i = 0; i < INFO_TABLE_SIZE; i++) {
            if( info[i].ptr != 0 ) {
                set_col(2);
                vprintf_custom("%x %d", info[i].ptr, info[i].size);
                newline();
                if( i > SCREEN_WIDTH - 3 ) {
                    set_col(20); set_row(3);
                }
            }
        }
        if (i == 0) {
            vprintf_custom("Aun no alocaste ninguna porcion de memoria.");
        }
    } else if( strcmp(option, "") == 0 ) {
        newline();
        vprintf_custom("Debes ingresar al menos una opcion para"
                " ser usada por esta funcion.");
    } else if(strcmp(option, "test") == 0) {
        malloc_tests(); 
        q_to_continue(SCREEN_LENGTH - 1, 2, 1);
    } else {
        newline();
        vprintf_custom("El comando que ingresaste no es valido.");
    }
    print_vscreen();

}
Пример #23
0
/***************************************************************
*   void malloc_tests
*      
*
****************************************************************/
void malloc_tests() {
    
    unsigned int row = 3;
    unsigned int col = 3;

    unsigned int size1 = 30000000;
    unsigned int* test_ptr1 = malloc_custom(size1, 0);
    set_row(row); set_col(col);
    vprintf_custom("1 Asked: %d, starts at: %x", size1, test_ptr1);
    set_row(row++); set_col(col + 40);
    vprintf_custom("mem left: %d", user_memory_size - allocated_space);

    unsigned int size2 = 1000;
    unsigned int* test_ptr2 = malloc_custom(size2, 0);
    set_row(row); set_col(col);
    vprintf_custom("2 Asked: %d, starts at: %x", size2, test_ptr2);
    set_row(row++); set_col(col + 40);
    vprintf_custom("mem left: %d", user_memory_size - allocated_space);

    unsigned int size3 = 0x00A00000; // 10MB
    unsigned int* test_ptr3 = malloc_custom(size3, 0);
    set_row(row); set_col(col);
    vprintf_custom("3 Asked: %d, starts at: %x", size3, test_ptr3);
    set_row(row++); set_col(col + 40);
    vprintf_custom("mem left: %d", user_memory_size - allocated_space);

    unsigned int size4 = 0x00A00000; // 10MB
    unsigned int* test_ptr4 = malloc_custom(size4, 0);
    set_row(row); set_col(col);
    vprintf_custom("4 Asked: %d, starts at: %x", size4, test_ptr4);
    set_row(row++); set_col(col + 40);
    vprintf_custom("mem left: %d", user_memory_size - allocated_space);

    unsigned int size5 = 0x00100000; // 1MB
    unsigned int* test_ptr5 = malloc_custom(size5, 1);
    set_row(row); set_col(col);
    vprintf_custom("5 Asked: %d, starts at: %x", size5, test_ptr5);
    set_row(row++); set_col(col + 40);
    vprintf_custom("mem left: %d", user_memory_size - allocated_space);

    unsigned int size6 = 0x00100000; // 1MB
    unsigned int* test_ptr6 = malloc_custom(size6, 0);
    set_row(row); set_col(col);
    vprintf_custom("6 Asked: %d, starts at: %x", size6, test_ptr6);
    set_row(row++); set_col(col + 40);
    vprintf_custom("mem left: %d", user_memory_size - allocated_space);

    unsigned int size7 = 0x00100000; // 1MB
    unsigned int* test_ptr7 = malloc_custom(size7, 0);
    set_row(row); set_col(col);
    vprintf_custom("7 Asked: %d, starts at: %x", size7, test_ptr7);
    set_row(row++); set_col(col + 40);
    vprintf_custom("mem left: %d", user_memory_size - allocated_space);

    unsigned int size8 = 0x00400000; // 4MB
    unsigned int* test_ptr8 = malloc_custom(size8, 0);
    set_row(row); set_col(col);
    vprintf_custom("8 Asked: %d, starts at: %x", size8, test_ptr8);
    set_row(row++); set_col(col + 40);
    vprintf_custom("mem left: %d", user_memory_size - allocated_space);

    unsigned int size9 = 0x00100000; // 64KB
    unsigned int* test_ptr9 = malloc_custom(size9, 0);
    set_row(row); set_col(col);
    vprintf_custom("9 Asked: %d, starts at: %x", size9, test_ptr9);
    set_row(row++); set_col(col + 40);
    vprintf_custom("mem left: %d", user_memory_size - allocated_space);

    unsigned int size10 = 0x00100000; // 64KB
    unsigned int* test_ptr10 = malloc_custom(size10, 0);
    set_row(row); set_col(col);
    vprintf_custom("10 Asked: %d, starts at: %x", size10, test_ptr10);
    set_row(row++); set_col(col + 40);
    vprintf_custom("mem left: %d", user_memory_size - allocated_space);

    unsigned int size11 = 0x00100000; // 64KB
    unsigned int* test_ptr11 = malloc_custom(size11, 0);
    set_row(row); set_col(col);
    vprintf_custom("11 Asked: %d, starts at: %x", size11, test_ptr11);
    set_row(row++); set_col(col + 40);
    vprintf_custom("mem left: %d", user_memory_size - allocated_space);

    free(test_ptr6);
    set_row(row); set_col(col);
    vprintf_custom("Released: %x (bytes)", size7);
    set_row(row++); set_col(col + 40);
    vprintf_custom("mem left: %d", user_memory_size - allocated_space);

    free(test_ptr7);
    set_row(row); set_col(col);
    vprintf_custom("Released: %x (bytes)", size7);
    set_row(row++); set_col(col + 40);
    vprintf_custom("mem left: %d", user_memory_size - allocated_space);

    test_ptr9 = malloc_custom(size9, 0);
    set_row(row); set_col(col);
    vprintf_custom("12 Asked: %d, starts at: %x", size9, test_ptr9);
    set_row(row++); set_col(col + 40);
    vprintf_custom("mem left: %d", user_memory_size - allocated_space);


    print_vscreen();
}
/**************************************************************************
    Main
***************************************************************************/
int main (void) 
{
	uint8_t color = UNIQUE_COLORS -1;
	uint8_t row = 0;
	uint8_t col = 0;
	uint8_t quad = 0;
	uint8_t binary_cnt = 0;
	uint8_t wdt_cnt = 0;
	uint8_t update_cnt = 0;
	
	initialize_AVR();

	SET_FLAG(SET_LEDS);
	chase_sequence = SMILEY;
	DISABLE_SERVOS();

	quad_flags = 0xFF;

	turn_off_matrices();

	// Turn On TWI
	TWI_RESET_WITH_ACK();


	/**********************************************
	 *	MAIN LOOP
	 *	- Handle Chase Sequences
	 **********************************************/
	for(;;)
	{
		//-------------------------
		// Handle Color Loops
		//-------------------------
		if (FLAG_IS_SET(INCREMENT_COLOR)) {
			if (++color == UNIQUE_COLORS)
				color = 1;
			CLEAR_FLAG(INCREMENT_COLOR);
		}
		else if (FLAG_IS_SET(DECREMENT_COLOR)) {
			if (--color == 0)
				color = UNIQUE_COLORS -1;
			CLEAR_FLAG(DECREMENT_COLOR);
		}

		//-------------------------
		// Reset Chase Sequence
		//-------------------------
		if (FLAG_IS_SET(RESET_CHASE)) {
			wdt_cnt = 0;
			chase_sequence = LOOP_QUAD;
			CLEAR_FLAG(RESET_CHASE);
			CLEAR_FLAG(PASSIVE_MODE);
			ENABLE_SERVOS();
		}

		//-------------------------
		// Handle Chase Sequences
		//-------------------------
		switch (chase_sequence) {

			//-------------------------
			// Constant On at the last color
			//-------------------------
			case ALL_CONSTANT:
				break;

			//-------------------------
			// Loop through all colors
			//-------------------------
			case LOOP_ALL:
				SET_FLAG(DECREMENT_COLOR);
				set_matrix(0, color);
				set_matrix(1, color);
				_delay_ms(100);
				break;
			
			//-------------------------
			// Color wheel - one color transistion per revolution
			//-------------------------
			case QUAD_WHEEL:
				if (quad == 0) {
					set_quadrant(0, 3, COL_BLACK);
					set_quadrant(1, 3, COL_BLACK);
				}
				else {
					set_quadrant(0, quad-1, COL_BLACK);
					set_quadrant(1, quad-1, COL_BLACK);
				}
				set_quadrant(0, quad, color);
				set_quadrant(1, quad, color);
				if (++quad == QUADS) {
					SET_FLAG(DECREMENT_COLOR);
					quad = 0;
				}
				_delay_ms(50);
				break;

			//-------------------------
			// Color wheel - change colors with quadrants
			//-------------------------
			case QUAD_WHEEL2:
				SET_FLAG(DECREMENT_COLOR);
				if (quad == 0) {
					set_quadrant(0, 3, COL_BLACK);
					set_quadrant(1, 3, COL_BLACK);
				}
				else {
					set_quadrant(0, quad-1, COL_BLACK);
					set_quadrant(1, quad-1, COL_BLACK);
				}
				set_quadrant(0, quad, color);
				set_quadrant(1, quad, color);
				if (++quad == QUADS) {
					quad = 0;
				}
				_delay_ms(50);
				
				break;

			//-------------------------
			// Loop through all colors in Quadrant(s)
			//-------------------------
			case LOOP_QUAD:
				SET_FLAG(DECREMENT_COLOR);
				set_quadrants(color);
				_delay_ms(100);
				break;

			//-------------------------
			// Binary Counter - by Columns
			//-------------------------
			case BINARY_COLS:
				for (col = 0; col < COLUMNS; ++col) {
					if (binary_cnt & _BV(col))
						set_column(0, col, COL_BLUE);
					else
						set_column(0, col, COL_BLACK);
				}
				++binary_cnt;
				_delay_ms(250);
				break;

			//-------------------------
			// Binary Counter - by Row
			//-------------------------
			case BINARY_ROWS:
				for (row = 0; row < ROWS; ++row) {
					if (binary_cnt & _BV(row))
						set_row(0, row, COL_RED);
					else
						set_row(0, row, COL_BLACK);
				}
				++binary_cnt;
				_delay_ms(250);
				break;

			//-------------------------
			// Display all colors
			//-------------------------
			case ALL_COLORS:
				if (FLAG_IS_SET(SET_LEDS)) {
					for (col = 0; col < COLUMNS; ++col) {
						for (row = 0; row < ROWS; ++row) {
							if (color < UNIQUE_COLORS) {
								set_led(0, col, row, color);
								++color;
							}
							else
								set_led(0, col, row, COL_BLACK);
						}
					}
					CLEAR_FLAG(SET_LEDS);
				}
				break;

			//-------------------------
			// Smiley Faces
			//-------------------------
			case SMILEY:
				if (FLAG_IS_SET(SET_LEDS)) {
					turn_off_matrices();

					// Border
					#define FACE_COLOR	COL_OLIVE
					set_row(0, 0, FACE_COLOR);
					set_row(0, 7, FACE_COLOR);
					set_column(0, 0, FACE_COLOR);
					set_column(0, 7, FACE_COLOR);

					set_row(1, 0, FACE_COLOR);
					set_row(1, 7, FACE_COLOR);
					set_column(1, 0, FACE_COLOR);
					set_column(1, 7, FACE_COLOR);

					// Eyes
					set_led(0, 1, 1, COL_WHITE);
					set_led(0, 1, 2, COL_WHITE);
					set_led(0, 2, 1, COL_WHITE);
					set_led(0, 2, 2, COL_BLUE);

					set_led(0, 1, 5, COL_WHITE);
					set_led(0, 1, 6, COL_WHITE);
					set_led(0, 2, 5, COL_WHITE);
					set_led(0, 2, 6, COL_BLUE);

					set_led(1, 1, 1, COL_WHITE);
					set_led(1, 1, 2, COL_WHITE);
					set_led(1, 2, 2, COL_WHITE);
					set_led(1, 2, 1, COL_GREEN);

					set_led(1, 1, 5, COL_WHITE);
					set_led(1, 1, 6, COL_WHITE);
					set_led(1, 2, 6, COL_WHITE);
					set_led(1, 2, 5, COL_GREEN);

					// Nose
					set_led(0, 3, 4, FACE_COLOR);
					set_led(0, 4, 3, FACE_COLOR);
					set_led(0, 4, 4, FACE_COLOR);

					set_led(1, 3, 3, FACE_COLOR);
					set_led(1, 4, 3, FACE_COLOR);
					set_led(1, 4, 4, FACE_COLOR);

					// Mouth
					set_led(0, 5, 1, COL_CORAL);
					set_led(0, 6, 2, COL_CORAL);
					set_led(0, 6, 3, COL_CORAL);
					set_led(0, 6, 4, COL_CORAL);
					set_led(0, 6, 5, COL_CORAL);
					set_led(0, 5, 6, COL_CORAL);

					set_led(1, 5, 1, COL_CORAL);
					set_led(1, 6, 2, COL_CORAL);
					set_led(1, 6, 3, COL_CORAL);
					set_led(1, 6, 4, COL_CORAL);
					set_led(1, 6, 5, COL_CORAL);
					set_led(1, 5, 6, COL_CORAL);
					CLEAR_FLAG(SET_LEDS);
					SET_FLAG(UPDATE_LEDS);
				}

					// Look back and forth
				if (FLAG_IS_SET(UPDATE_LEDS)) {
					set_led(0, 2, 2, COL_WHITE);
					set_led(0, 2, 1, COL_BLUE);
					set_led(0, 2, 6, COL_WHITE);
					set_led(0, 2, 5, COL_BLUE);
					set_led(1, 2, 1, COL_WHITE);
					set_led(1, 2, 2, COL_GREEN);
					set_led(1, 2, 5, COL_WHITE);
					set_led(1, 2, 6, COL_GREEN);
					_delay_ms(200);
					set_led(0, 2, 1, COL_WHITE);
					set_led(0, 2, 2, COL_BLUE);
					set_led(0, 2, 5, COL_WHITE);
					set_led(0, 2, 6, COL_BLUE);
					set_led(1, 2, 2, COL_WHITE);
					set_led(1, 2, 1, COL_GREEN);
					set_led(1, 2, 6, COL_WHITE);
					set_led(1, 2, 5, COL_GREEN);
					update_cnt = SMILEY_EYE_DELAY;
					CLEAR_FLAG(UPDATE_LEDS);
				}

				break;

			//-------------------------
			// Set matrix to white
			//-------------------------
			case ALL_WHITE:
				if (FLAG_IS_SET(SET_LEDS)) {
					set_matrix(0, COL_WHITE);
					CLEAR_FLAG(SET_LEDS);
				}
				break;

			//-------------------------
			// Turn off all LEDs
			//-------------------------
			case ALL_OFF:
			default:
				if (FLAG_IS_SET(SET_LEDS)) {
					turn_off_matrices();
					CLEAR_FLAG(SET_LEDS);
				}
				break;
			
			//-------------------------
			// Test - Test corner LEDs
			//-------------------------
			case TEST_CORNERS:
				set_led(0, 7, 0, COL_BLACK);
				set_led(0, 0, 0, COL_RED);
				set_led(0, 4, 4, COL_RED);
				set_led(1, 7, 7, COL_BLACK);
				set_led(1, 0, 7, COL_RED);
				set_led(1, 4, 3, COL_RED);
				_delay_ms(200);
				set_led(0, 0, 0, COL_BLACK);
				set_led(0, 0, 7, COL_BLUE);
				set_led(0, 4, 4, COL_BLUE);
				set_led(1, 0, 7, COL_BLACK);
				set_led(1, 0, 0, COL_BLUE);
				set_led(1, 4, 3, COL_BLUE);
				_delay_ms(200);
				set_led(0, 0, 7, COL_BLACK);
				set_led(0, 7, 7, COL_YELLOW);
				set_led(0, 4, 4, COL_YELLOW);
				set_led(1, 0, 0, COL_BLACK);
				set_led(1, 7, 0, COL_YELLOW);
				set_led(1, 4, 3, COL_YELLOW);
				_delay_ms(200);
				set_led(0, 7, 7, COL_BLACK);
				set_led(0, 7, 0, COL_GREEN);
				set_led(0, 4, 4, COL_GREEN);
				set_led(1, 7, 0, COL_BLACK);
				set_led(1, 7, 7, COL_GREEN);
				set_led(1, 4, 3, COL_GREEN);
				_delay_ms(200);
				break;
		}

		//-------------------------
		// Update Timer - 10ms increments
		//-------------------------
		if (update_cnt > 0) {
			_delay_ms(10);
			if (--update_cnt == 0) {
				SET_FLAG(UPDATE_LEDS);
			}
		}


		//-------------------------
		// WatchDog Timer
		//-------------------------
		if (wdt_cnt < WDT_MAX) {
			if (++wdt_cnt == WDT_MAX) {
				DISABLE_SERVOS();
				SET_FLAG(SET_LEDS);
				SET_FLAG(PASSIVE_MODE);
				chase_sequence = SMILEY;
			}
		}
		

	}	// End of Main Loop
}	// End of Main
Пример #25
0
void init(void)
{
	for(uint8_t i = 0; i < 8; i++) {
		set_row(i, i, 0, 7, MAX_INTENSITY);
	}
}
Пример #26
0
/*
 * This program demonstrates the Cdk matrix widget.
 */
int main (int argc, char **argv)
{
   /* Declare local variables. */
   CDKSCREEN *cdkscreen     = 0;
   CDKMATRIX *form_prov    = 0;
   WINDOW *cursesWin        = 0;
   char *title          = 0;
   int rows         = 5;
   int cols         = 1;
   int vrows            = 5;
   int vcols            = 1;
   char *coltitle[10], *rowtitle[10], *mesg[10];
   int colwidth[10], colvalue[10];

 //  CDK_PARAMS params;

 //  CDKparseParams (argc, argv, &params, CDK_MIN_PARAMS);

   /* Set up CDK. */
   cursesWin = initscr();
   cdkscreen = initCDKScreen (cursesWin);

   /* Start CDK Colors. */
   initCDKColor();

   /* Create the horizontal and vertical matrix labels. */
#define set_col(n, width, string) \
   coltitle[n] = string;   colwidth[n] = width ; colvalue[n] = vUMIXED

   set_col(1, 7, "</B/5>Proveedor");
   set_col(2, 7, "</B/33>Lec 1");
   set_col(3, 7, "</B/33>Lec 2");
   set_col(4, 7, "</B/33>Lec 3");
   set_col(5, 1, "</B/7>Flag");

#define set_row(n, string) \
   rowtitle[n] = "</B/8>" string

   set_row(1, "ID");
   set_row(2, "Nombre");
   set_row(3, "Apellido");
   set_row(4, "Correo");
   set_row(5, "Direccion");
   set_row(6, "Course 6");
   set_row(7, "Course 7");
   set_row(8, "Course 8");

   /* Create the title. */
   /* Create the matrix object. */
   form_prov = newCDKMatrix (cdkscreen,
                   CENTER,
                   CENTER,
                  rows, cols, vrows, vcols,
                  title, rowtitle, coltitle,
                  colwidth, colvalue,
                  -1, -1, '.',
                  COL, TRUE,
                  TRUE,
                   FALSE);

   /* Check to see if the matrix is null. */
   if (form_prov == 0)
   {
      /* Clean up. */
      destroyCDKScreen (cdkscreen);
      endCDK();

      /* Print out a little message. */
      printf ("Oops. Can't seem to create the matrix widget. Is the window too small ?\n");
      exit (EXIT_FAILURE);
   }

   /* Activate the matrix. */
   activateCDKMatrix (form_prov, 0);

   /* Check if the user hit escape or not. */
   if (form_prov->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>You hit escape. No information passed back.";
      mesg[1] = "",
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 3);
   }
   else if (form_prov->exitType == vNORMAL)
   {
      char temp[80];

      sprintf(temp, "Current cell (%d,%d)", form_prov->crow, form_prov->ccol);
      mesg[0] = "<L>You exited the matrix normally.";
      mesg[1] = temp;
      mesg[2] = "<L>To get the contents of the matrix cell, you can";
      mesg[3] = "<L>use getCDKMatrixCell():";
      mesg[4] = getCDKMatrixCell(form_prov, form_prov->crow, form_prov->ccol);
      mesg[5] = "";
      mesg[6] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 7);
   }

   /* Clean up. */
   destroyCDKMatrix (form_prov);
   destroyCDKScreen (cdkscreen);
   endCDK();
   exit (EXIT_SUCCESS);
}
Пример #27
0
/**
  \brief Rozklada se na LDU soucin
  \return Rozlozena matice ldu
  \param[in,out] LDU - matice do ktere bude zapsan ldu soucin
  \todo Predelat aby se matice LDU vytvorila zde a nemusela vytvaret externe - vytvor MTX copy(MTX)
*/
void MTX::make_ldu(MTX& LDU)
{
    LDU.value_number_orig = LDU.value_number;
    LDU.na = LDU.ns = LDU.nm = LDU.nd = 0;
    long j=0;//chodi po ridkem, prave vytvarenem, radku
    long ac; //Actual column/index
    double d=0;  // Diagonalni prvek aktualniho radku

//    double l;  // Hodnota l pri nasobeni radku - jen pro prehlednost
//    ROW u; //nacte se z LDU

#ifdef LDU_VEKTOR
    VTR_SPARSE ldu(LDU.column_number);//radek, ktery se nacte z matice a na konci upravy zapise do LDU

    for(long i=0; i<LDU.row_number; i++){//pres radky
//        if(i%1000==0)
            printf("\nJe zpracovavan radek: %li",i);

        LDU.set_vtr_sparse(i,ldu);
//        printf("\n\nRADEK PO NACTENI:\n");
//        ldu.print_full();

        ac = ldu.get_first_ac();

//        try{
            while(ac<i && ac!=-2){//VYTVOR CAST L
                LDU.update_ldu_row(ac, ldu);
                ldu.get_next_ac(ac);
            }
//        }catch(...){
//            std::cerr<<"Chyba: cast L";
//            throw;
//        }

        //JSI NA DIAGONALNIM PRVKU
        d = ldu.values[i]; //PREDELAT

        //VYTVOR CAST U
        if(ac != -2)
            ldu.get_next_ac(ac);

        try{
            while(ac != -2 /*|| ac < (ldu.value_number)*/){
                ldu.values[ac] /= d;
                ldu.get_next_ac(ac);
            }
        }catch(...){
            std::cerr<<"Chyba: cast U";
            throw;
        }

        LDU.nd += ldu.value_number-j;//POCET OPERACI
        LDU.set_row(ldu,i);
//        printf("RADEK PO ROZLOZENI:\n");
//        ldu.print_full();

//        LDU.print_full_mtx();
        //======================
//        //SPOCTI POCTY OPERACI
//        LDU.nd++;
//        LDU.nm++;
////            LDU.nm += u.value_number;

#else
    ROW ldu;//radek, ktery se nacte z matice a na konci upravy zapise do LDU // PRO ROW::

    for(long i=0; i<LDU.row_number; i++){//pres radky
        std::cout<<"\nJe zpracovavan radek: " << i<<std::endl;

        ldu = get_row(i); // PRO ROW::
//        ldu.print_full();
        j = 0;

        ac = ldu.index[j];
        while(ac<i){//VYTVOR CAST L

            //PUVODNI METODA
//            l = ldu.values[j] /= LDU.get_diagonal(ac);
//
//            u = LDU.get_row(ac,ac+1);
//            d = LDU.get_diagonal(ac);
//            ldu += u*(-l*d);
//            j++;
            //===============

            //NOVY ZPUSOB - NEVYTVARI ROW "U"
            LDU.update_ldu_row(ac, j, ldu);
            j++;
            ac = ldu.index[j];
//            ldu.print_full();
            //===============

            //======================
            //SPOCTI POCTY OPERACI
            LDU.nd++;
            LDU.nm++;
//            LDU.nm += u.value_number;
        }

        //JSI NA DIAGONALNIM PRVKU
        d = ldu.values[j];
        j++;

        //VYTVOR CAST U

        LDU.nd += ldu.value_number-j;//POCET OPERACI

        while(j<ldu.value_number){
            ldu.values[j] /= d;
            j++;
            //======================
            //SPOCTI POCTY OPERACI
        }
//        ldu.print_full();
        LDU.set_row(ldu,i);
#endif
    }
}



// ==============================================================================
/**
  \brief Nacte cast L z matice A
 */
void MTX::get_mtx_L(MTX& A)
{
    long i,j;
    ROW r;
    initialize(A.get_row_number(),A.get_column_number(),A.get_values_number());

    for(i=0;i<A.get_row_number();i++){
        j=0;
        r = A.get_row(i,0);

        while(r.index[j] < i)
            j++;
        r.values[j]=1;//nastav diagonalu
        r.value_number= ++j;//zkrat radek at se zbytek neopisuje

        set_row(r,i);
    }
}