static void game_logic() {
    // Per-frame game logic here
    if(get_current_state() == STATE_SPLASH) {
        psleep(MENUPSLEEPTIME); // Trying to save the battery!
    } else if(get_current_state() == STATE_SHOWMAINMENU) {
        main_menu_create();
    } else if(get_current_state() == STATE_MARATHON) {
        race_reset_cars();
        race_set_difficulty(DIFFICULTY);
        track_set_length(14000);
        main_menu_destroy();
        switch_on_light(50000);
        set_current_state(STATE_BEFORERACE);
    } else if(get_current_state() == STATE_SPRINT) {
        race_reset_cars();
        race_set_difficulty(DIFFICULTY);
        track_set_length(7000);        
        main_menu_destroy();
        switch_on_light(35000);
        set_current_state(STATE_BEFORERACE);
    } else if(get_current_state() == STATE_BEFORERACE) {
        race_result_create_position_layers();
        race_place_cars_on_grid();
        race_set_start_time();
        set_current_state(STATE_RACING);
    } else if(get_current_state() == STATE_RACING) {
        race_frame_update();
    } else if(get_current_state() == STATE_AFTERRESULTS) {
        psleep(MENUPSLEEPTIME); // Trying to save the battery!
    } else if(get_current_state() == STATE_QUITTING) {
        APP_LOG(APP_LOG_LEVEL_DEBUG, "!!!   QUITTING from horizontalboost !!!!");        
        window_stack_pop(false); 
    }
}
Example #2
0
File: tty.c Project: aralbrec/FUZIX
void tty_putc_wait(uint8_t minor, unsigned char c)
{
        uint8_t t;
#ifdef CONFIG_DEV_PTY
	if (minor >= PTY_OFFSET)
		ptty_putc_wait(minor, c);
	else
#endif
        /* For slower platforms it's not worth the task switching and return
           costs versus waiting a bit. A box with tx interrupts and sufficient
           performance can buffer or sleep in tty_putc instead.

           The driver should return a value from the ttyready_t enum:
            1 (TTY_READY_NOW) -- send bytes now
            0 (TTY_READY_SOON) -- spinning may be useful
           -1 (TTY_READY_LATER) -- blocked, don't spin (eg flow controlled) */
	if (!udata.u_ininterrupt) {
		while ((t = tty_writeready(minor)) != TTY_READY_NOW)
			if (t != TTY_READY_SOON || need_resched()){
				irqflags_t irq = di();
				tty_sleeping(minor);
				psleep(&ttydata[minor]);
				irqrestore(irq);
			}
	}
	tty_putc(minor, c);
}
Example #3
0
int
tty_read(int16 minor, int16 rawflag)
{
	int nread;

	nread = 0;
	while (nread < udata.u_count) {
		for (;;) {
			di();
			if (remq(&ttyinq, udata.u_base))
				break;
			psleep(&ttyinq);
			/* XXX - messy */
			if (udata.u_cursig || udata.u_ptab->p_pending) {
				udata.u_error = EINTR;
				return (-1);
			}
		}
		ei();   
		if ((nread++ == 0) && (*udata.u_base == '\004'))	/* ^D */
			return (0);
		if (*udata.u_base == '\n')
			break;
		++udata.u_base;
	} 
	return (nread);
}
Example #4
0
int
tty_write(int16 minor, int16 rawflag)
{
	int towrite;

	towrite = udata.u_count;

	while (udata.u_count-- != 0) {
		/* Wait on the ^S/^Q flag. */
		for (;;) {
			di();
			ifnot (stopflag)    
				break;
			psleep(&stopflag);
			/* XXX - messy */
			if (udata.u_cursig || udata.u_ptab->p_pending) {
				udata.u_error = EINTR;
				return (-1);
			}
		}
		ei();   
		ifnot (flshflag) {
			if (*udata.u_base == '\n')
				_putc('\r');
			_putc(*udata.u_base);
		}
		++udata.u_base;
	}
	return (towrite);
}
Example #5
0
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
	
  // Read first item
  Tuple *t = dict_read_first(iterator);

  text_layer_set_text( title_layer, title );
	
  // For all items
  while(t != NULL) {
    // Which key was received?
		APP_LOG(APP_LOG_LEVEL_DEBUG, "Loop index now %s", t->value->cstring);
    switch(t->key) {
    case KEY_ABSTRACT:
          snprintf(abstract, sizeof(abstract), "%s", t->value->cstring);			
      break;
    case KEY_TITLE:
          snprintf(title, sizeof(title), "%s", t->value->cstring);
      break;
    default:
      snprintf( title, sizeof(abstract), "%s", t->value->cstring );
      break;
    }
		text_layer_set_text( word_layer, abstract );// Look for next item
    app_timer_register( (200+10*( strlen(abstract) )), (AppTimerCallback) refresh, NULL);
    
		psleep(500);
    t = dict_read_next(iterator);
  }
  window_stack_pop(true);  
}
Example #6
0
static void chug_timer_timeout(void)
{
    static char s_buffer[16];
    static uint32_t chug_count = 0;
    chug_count++;
    //Extract the digits to the left of the DP
    uint16_t count_sec = chug_count/1000;
    //Find digits to left of DP
    uint16_t count_ms = chug_count % 1000;
    //3 digit precision before and after DP
    snprintf(s_buffer, sizeof(s_buffer), " Time:\n%3d:%3d", count_sec, count_ms);
    text_layer_set_text(s_count_layer, s_buffer);
    if(state == RUN_CLOCK)
        app_timer_register(1, (AppTimerCallback) chug_timer_timeout, NULL);
    else
    {
        if (NULL != s_count_layer)
        {

            text_layer_destroy(s_count_layer);
            s_count_layer = NULL;
        }
        //Reset counter, display final time for 3s before repainting welcome screen
        psleep(1500);
        welcome_window_build(s_main_window);

    }

}
Example #7
0
arg_t _waitpid(void)
{
	ptptr p;
	int retval;

	if (statloc && !valaddr((char *) statloc, sizeof(int))) {
		udata.u_error = EFAULT;
		return (-1);
	}

	/* FIXME: move this scan into the main loop and also error
	   on a complete loop finding no matchi for pid */
	/* See if we have any children. */
	for (p = ptab; p < ptab_end; ++p) {
		if (p->p_status && p->p_pptr == udata.u_ptab
		    && p != udata.u_ptab)
			goto ok;
	}
	udata.u_error = ECHILD;
	return (-1);
      ok:
	if (pid == 0)
		pid = -udata.u_ptab->p_pgrp;
	/* Search for an exited child; */
	for (;;) {
		chksigs();
		if (udata.u_cursig) {
			udata.u_error = EINTR;
			return -1;
		}
		for (p = ptab; p < ptab_end; ++p) {
			if (p->p_status == P_ZOMBIE
			    && p->p_pptr == udata.u_ptab) {
				if (pid == -1 || p->p_pid == pid
				    || p->p_pgrp == -pid) {
					if (statloc)
						uputw(p->p_exitval,
						      statloc);

					retval = p->p_pid;
					p->p_status = P_EMPTY;

					/* Add in child's time info.  It was stored on top */
					/* of p_priority in the childs process table entry. */
					udata.u_cutime += ((clock_t *)p->p_priority)[0];
					udata.u_cstime += ((clock_t *)p->p_priority)[1];
					return retval;
				}
			}
		}
		/* Nothing yet, so wait */
		if (options & WNOHANG)
			break;
		psleep(udata.u_ptab);
	}
	udata.u_error = EINTR;
	return -1;
}
Example #8
0
File: process.c Project: 8l/FUZIX
/* This sees if the current process has any signals set, and handles them.
 */
