Exemple #1
0
void handle_init(AppContextRef ctx) {
    (void)ctx;

    window_init(&window, "Demo");
    window_stack_push(&window, true /* Animated */);

    resource_init_current_app(&FUZZYZEIT_RESOURCES);

    custom_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_MPC_32));
    custom_font2 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_MPBC_32));

    window_set_background_color(&window, GColorBlack);
    graphics_context_set_text_color(ctx, GColorWhite);

    text_layer_init(&min_layer, GRect(4, 35, 144 /* width */, 50 /* height */));
    text_layer_set_text_color(&min_layer, GColorWhite);
    text_layer_set_text(&min_layer, "");
    text_layer_set_font(&min_layer, custom_font);
    text_layer_set_background_color(&min_layer, GColorClear);

    layer_add_child(&window.layer, &min_layer.layer);
    layer_mark_dirty(&min_layer.layer);

    text_layer_init(&hour_layer, GRect(4, 80, 144 /* width */, 50 /* height */));
    text_layer_set_text_color(&hour_layer, GColorWhite);
    text_layer_set_text(&hour_layer, "");
    text_layer_set_font(&hour_layer, custom_font2);
    text_layer_set_background_color(&hour_layer, GColorClear);

    layer_add_child(&window.layer, &hour_layer.layer);
    layer_mark_dirty(&hour_layer.layer);

    update_layer(ctx);

}
static DFBResult
sh_du_add_region( CoreLayer             *layer,
                  void                  *driver_data,
                  void                  *layer_data,
                  void                  *region_data,
                  CoreLayerRegionConfig *config )
{
     SHGfxDriverData *drv;
     SHDuLayerData   *lyr;
     DFBResult        ret;

     D_DEBUG_AT( SH_DU_LAYER, "%s( %u )\n",
                 __FUNCTION__, dfb_layer_id( layer ) );
     D_UNUSED_P( region_data );

     drv = (SHGfxDriverData *)driver_data;
     lyr = (SHDuLayerData *)layer_data;

     init_layer( drv, lyr, dfb_layer_id( layer ), config );
     ret = update_layer( drv, lyr, PLANE_ALL, NULL );
     if (ret == DFB_OK)
          ret = sh_du_add_layer( dfb_layer_screen( layer ), driver_data,
	                         lyr->id, lyr->plane.id, &lyr->level );

     return ret;
}
Exemple #3
0
void update(TYPE weights[][MAX_ROWS][MAX_COLS],
        TYPE *input,
        TYPE activations[][MAX_ROWS]){
    int i;

    //initialize first activation layer to be the inputs to the nnet..
    u_1 : for(i = 0; i < layer_size[0]; i++){
        activations[0][i] = input[i];
    }

    //iterate over each weight layer...
    u_2 : for(i = 0; i < NUM_LAYERS - 1; i++){
        update_layer(layer_size[i], layer_size[i + 1], weights[i], activations[i], activations[i + 1]);
    }
}
static DFBResult
sh_du_flip_region( CoreLayer             *layer,
                   void                  *driver_data,
                   void                  *layer_data,
                   void                  *region_data,
                   CoreSurface           *surface,
                   DFBSurfaceFlipFlags    flags,
                   CoreSurfaceBufferLock *left_lock,
                   CoreSurfaceBufferLock *right_lock )
{
     DFBResult        ret;
     SHGfxDriverData *drv;
     SHDuLayerData   *lyr;
 
     D_DEBUG_AT( SH_DU_LAYER, "%s( %u, 0x%x, 0x%lx )\n",
                 __FUNCTION__, dfb_layer_id( layer ), flags, left_lock->phys );
     D_UNUSED_P( region_data );
     D_UNUSED_P( right_lock );

     ret = DFB_OK;
     drv = (SHGfxDriverData *)driver_data;
     lyr = (SHDuLayerData *)layer_data;

     if (D_FLAGS_IS_SET( flags, DSFLIP_ONSYNC ))
          ret = dfb_layer_wait_vsync( layer );

     if (ret)
          goto out;

     D_ASSERT( lyr->plane.pa0 != left_lock->phys );
     lyr->plane.pa0 = left_lock->phys;
     ret = update_layer( drv, lyr, PLANE_PA0, NULL );
     if (ret)
          goto out;

     if (D_FLAGS_IS_SET( flags, DSFLIP_WAIT ))
          ret = dfb_layer_wait_vsync( layer );

     dfb_surface_flip( surface, false );

     if (ret)
          goto out;

     ret = sh_du_show_layer( dfb_layer_screen( layer ), driver_data, lyr->id );

out:
     return ret;
}
Exemple #5
0
void handle_init(AppContextRef ctx) {
  (void)ctx;

  window_init(&window, "MyWatchfaceByTobi");
  window_stack_push(&window, true /* Animated */);
	
	 resource_init_current_app(&APP_RESOURCES);

    custom_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_CHECKBOOK_32));
    custom_font2 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_ANGRY_32));
	custom_font3 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DATE_JEN_20));

    window_set_background_color(&window, GColorBlack);
    graphics_context_set_text_color(ctx, GColorWhite);

    text_layer_init(&min_layer, GRect(4, 45, 144 /* width */, 50 /* height */));
    text_layer_set_text_color(&min_layer, GColorWhite);
    text_layer_set_text(&min_layer, "");
    text_layer_set_font(&min_layer, custom_font);
    text_layer_set_background_color(&min_layer, GColorClear);
	/*text_layer_set_size(&min_layer, );*/

    layer_add_child(&window.layer, &min_layer.layer);
    layer_mark_dirty(&min_layer.layer);

    text_layer_init(&hour_layer, GRect(4, 80, 144 /* width */, 50 /* height */));
    text_layer_set_text_color(&hour_layer, GColorWhite);
    text_layer_set_text(&hour_layer, "");
    text_layer_set_font(&hour_layer, custom_font2);
	/*text_layer_set_size(&hour_layer, const GSize max_size);*/
    text_layer_set_background_color(&hour_layer, GColorClear);

    layer_add_child(&window.layer, &hour_layer.layer);
    layer_mark_dirty(&hour_layer.layer);
	
	text_layer_init(&date_layer, GRect(4, 0, 144 /* width */, 35 /* height */));
    text_layer_set_text_color(&date_layer, GColorWhite);
    text_layer_set_text(&date_layer, "");
    text_layer_set_font(&date_layer, custom_font3);
    text_layer_set_background_color(&date_layer, GColorClear);	
	layer_add_child(&window.layer, &date_layer.layer);
    layer_mark_dirty(&date_layer.layer);

    update_layer(ctx);
}
Exemple #6
0
void stop_winding (void)
{
	char buf[8];

	stop_motor();
	update_command(); 
    if (action==INACTIVE) return;  // als we wikkelen zonder power aan op relays
    if (turns_done==0) {
		action=INACTIVE;
		return;
	} 
	
	if (action==WIND_LEFT) { strcat (layer,"L");}
	if (action==WIND_RIGHT) { strcat (layer,"R");}
	if (action==FILL) { strcat (layer,"F");}
	action=INACTIVE;
	itoa(turns_done,buf,10);
	strcat(layer,buf);
	update_layer();
}
static DFBResult
sh_du_update_region( CoreLayer             *layer,
                     void                  *driver_data,
                     void                  *layer_data,
                     void                  *region_data,
                     CoreSurface           *surface,
                     const DFBRegion       *left_update,
                     CoreSurfaceBufferLock *left_lock,
                     const DFBRegion       *right_update,
                     CoreSurfaceBufferLock *right_lock )
{
     DFBResult             ret;
     SHGfxDriverData      *drv;
     SHDuLayerData        *lyr;
 
     D_DEBUG_AT( SH_DU_LAYER, "%s( %u, 0x%lx )\n",
                 __FUNCTION__, dfb_layer_id( layer ), left_lock->phys );
     D_UNUSED_P( region_data );
     D_UNUSED_P( left_update );
     D_UNUSED_P( right_lock );
     D_UNUSED_P( right_update );

     drv = (SHGfxDriverData *)driver_data;
     lyr = (SHDuLayerData *)layer_data;
     
     if (lyr->plane.pa0 != left_lock->phys) {
          lyr->plane.pa0 = left_lock->phys;
          ret = update_layer( drv, lyr, PLANE_PA0, NULL );
          if (ret)
               goto out;
     }

     ret = sh_du_show_layer( dfb_layer_screen( layer ), driver_data, lyr->id );

out:
     return ret;
}
Exemple #8
0
void handle_minute_tick(AppContextRef ctx, PebbleTickEvent *tE) {
    (void)ctx;
    update_layer(ctx);
}
Exemple #9
0
int main(void)
{
	uint8_t i;
	
		  
#ifdef DEBUG
	uart_init();
	uart_puts ("\r\nreset\r\ninit port 1\r\n");	
#endif
	
	//
/*
	uart_puts ("a123\n");
	uart_puts ("b456\n");
	uart_puts ("c789\n");
	uart_puts ("d20\n");
*/	
	init_keypad_4x4s (P_PORTC);
	init_count_switch();
    init_timer ();

	lcd_setup (0, P_PA2, P_PA4, P_PA6, P_PA0,
			  P_PA1, P_PA3, P_PA5, P_PA7);	 

 //lcd_setup  (uint8_t chip,  uint8_t strobe, uint8_t clock, uint8_t io)
	lcd_setup_info (0, HD44780, 20, 2);
	
	lcd_init (0, LCD_DISP_ON);

  // relays
		//	sh_cp:11 (geel)    st_cp:12(paars)    ds:14(wit)
	//void hc595_setup (uint8_t chip, uint8_t clk, uint8_t cs, uint8_t data)

	DDRD|=P_BIT7 | P_BIT6 | P_BIT5 | P_BIT4;
#ifdef DEBUG
    test_relais();
#endif


	c=0;
	prevc=0;
	num=0;
	turns_done=0;
	turns_prog=0;	
	total_turns_done=0;
	for (i=0; i<80; i++) layer[i]=0;
	stop_motor();
	set_wind_dir_none();

	lcd_clrscr(0);
	lcd_puts (0,"*    Winding controller 20140114");
	lcd_gotoxy(0,39,0);
	lcd_puts (0,"*");
	lcd_gotoxy(0,0,3);
	lcd_puts (0,"*");
	lcd_gotoxy(0,39,3);
	lcd_puts (0,"*");
	lcd_gotoxy(0,2,2);
	lcd_printf(0,"Free RAM:%d b",freeRam());
	sleep(1);


	lcd_clrscr(0);
	update_info ();
    update_command();
	update_num ();
	update_speed ();
	update_turns();

	for (;;) {

		c=keypad_w_getch();

		if (c!=prevc)  {
			/*a=PINC;
			uart_printf ("%x %x %d\r\n",a,c,num); */
			prevc=c;

			if ((action==FILL) || (action==WIND_LEFT) || (action==WIND_RIGHT)) {
				switch (c) {
					case 0x0c: 	stop_winding();
								action=INACTIVE; //dubbel maar extra voor readability
							   	break;
				}
			}  // if !INACTIVE

			if (action==HELP) {

			switch (c) {
					case 0x0f: 	if (helppage<MAX_HELPPAGES) helppage++;
								show_help();
							   	break;
					case 0x0e: 	if (helppage>0) helppage--;
								show_help();
							   	break;
					case 0x0c: 	action=INACTIVE;
								lcd_clrscr(0);
							   	break;
					}
			}  // if HELP

			if (action==CORR) {
			switch (c) {  //corrmode is wat we de *vorige* keer gedaan hebben
					char buf[10];

					case 0x0c: 	turns_done=turns_before_corr;
								total_turns_done=total_turns_done_before_corr;
								action=INACTIVE;
								break;
					case 0x0e: 	turns_done=turns_before_corr;
								total_turns_done=total_turns_done_before_corr;
								if (corrmode==SUB) {
									turns_done+=corr;
									total_turns_done+=corr;
									corrmode=ADD;
									break;
								}
								if (corrmode==ADD) {
									if (turns_done>=corr) {
											turns_done-=corr;
											total_turns_done-=corr;
									}
									corrmode=SUB;
								}
								break;
					case 0x0f: 	turns_done=0;
							 	total_turns_done=0;
								turns_before_corr=0;
								total_turns_done_before_corr=0;
								action=INACTIVE;
								break;
			   		case 0xff:
			   		case 0xfd:
			   		case 0xfe: break;
					default:
								num=0;
								action=INACTIVE;
								itoa(corr,buf,10);
								if (corrmode==SUB) strcat(layer,"+");
								if (corrmode==ADD) strcat(layer,"+");
 								strcat (layer,buf);
								update_layer();
								break;
					}
    				update_command();
					update_turns();
							 
			}


			if (action==INACTIVE) {
				switch (c) {
					case 0x0a: 	wind_left();
								turns_prog=num;
								num=0;
								break;
					case 0x0b:  wind_right ();	
								turns_prog=num;
								num=0;
								break;
					case 0x0d:  fill ();	
								turns_prog=num;
								num=0;
								break;
					case 0x0c: 	num=0;					   
								stop_motor();
							   	break;
					case 0x0e: 	corr=num;
								turns_before_corr=turns_done;
								if (turns_done>=corr) turns_done-=corr;
								action=CORR;
								corrmode=SUB;
							   	break;
					case 0x0f:  helppage=0;
								show_help();
								action=HELP;
								break;
			   		case 0xff:
			   		case 0xfd:
			   		case 0xfe: break;

					default: if (num<1000)  {
							num=num*10 + c;						
							update_num();
							update_speed();
						}
				}
				if (action!=HELP)  {
    				update_command();
					update_turns();
					update_num();
					update_speed();
				}
			  } // if INACTIVE

		
			} // if c==prevc
	}  // mainloop
	
 return 0;
}
static DFBResult
sh_du_set_region( CoreLayer                  *layer,
                  void                       *driver_data,
                  void                       *layer_data,
                  void                       *region_data,
                  CoreLayerRegionConfig      *config,
                  CoreLayerRegionConfigFlags  updated,
                  CoreSurface                *surface,
                  CorePalette                *palette,
                  CoreSurfaceBufferLock      *left_lock,
                  CoreSurfaceBufferLock      *right_lock )
{
     DFBResult        ret;
     SHGfxDriverData *drv;
     SHDuLayerData   *lyr;
     u32             *pal, dirty;

     D_DEBUG_AT( SH_DU_LAYER, "%s( %u, 0x%x, 0x%lx )\n",
                 __FUNCTION__, dfb_layer_id( layer ), updated,
                 D_FLAGS_IS_SET( updated, CLRCF_SURFACE ) ?
                 left_lock->phys : 0 );
     D_UNUSED_P( region_data );
     D_UNUSED_P( surface );
     D_UNUSED_P( right_lock );

     drv   = (SHGfxDriverData *)driver_data;
     lyr   = (SHDuLayerData *)layer_data;
     pal   = NULL;
     dirty = 0u;

     /* color palette */
     if (D_FLAGS_IS_SET( updated, CLRCF_PALETTE ) && palette) {
          unsigned int i;

          if (palette->num_entries > 256)
               return DFB_UNSUPPORTED;

          pal = malloc(256 * sizeof(u32));
          if (!pal)
               return DFB_NOSYSTEMMEMORY;

          for (i = 0; i < palette->num_entries; i++)
               pal[i] = SH_DU_COLOR_TO_PALETTE(palette->entries[i]);
          while (i < 256)
               pal[i++] = 0u;
     }

     /* buffer address and stride */
     if (D_FLAGS_IS_SET( updated, CLRCF_SURFACE )) {
          u32 stride;

          stride  = (u32)(left_lock->pitch * 8);
          stride /= DFB_BITS_PER_PIXEL( left_lock->buffer->format );
          if (lyr->plane.stride != stride) {
               lyr->plane.stride = stride;
               SH_DU_PLANE_SET_DIRTY( dirty, STRIDE );
          }
          if (lyr->plane.pa0 != left_lock->phys) {
               lyr->plane.pa0 = left_lock->phys;
               SH_DU_PLANE_SET_DIRTY( dirty, PA0 );
          }
     }

     /* area */
     if (D_FLAGS_IS_SET( updated, CLRCF_WIDTH |
                                  CLRCF_HEIGHT |
                                  CLRCF_SOURCE |
                                  CLRCF_DEST )) {
          u32 sx, sy, dx, dy, w, h;

          if (D_FLAGS_IS_SET( updated, CLRCF_WIDTH )) {
               D_ASSERT( config->width > 0 );
               lyr->width = config->width;
          }
          if (D_FLAGS_IS_SET( updated, CLRCF_HEIGHT )) {
               D_ASSERT( config->height > 0 );
               lyr->height = config->height;
          }
          if (D_FLAGS_IS_SET( updated, CLRCF_SOURCE )) {
               D_ASSERT( config->source.x >= 0 );
               D_ASSERT( config->source.y >= 0 );
               lyr->sx = config->source.x;
               lyr->sy = config->source.y;
          }
          if (D_FLAGS_IS_SET( updated, CLRCF_DEST )) {
               lyr->dx = config->dest.x;
               lyr->dy = config->dest.y;
          }
          if (lyr->dx >= 0) {
               w  = (u32)lyr->width;
               sx = (u32)lyr->sx;
               dx = (u32)lyr->dx;
          }
          else {
               w  = (lyr->width + lyr->dx) <= 0 ?
                    0u : (u32)(lyr->width + lyr->dx);
               sx = (u32)(lyr->sx - lyr->dx);
               dx = 0u;
          }
          if (lyr->dy >= 0) {
               h  = (u32)lyr->height;
               sy = (u32)lyr->sy;
               dy = (u32)lyr->dy;
          }
          else {
               h  = (lyr->height + lyr->dy) <= 0 ?
                    0u : (u32)(lyr->height + lyr->dy);
               sy = (u32)(lyr->sy - lyr->dy);
               dy = 0u;
          }
          if (lyr->plane.width != w) {
               lyr->plane.width = w;
               SH_DU_PLANE_SET_DIRTY( dirty, WIDTH );
          }
          if (lyr->plane.height != h) {
               lyr->plane.height = h;
               SH_DU_PLANE_SET_DIRTY( dirty, HEIGHT );
          }
          if (lyr->plane.sx != sx) {
               lyr->plane.sx = sx;
               SH_DU_PLANE_SET_DIRTY( dirty, SX );
          }
          if (lyr->plane.sy != sy) {
               lyr->plane.sy = sy;
               SH_DU_PLANE_SET_DIRTY( dirty, SY );
          }
          if (lyr->plane.dx != dx) {
               lyr->plane.dx = dx;
               SH_DU_PLANE_SET_DIRTY( dirty, DX );
          }
          if (lyr->plane.dy != dy) {
               lyr->plane.dy = dy;
               SH_DU_PLANE_SET_DIRTY( dirty, DY );
          }
     }

     /* mode and opacity */
     if (D_FLAGS_IS_SET( updated, CLRCF_FORMAT |
                                  CLRCF_OPTIONS |
                                  CLRCF_OPACITY )) {
          u32 mode, opacity;

          mode    = lyr->plane.mode;
          opacity = lyr->plane.opacity;

          if (D_FLAGS_IS_SET( updated, CLRCF_OPACITY ))
	       lyr->opacity = config->opacity;

          if (D_FLAGS_IS_SET( updated, CLRCF_OPTIONS )) {
               if (D_FLAGS_IS_SET( config->options, DLOP_ALPHACHANNEL )) {
                    D_FLAGS_SET( mode, SH_DU_PMR_BLEND );
                    D_FLAGS_CLEAR( opacity, SH_DU_PALPHAR_ABIT_IGNORE );
                    D_FLAGS_SET( opacity, SH_DU_PALPHAR_PALETTE );
               }
               else if (D_FLAGS_IS_SET( config->options, DLOP_OPACITY )) {
                    D_FLAGS_SET( mode, SH_DU_PMR_BLEND );
                    D_FLAGS_SET( opacity, SH_DU_PALPHAR_ABIT_IGNORE );
                    D_FLAGS_CLEAR( opacity, SH_DU_PALPHAR_PALETTE );
               }
               else {
                    D_FLAGS_CLEAR( mode, SH_DU_PMR_BLEND );
               }
               if (D_FLAGS_IS_SET( config->options, DLOP_SRC_COLORKEY ))
                    D_FLAGS_CLEAR( mode, SH_DU_PMR_NOSRCKEY );
               else
                    D_FLAGS_SET( mode, SH_DU_PMR_NOSRCKEY );
          }

          if (D_FLAGS_IS_SET( updated, CLRCF_FORMAT )) {
               mode &= ~SH_DU_PMR_DDF_MASK;
               switch (config->format) {
               case DSPF_RGB16:
                    mode |= SH_DU_PMR_DDF565;
                    break;
               case DSPF_ARGB1555:
                    mode |= SH_DU_PMR_DDF1555;
                    break;
               default:
                    D_ASSERT( config->format == DSPF_LUT8 );
                    mode |= SH_DU_PMR_DDF8;
                    break;
               }
          }

          if (D_FLAGS_IS_SET( mode, SH_DU_PMR_BLEND )) {
	       if (D_FLAGS_IS_SET( opacity, SH_DU_PALPHAR_PALETTE ))
                    /* pixel alpha blending */
	            opacity |= SH_DU_PALPHAR_ALPHA_MASK;
	       else /* const alpha blending */
	            opacity = (opacity & ~SH_DU_PALPHAR_ALPHA_MASK) |
                              (u32)lyr->opacity;
          }
          if (lyr->plane.opacity != opacity) {
               lyr->plane.opacity = opacity;
               SH_DU_PLANE_SET_DIRTY( dirty, OPACITY );
          }
          if (lyr->plane.mode != mode) {
               lyr->plane.mode = mode;
               SH_DU_PLANE_SET_DIRTY( dirty, MODE );
          }
     }

     /* src color key */
     if (D_FLAGS_IS_SET( updated, CLRCF_SRCKEY ))
          lyr->ckey = config->src_key;
     if (D_FLAGS_IS_SET( updated, CLRCF_SRCKEY | CLRCF_FORMAT )) {
          u32 ddf, ckey;

          ddf = lyr->plane.mode & SH_DU_PMR_DDF_MASK;
          if (ddf == SH_DU_PMR_DDF8) {
               ckey = (u32)lyr->ckey.index;
               if (lyr->plane.ckey8 != ckey) {
                    lyr->plane.ckey8 = ckey;
                    SH_DU_PLANE_SET_DIRTY( dirty, CKEY8 );
               }
          }
          else {
               ckey = (ddf == SH_DU_PMR_DDF565) ?
                      SH_DU_COLORKEY_TO_RGB565( lyr->ckey ) :
                      SH_DU_COLORKEY_TO_ARGB1555( lyr->ckey );
               if (lyr->plane.ckey16 != ckey) {
                    lyr->plane.ckey16 = ckey;
                    SH_DU_PLANE_SET_DIRTY( dirty, CKEY16 );
               }
          }
     }

     ret = (dirty || pal) ? update_layer( drv, lyr, dirty, pal ) : DFB_OK;
     if (pal)
          free( pal );

     return ret;
}