void chksigs(void)
{
	uint8_t j;
	uint32_t pending = udata.u_ptab->p_pending & ~udata.u_ptab->p_held;
	int (**svec)(int) = &udata.u_sigvec[0];
	uint32_t m;

	/* Fast path - no signals pending means no work
	   Also don't do signal processing if we are in P_STOPPED. This
	   isn't quite right but will paper over the holes for the moment
	   FIXME */
	if (!pending || udata.u_ptab->p_status == P_STOPPED)
		return;

	/* Dispatch the lowest numbered signal */
	for (j = 1; j < NSIGS; ++j) {
		svec++;
		m = sigmask(j);
		if (!(m & pending))
			continue;
	        /* SIGSTOP can't be ignored and puts the process into
	           P_STOPPED state when it is ready to handle the signal.
	           Annoyingly right now we have to context switch to the task
	           in order to stop it in the right place. That would be nice
	           to fix */
	        if (j == SIGSTOP || j == SIGTTIN || j == SIGTTOU) {
			udata.u_ptab->p_status = P_STOPPED;
			udata.u_ptab->p_event = j;
			psleep(NULL);
                }
		/* This is more complex than in V7 - we have multiple
		   behaviours (plus the unimplemented as yet core dump) */
		if (*svec == SIG_DFL) {
			/* SIGCONT is subtle - we woke the process to handle
			   the signal so ignoring here works fine */
			if (j == SIGCHLD || j == SIGURG || j == SIGSTOP ||
                            j == SIGTTIN || j == SIGTTOU ||
			    j == SIGIO || j == SIGCONT || udata.u_ptab->p_pid == 1) {
				udata.u_ptab->p_pending &= ~m;	// unset the bit
				continue;
			}
			/* FIXME: core dump on some signals */
#ifdef DEBUG
			kprintf("process terminated by signal %d\n", j);
#endif
                        doexit(dump_core(j));
		} else if (*svec != SIG_IGN) {
			/* Arrange to call the user routine at return */
			udata.u_ptab->p_pending &= ~m;	// unset the bit
#ifdef DEBUG
			kprintf("about to process signal %d\n", j);
#endif
			udata.u_cursig = j;
			break;
		}
	}
}
Example #9
0
void select_click_callback(MenuLayer *menu_layer, MenuIndex *cell_index, void *callback_context)
{
	  int which = cell_index->row;
 
    //The array that will hold the on/off vibration times
    uint32_t segments[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 
    //Build the pattern (milliseconds on and off in alternating positions)
    for(int i = 0; i < which + 1; i++)
    {
        segments[2 * i] = 200;
        segments[(2 * i) + 1] = 100;
    }
 
    //Create a VibePattern data structure
    VibePattern pattern = {
        .durations = segments,
        .num_segments = 16
    };
 
    //Do the vibration pattern!
    vibes_enqueue_custom_pattern(pattern);
  
    psleep( 1000 );
  

    // create window to show
    word_window = window_create(); 
    window_set_window_handlers(word_window, (WindowHandlers) {
       .load = word_window_load,
       .unload = word_window_unload,
    });
    window_stack_push(word_window, true);  
    // create window to show
  
		
    app_message_register_inbox_received(inbox_received_callback);
    app_message_register_inbox_dropped(inbox_dropped_callback);
    app_message_register_outbox_failed(outbox_failed_callback);
    app_message_register_outbox_sent(outbox_sent_callback);		
		//APP_LOG(APP_LOG_LEVEL_DEBUG, "Loop index now %d", 1);

		// Open AppMessage
		app_message_open( app_message_inbox_size_maximum(), app_message_outbox_size_maximum() );
	
		// Begin dictionary
  	DictionaryIterator *iter;
  	app_message_outbox_begin(&iter);

  	// Add a key-value pair
  	dict_write_uint8(iter, 0, 0);

  	// Send the message!
  	app_message_outbox_send();

}
Example #10
0
void tick_handler(struct tm *tick_time, TimeUnits units_changed)
{
        //Format the buffer string using tick_time as the time source
        strftime(buffer, sizeof("00:00"), "%H:%M", tick_time);
        
        //Change the TextLayer text to show the new time!
        text_layer_set_text(time_layer, buffer);
	
		psleep(500); // 500ms sleep to wait for JS to be ready.
		update();	
}
Example #11
0
File: tty.c Project: jfernand/FUZIX
void tty_putc_wait(uint8_t minor, unsigned char c)
{
#ifdef CONFIG_DEV_PTY
	if (minor >= PTY_OFFSET)
		ptty_putc_wait(minor, c);
	else
#endif
	if (!udata.u_ininterrupt) {
		while (!tty_writeready(minor))
			psleep(&ttydata[minor]);
	}
	tty_putc(minor, c);
}
Example #12
0
int psleep_flags(void *p, unsigned char flags)
{
	if (flags & O_NDELAY) {
		udata.u_error = EAGAIN;
		return -1;
	}
	psleep(p);
	if (chksigs()) {
                udata.u_error = EINTR;
		return -1;
	}
	return 0;
}
Example #13
0
void * send_activity_message(void * p_data)
{
    SocketYS* s = (SocketYS*) p_data;
    char buffer[8];
    packtheader(4,17, buffer);
    while (1)
    {
        psleep (30);
        s->sends(buffer, 8);
    }

    return NULL;
}
Example #14
0
void PClock::tick()
{
    puint32 thisFrameTime = pTimeGetCurrentTimestamp();
    puint32 deltaTime = thisFrameTime - m_timestamp;
    deltaTime = deltaTime < 1? 1 : deltaTime; // at least 1 ms
    m_timestamp = thisFrameTime;
    
    if (!m_paused)
    {
    #if defined (P_WIN32) && defined (P_DEBUG)
        if (!isFpsControlEnabled() && deltaTime > P_MILLISECONDS_PER_FRAME)
        {
            // The application is in the debug mode and we are stepping through
            // the application, so the interval between two frames might be 
            // abnormally large. In this case, we need to trim the large delta
            // time to normal one for 
            deltaTime = P_MILLISECONDS_PER_FRAME;
        }
    #endif

        // We use the approximate average of last n frames to predicate the delta time
        // for next frame.
        // The larger n is, the faster animation will be after resume in a short while.
        const puint32 n = 4;
        pfloat32 elapsedNumFrames = (pfloat32)pMin(m_playedFrames, n - 1);
        m_systemDeltaTime = (m_systemDeltaTime * elapsedNumFrames + (pfloat32)deltaTime) / 
            (elapsedNumFrames + 1.0f);

        m_systemCurrentTime += m_systemDeltaTime;
        // The awake time is the real time invested in rendering and computation.
        pfloat32 awakeTime = m_systemDeltaTime - m_lastSleepingTime;
        
        if (isFpsControlEnabled() && awakeTime < m_minMSPerFrame)
        {
            // Note that the FPS control is upon the system frame/delta time
            // rather than the scaled one. The former is a measurement of frame
            // rate while the latter is that of the application/game speed.
            pfloat32 sleepingTime = m_minMSPerFrame - awakeTime;
            m_lastSleepingTime = sleepingTime;
            psleep(sleepingTime);
        }

        m_deltaTime = m_systemDeltaTime * m_scaling;

        m_currentTime += m_deltaTime;

        m_elapsedFrames++;
        m_playedFrames++;
    }
}
Example #15
0
/* Fonction pour les threads des clients. */
static void * fn_clients (void * p_data){
   int nb = (int) p_data;

   while (1){
      int val = get_random (6);
      psleep (get_random (3));
      store.stock = store.stock - val;
      printf (
         "Client %d prend %d du stock, reste %d en stock !\n",
         nb, val, store.stock
      );
   }
   return NULL;
}
Example #16
0
static void accel_tap_handler(AccelAxisType axis, int32_t direction) {
    accel_data_service_unsubscribe();
    vibes_short_pulse();
    psleep(2000);
    accel_data_service_subscribe(1, accel_handler);
    accel_service_set_sampling_rate(ACCEL_SAMPLING_10HZ);
    pause = 1;
    accel_tap_service_unsubscribe();
    text_layer_set_text(text_layer_2, "RUNNING");
    text_layer_set_text(text_layer_3, "");
    action_bar_layer_set_icon(s_action_bar, BUTTON_ID_SELECT, s_icon_pause);   
    start_time = time(NULL);
    app_timer_register(10000, endtrial_callback, (void*)start_time);
}
Example #17
0
arg_t _pause(void)
{
	/* 0 is a traditional "pause", n is a timeout for doing
	   sleep etc without ugly alarm hacks */
	if (t)
		udata.u_ptab->p_timeout = t + 1;
	psleep(0);
	/* Were we interrupted ? */
	if (!t || udata.u_ptab->p_timeout > 1) {
		udata.u_error = EINTR;
		/* Our timeout is automatically cleared on syscall exit */
		return (-1);
	}
	return 0;
}
void
ThreadFactory::execute() {

    assert(cb && "thread execute: invalid function pointer");

    unsigned int cnt = 0;

    sleep = (unsigned int) (interval * 1000);

    while (run) {
        psleep(sleep);

        cb(0, 0, cnt++, NULL);
    }
pout.putf("Goodbye from ThreadFactory \n");
}
static void select_click_handler(ClickRecognizerRef recognizer, void *context){
  // invert the current opt from black background white text to
  text_layer_set_background_color(s_num_text_layer_ary[cur_opt], GColorWhite);
  text_layer_set_text_color(s_num_text_layer_ary[cur_opt], GColorBlack);

  cur_opt = (prm_lcl->opt_fptr_ary[cur_opt](NULL)).next_opt_i; // move to the next opt

  // if have reached the final opt, then give the data to the finish function
  if(cur_opt == 4){
    window_stack_remove(s_enter_num_window, false);
    psleep(100); // wait a bit for the OS to reset the window pointers
    (prm_lcl->opt_fptr_ary[3])(cur_num); // this is the final finishing function
  }else{
    // invert the current opt from white background black text
    text_layer_set_background_color(s_num_text_layer_ary[cur_opt], GColorBlack);
    text_layer_set_text_color(s_num_text_layer_ary[cur_opt], GColorWhite);
  }
}
Example #20
0
File: devio.c Project: 8l/FUZIX
int psleep_flags_io(void *p, unsigned char flags, usize_t *n)
{
	if (flags & O_NDELAY) {
	        if (!*n) {
	                *n = (usize_t)-1;
			udata.u_error = EAGAIN;
                }
		return -1;
	}
	psleep(p);
	if (udata.u_cursig || udata.u_ptab->p_pending) {	/* messy */
	        if (!*n) {
	                *n = (usize_t)-1;
                        udata.u_error = EINTR;
                }
		return -1;
	}
	return 0;
}
Example #21
0
int psleep_flags_io(void *p, unsigned char flags)
{
	if (flags & O_NDELAY) {
	        if (!udata.u_done) {
	                udata.u_done = (usize_t)-1;
			udata.u_error = EAGAIN;
                }
		return -1;
	}
	psleep(p);
	if (chksigs()) {
	        if (!udata.u_done) {
	                udata.u_done = (usize_t)-1;
                        udata.u_error = EINTR;
                }
		return -1;
	}
	return 0;
}
Example #22
0
/* clients thread */
static void *fn_clients(void *p_data)
{
	int nb = (int)p_data;

	while (1)
	{
		int val = get_random(6);
		psleep(get_random(3));
		pthread_mutex_lock(&store.mutex_stock);
		if (val > store.stock)
		{
			pthread_cond_signal(&store.cond_stock);
			pthread_cond_wait(&store.cond_clients, &store.mutex_stock);
		}
		store.stock = store.stock - val;
		printf("Client %d prend %d du stock, reste, %d en stock!\n",
				nb, val, store.stock);
		pthread_mutex_unlock(&store.mutex_stock);
	}
	return NULL;
}
Example #23
0
int main(void) {
  window = window_create();
  window_stack_push(window, true /* Animated */ );
  //accel_data_service_subscribe(0, handle_accel);//subscribe to the accel service
  window_set_click_config_provider(window, click_config_provider);
  psleep(1000);
  
  accel_tap_service_subscribe(&accel_tap_handler);
  
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_frame(window_layer);
  text_layer = text_layer_create(bounds);
  char str[30];
  snprintf(str, 30, "Pebble Butt");
  text_layer_set_text(text_layer, str);
  text_layer_set_font(text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
  text_layer_set_text_alignment(text_layer, GTextAlignmentCenter);
  layer_add_child(window_layer, text_layer_get_layer(text_layer));
  app_event_loop();  
  //destructor of the main func
  accel_tap_service_unsubscribe();
  text_layer_destroy(text_layer);
  window_destroy(window);
}
Example #24
0
static void next_animation() {
  // Determine start and finish positions
  Layer *window_layer = window_get_root_layer(s_main_window);
  GRect bounds = layer_get_frame(window_layer);
  
  GRect start, finish;
  
  int i_Kreis = layer_get_frame(window_layer).size.w / 5;
  APP_LOG(APP_LOG_LEVEL_INFO, "i_Kreis: %d", i_Kreis);
  int i_X = 0;
  int i_Y = 0;
  int i_X_alt = 0;
  int i_Y_alt = 0;
  
  int i_delay = ANIM_DELAY;
  int i_duration = ANIM_DURATION;
  
  switch (s_current_stage) {
    case 0:
      
      APP_LOG(APP_LOG_LEVEL_INFO, "Animation Schritt: %d", 0);
      i_delay = ANIM_FIRST_DELAY;
      
      //Layer positionieren
      layer_set_frame(bitmap_layer_get_layer(s_bgbox_layer), GRect(bounds.size.w+1, 0, bounds.size.w, bounds.size.h));
      
      //Layer sichtbarkeit anpassen
      layer_set_hidden(s_box2_layer, true);
      layer_set_hidden(s_bg_layer, true);
      layer_set_hidden(bitmap_layer_get_layer(s_bgbox_layer), true);
      layer_set_hidden(bitmap_layer_get_layer(s_logo_layer), true);
      layer_set_hidden(text_layer_get_layer(s_date_layer), true);
      layer_set_hidden(text_layer_get_layer(s_time_layer), true);

      //"Alt"-Koordinaten ermitteln
      i_X_alt = - BOX_SIZE;  
      i_Y_alt = (bounds.size.h - BOX_SIZE)/2;
      
      //Neue Koordinaten
      i_X = 0;
      i_Y = i_Y_alt;
        
      //Animationskoordinaten setzen
      start = GRect(i_X_alt, i_Y_alt, BOX_SIZE, BOX_SIZE);
      finish = GRect(i_X, i_Y, BOX_SIZE, BOX_SIZE);
      
      //Animationsebene sichtbar machen
      layer_set_hidden(s_box_layer, false);
      break;

    case 1:

      APP_LOG(APP_LOG_LEVEL_INFO, "Animation Schritt: 1");

      //"Alt"-Koordinaten ermitteln
      i_X_alt = 0;  
      i_Y_alt = (bounds.size.h - BOX_SIZE)/2;
      
      //Neue Koordinaten
      i_X = i_Kreis;
      i_Y = i_Y_alt;
        
      //Animationskoordinaten setzen
      start = GRect(i_X_alt, i_Y_alt, BOX_SIZE, BOX_SIZE);
      finish = GRect(i_X, i_Y, BOX_SIZE, BOX_SIZE);

      //Kreiskopie positionieren
      layer_set_frame(s_box2_layer, start);

      //Kreiskopie sichtbar machen
      layer_set_hidden(s_box2_layer, false);
      break;

    case 2:

      APP_LOG(APP_LOG_LEVEL_INFO, "Animation Schritt: 2");

      //"Alt"-Koordinaten ermitteln
      i_X_alt = i_Kreis;  
      i_Y_alt = (bounds.size.h - BOX_SIZE)/2;
      
      //Neue Koordinaten
      i_X = i_Kreis*2;
      i_Y = i_Y_alt;
        
      //Animationskoordinaten setzen
      start = GRect(i_X_alt, i_Y_alt, BOX_SIZE, BOX_SIZE);
      finish = GRect(i_X, i_Y, BOX_SIZE, BOX_SIZE);

      //Kreiskopie positionieren
      layer_set_frame(s_box2_layer, start);

      break;

    case 3:

      APP_LOG(APP_LOG_LEVEL_INFO, "Animation Schritt: 3");

      //Layer sichtbarkeit anpassen
      layer_set_hidden(s_box2_layer, true);

      //"Alt"-Koordinaten ermitteln
      i_X_alt = i_Kreis*2;  
      i_Y_alt = (bounds.size.h - BOX_SIZE)/2;
      
      //Neue Koordinaten
      i_X = i_Kreis*3;
      i_Y = i_Y_alt;
        
      //Animationskoordinaten setzen
      start = GRect(i_X_alt, i_Y_alt, BOX_SIZE, BOX_SIZE);
      finish = GRect(i_X, i_Y, BOX_SIZE, BOX_SIZE);

      //Kreiskopie positionieren
      layer_set_frame(s_box2_layer, start);

      //Kreiskopie sichtbar machen
      layer_set_hidden(s_box2_layer, false);
      break;

    case 4:

      APP_LOG(APP_LOG_LEVEL_INFO, "Animation Schritt: 4");

      //Layer sichtbarkeit anpassen
      layer_set_hidden(s_box2_layer, true);

      //"Alt"-Koordinaten ermitteln
      i_X_alt = i_Kreis*3;  
      i_Y_alt = (bounds.size.h - BOX_SIZE)/2;
      
      //Neue Koordinaten
      i_X = i_Kreis*4;
      i_Y = i_Y_alt;
        
      //Animationskoordinaten setzen
      start = GRect(i_X_alt, i_Y_alt, BOX_SIZE, BOX_SIZE);
      finish = GRect(i_X, i_Y, BOX_SIZE, BOX_SIZE);

      //Kreiskopie positionieren
      layer_set_frame(s_box2_layer, start);

      //Kreiskopie sichtbar machen
      layer_set_hidden(s_box2_layer, false);
      break;

    case 5:

      APP_LOG(APP_LOG_LEVEL_INFO, "Animation Schritt: 5");

      //Layer sichtbarkeit anpassen
      layer_set_hidden(s_box2_layer, true);

      //"Alt"-Koordinaten ermitteln
      i_X_alt = i_Kreis*4;  
      i_Y_alt = (bounds.size.h - BOX_SIZE)/2;
      
      //Neue Koordinaten
      i_X = bounds.size.h;
      i_Y = i_Y_alt;
        
      //Animationskoordinaten setzen
      start = GRect(i_X_alt, i_Y_alt, BOX_SIZE, BOX_SIZE);
      finish = GRect(i_X, i_Y, BOX_SIZE, BOX_SIZE);

      //Kreiskopie positionieren
      layer_set_frame(s_box2_layer, start);

      //Kreiskopie sichtbar machen
      layer_set_hidden(s_box2_layer, false);
      break;

    
    case 6:
      APP_LOG(APP_LOG_LEVEL_INFO, "Animation Schritt: 6");
  
      i_duration = ANIM_DURATION * 2;
    
      //Kreise ausblenden
      layer_set_hidden(s_box_layer, true);
      layer_set_hidden(s_box2_layer, true);
      layer_set_frame(s_box_layer, GRect(-BOX_SIZE,(bounds.size.h - BOX_SIZE)/2, BOX_SIZE, BOX_SIZE));
      layer_set_frame(s_box2_layer, GRect(-BOX_SIZE,(bounds.size.h - BOX_SIZE)/2, BOX_SIZE, BOX_SIZE));
    
      //Animations_Layer einbelnden
      layer_set_hidden(bitmap_layer_get_layer(s_bgbox_layer), false);

      //"Alt"-Koordinaten ermitteln
      i_X_alt = bounds.size.w+1;  
      i_Y_alt = 0;
      
      //Neue Koordinaten
      i_X = -1;
      i_Y = 0;
       
      //Animationskoordinaten setzen
      start = GRect(i_X_alt, i_Y_alt, bounds.size.w, bounds.size.h);
      finish = GRect(i_X, i_Y, bounds.size.w, bounds.size.h);
      break;
    
    case 7:
      APP_LOG(APP_LOG_LEVEL_INFO, "Animation Schritt: 7");

      layer_set_hidden(bitmap_layer_get_layer(s_bgbox_layer), true);
      layer_set_hidden(text_layer_get_layer(s_date_layer), false);
      layer_set_hidden(text_layer_get_layer(s_time_layer), false);
      psleep(200);
      layer_set_hidden(s_bg_layer, false);
      layer_set_hidden(bitmap_layer_get_layer(s_logo_layer), false);
      break;

    default:
      APP_LOG(APP_LOG_LEVEL_INFO, "Animation Schritt: default");

      start = GRect(-BOX_SIZE, (bounds.size.h - BOX_SIZE)/2 , BOX_SIZE, BOX_SIZE);
      finish = GRect(-BOX_SIZE, (bounds.size.h - BOX_SIZE)/2 , BOX_SIZE, BOX_SIZE);
      break;
  }

  APP_LOG(APP_LOG_LEVEL_INFO, "Animation von X=%d nach X=%d", i_X_alt, i_X);

  if (s_current_stage < ANI_STEPS){
    // Schedule the next animation
    switch (s_current_stage) {
      case 0-5:
        s_box_animation = property_animation_create_layer_frame(s_box_layer, &start, &finish);
        animation_set_curve((Animation*)s_box_animation, AnimationCurveLinear);
        break;
      
      case 6:
        s_box_animation = property_animation_create_layer_frame(bitmap_layer_get_layer(s_bgbox_layer), &start, &finish); 
        animation_set_curve((Animation*)s_box_animation, AnimationCurveEaseOut);
      break;
      
      default:
        s_box_animation = property_animation_create_layer_frame(s_box_layer, &start, &finish);
        break;
    }
    
    animation_set_duration((Animation*)s_box_animation, i_duration);
    animation_set_delay((Animation*)s_box_animation, i_delay);
    animation_set_handlers((Animation*)s_box_animation, (AnimationHandlers) {
      .stopped = anim_stopped_handler
    }, NULL);
    
    //Animation starten
    animation_schedule((Animation*)s_box_animation); 
    
    //Step erhöhen
    s_current_stage = (s_current_stage + 1);

  } else {
void overlay_loop()
{
	slothSock sock;
	bool discon = false;

	std::string cid;
	std::wstring clientname;
	std::vector<std::wstring> name_list;
	std::vector<bool> talking_list;
	std::vector<std::string> schandlerid;

	while(true)
	{
		while(pause)
		{
			psleep(200);
		}
		//clear vectors
		name_list.clear();
		talking_list.clear();
		schandlerid.clear();

		if(get_TS3_enabled())
		{
			//blog(LOG_WARNING, "connect");
			if(connect(sock, discon) == 0)
			{
				//blog(LOG_WARNING, "authorise");
				if(authorise(sock, discon) == 0)
				{
					if(discon)
					{
						discon = false;
					}
					//Get Channel client list and talking state
					//blog(LOG_WARNING, "get_cid");
					if(get_cid(sock, cid) == 0)
					{
						//blog(LOG_WARNING, "get_channelclientlist");
						get_channelclientlist(sock, cid, name_list, talking_list);
						//names = name_list;
						//talking = talking_list;
					}
					//get own name
					//blog(LOG_WARNING, "get_schandlerid");
					if(get_schandlerid(sock, schandlerid) == 0)
					{
						//blog(LOG_WARNING, "notifyregister");
						if(notifyregister(sock, schandlerid[0]) == 0)
						{
							//blog(LOG_WARNING, "clientname_from_uid");
							clientname_from_uid(sock, clientname);
							own_name = clientname;
						}
					}
				}
				sock.closeConnection();
			}
		}
		names = name_list;
		talking = talking_list;
		psleep(200);
	}
	return;
}
Example #26
0
int main(void) {
    int i,addr;

    for(addr=DUMP_START; addr < DUMP_END; addr += BATCH_SIZE)
    {
        memset(data, 0, BATCH_SIZE);
        int bytes_left = DUMP_END - addr;
        int step_bytes = bytes_left < BATCH_SIZE ? bytes_left : BATCH_SIZE;

        APP_LOG(APP_LOG_LEVEL_DEBUG, "Dumping %d bytes from offset 0x%X", step_bytes, addr);
        // Enable GPIOA, SPI1
        RCC->APB2ENR |= (uint32_t)(1<<12);
        RCC->AHB1ENR |= (uint32_t)(1<<0);
        // Reset SPI1
        RCC->APB2RSTR |= (uint32_t)(1<<12);
        RCC->APB2RSTR &= ~(uint32_t)(1<<12);

        // Clear CS line
        GPIOA->BSRRL = (1<<4);
        GPIOA->BSRRH = (1<<4);

        // Initialize SPI
        SPI1->CR1 = 0;
        SPI1->CR1 |= 0x304;
        SPI1->I2SCFGR = 0;
        SPI1->CRCPR = 0x7;
        SPI1->CR2 = 0;

        // SPE=1
        SPI1->CR1 |= 0x40;

        for(i=0; i < step_bytes; i++)
        {
            if(i % 256 == 0)
            {
                int tmpaddr = addr + i;
                GPIOA->BSRRL = (1<<4);
                GPIOA->BSRRH = (1<<4);

                SendData(0x3); // Read command
                // Address to read from
                SendData((tmpaddr & 0xFF0000) >> 16);
                SendData((tmpaddr & 0x00FF00) >> 8);
                SendData((tmpaddr & 0x0000FF));
            }
            data[i] = SendData(0xa9);
        }

        /* Disable SPI before sending log messages.
         * This is required because sending logs appear to maybe cause writes to the SPI storage
         * and pebble crashes if SPI is somehow active and running when this happens */
        GPIOA->BSRRL = (1<<4);
        RCC->AHB1ENR &= ~(uint32_t)(1<<0);
        RCC->APB2ENR &= ~(uint32_t)(1<<12);

        for(i=0; i < step_bytes; i+=32)
        {
            APP_LOG(APP_LOG_LEVEL_DEBUG,
                    "0x%08X: %02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X"
                    "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X"
                    "%02X%02X%02X%02X%02X%02X",
                addr+i,
                data[i], data[i+1], data[i+2], data[i+3],
                data[i+4], data[i+5], data[i+6], data[i+7],
                data[i+8], data[i+9], data[i+10], data[i+11],
                data[i+12], data[i+13], data[i+14], data[i+15],
                data[i+16], data[i+17], data[i+18], data[i+19],
                data[i+20], data[i+21], data[i+22], data[i+23],
                data[i+24], data[i+25], data[i+26], data[i+27],
                data[i+28], data[i+29], data[i+30], data[i+31]);
        }
        // Needed to ensure all the log messages are sent before we start filling the buffer again
        psleep(1000);
    }
Example #27
0
void pebble_mutex_acquire(volatile unsigned char* lock)
{
  while(!mutex_acquire(lock))
    psleep(0); // or sleep 1?
}
Example #28
0
arg_t _open(void)
{
	int8_t uindex;
	int8_t oftindex;
	staticfast inoptr ino;
	int16_t perm;
	staticfast inoptr parent;
	char fname[FILENAME_LEN + 1];
	int trunc;
	int r;
	int w;
	int j;

	parent = NULLINODE;

	trunc = flag & O_TRUNC;
	r = (flag + 1) & 1;
	w = (flag + 1) & 2;

	if (O_ACCMODE(flag) == 3 || (flag & O_BADBITS)) {
		udata.u_error = EINVAL;
		return (-1);
	}
	if ((uindex = uf_alloc()) == -1)
		return (-1);

	if ((oftindex = oft_alloc()) == -1)
		goto nooft;

	ino = n_open(name, &parent);
	if (ino) {
		i_deref(parent);
		/* O_EXCL test */
		if ((flag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) {
			udata.u_error = EEXIST;
			goto idrop;
		}
	} else {
		/* The n_open failed */
		if (udata.u_error == EFAULT)
			goto cantopen;
		/* New file */
		if (!(flag & O_CREAT)) {
			udata.u_error = ENOENT;
			goto cantopen;
		}
		filename(name, fname);
		/* newfile drops parent for us */
		if (parent && (ino = newfile(parent, fname))) {
			ino->c_node.i_mode =
			    (F_REG | (mode & MODE_MASK & ~udata.u_mask));
			setftime(ino, A_TIME | M_TIME | C_TIME);
			wr_inode(ino);
		} else {
			udata.u_error = ENFILE;	/* FIXME, should be set in newfile
						   not bodged to a guessed code */
			goto cantopen;
		}
	}
	/* Book our slot in case we block opening a device */
	of_tab[oftindex].o_inode = ino;

	perm = getperm(ino);
	if ((r && !(perm & OTH_RD)) || (w && !(perm & OTH_WR))) {
		udata.u_error = EACCES;
		goto cantopen;
	}
	if (w) {
		if (getmode(ino) == F_DIR ) {
			udata.u_error = EISDIR;
			goto cantopen;
		}
		if (ino->c_flags & CRDONLY) {
			udata.u_error = EROFS;
			goto cantopen;
		}
	}

	if (isdevice(ino)) {
		inoptr *iptr = &of_tab[oftindex].o_inode;
		/* d_open may block and thus ino may become invalid as may
		   parent (but we don't need it again). It may also be changed
		   by the call to dev_openi */

		if (dev_openi(iptr, flag) != 0)
			goto cantopen;

		/* May have changed */
		/* get the static pointer back in case it changed via dev 
		   usage or just because we blocked */
		ino = *iptr;
	}

	if (trunc && getmode(ino) == F_REG) {
		if (f_trunc(ino))
			goto idrop;
		for (j = 0; j < OFTSIZE; ++j)
			/* Arguably should fix at read/write */
			if (of_tab[j].o_inode == ino)
				of_tab[j].o_ptr = 0;
	}

	udata.u_files[uindex] = oftindex;

	of_tab[oftindex].o_ptr = 0;
	of_tab[oftindex].o_access = flag;	/* Save the low bits only */
	if (flag & O_CLOEXEC)
		udata.u_cloexec |= (1 << oftindex);
	/* FIXME: ATIME ? */

/*
 *         Sleep process if no writer or reader
 */
	if (getmode(ino) == F_PIPE && of_tab[oftindex].o_refs == 1
	    && !(flag & O_NDELAY))
		psleep(ino);

        /* From the moment of the psleep ino is invalid */

	return (uindex);
      idrop:
	i_deref(ino);
      cantopen:
	oft_deref(oftindex);	/* This will call i_deref() */
      nooft:
	udata.u_files[uindex] = NO_FILE;
	return (-1);
}
Example #29
0
void platform_input_wait(void)
{
    psleep(&kqueue);	/* We wake this on timers so it works for sticks */
}