TouchCalibrationView::TouchCalibrationView(
	NavigationView& nav
) : nav { nav },
	calibration { touch::default_calibration() }
{
	add_children({
		&image_calibrate_0,
		&image_calibrate_1,
		&image_calibrate_2,
		&image_verify_0,
		&image_verify_1,
		&image_verify_2,
		&label_calibrate,
		&label_verify,
		&label_success,
		&label_failure,
		&button_cancel,
		&button_ok,
	});

	button_cancel.on_select = [this](Button&){ this->on_cancel(); };
	button_ok.on_select = [this](Button&){ this->on_ok(); };

	set_phase(Phase::Calibrate0);
}
void TouchCalibrationView::on_ok() {
	if( phase == Phase::Success ) {
		persistent_memory::set_touch_calibration(calibration);
		nav.pop();
	}
	if( phase == Phase::Failure ) {
		set_phase(Phase::Calibrate0);
	}
}
Ejemplo n.º 3
0
static RefList *read_stream_reflections_2_1(FILE *fh)
{
	char *rval = NULL;
	int first = 1;
	RefList *out;

	out = reflist_new();

	do {

		char line[1024];
		signed int h, k, l;
		float intensity, sigma, fs, ss;
		char phs[1024];
		int cts;
		int r;
		Reflection *refl;

		rval = fgets(line, 1023, fh);
		if ( rval == NULL ) continue;
		chomp(line);

		if ( strcmp(line, REFLECTION_END_MARKER) == 0 ) return out;

		r = sscanf(line, "%i %i %i %f %s %f %i %f %f",
		           &h, &k, &l, &intensity, phs, &sigma, &cts, &fs, &ss);
		if ( (r != 9) && (!first) ) {
			reflist_free(out);
			return NULL;
		}

		first = 0;
		if ( r == 9 ) {

			double ph;
			char *v;

			refl = add_refl(out, h, k, l);
			set_intensity(refl, intensity);
			set_detector_pos(refl, 0.0, fs, ss);
			set_esd_intensity(refl, sigma);
			set_redundancy(refl, cts);

			ph = strtod(phs, &v);
			if ( v != phs ) set_phase(refl, deg2rad(ph));

		}

	} while ( rval != NULL );

	/* Got read error of some kind before finding PEAK_LIST_END_MARKER */
	return NULL;
}
void TouchCalibrationView::touch_complete() {
	auto next_phase = static_cast<Phase>(toUType(phase) + 1);

	switch(phase) {
	case Phase::Calibrate0:
	case Phase::Verify0:
		digitizer_points[0] = average;
		break;

	case Phase::Calibrate1:
	case Phase::Verify1:
		digitizer_points[1] = average;
		break;

	case Phase::Calibrate2:
	case Phase::Verify2:
		digitizer_points[2] = average;
		break;

	default:
		break;
	}

	if( phase == Phase::Calibrate2 ) {
		const std::array<Point, 3> display_points { {
			image_calibrate_0.screen_rect().center(),
			image_calibrate_1.screen_rect().center(),
			image_calibrate_2.screen_rect().center(),
		} };

		calibration = { digitizer_points, display_points };
	}

	if( phase == Phase::Verify2 ) {
		const auto calibrated_0 = calibration.translate(digitizer_points[0]);
		const auto d_sq_0 = distance_squared(calibrated_0, image_verify_0);

		const auto calibrated_1 = calibration.translate(digitizer_points[1]);
		const auto d_sq_1 = distance_squared(calibrated_1, image_verify_1);

		const auto calibrated_2 = calibration.translate(digitizer_points[2]);
		const auto d_sq_2 = distance_squared(calibrated_2, image_verify_2);

		if( (d_sq_0 < verify_d_sq_max) && (d_sq_1 < verify_d_sq_max) && (d_sq_2 < verify_d_sq_max) ) {
			next_phase = Phase::Success;
		} else {
			next_phase = Phase::Failure;
		}
	}

	set_phase(next_phase);
}
Ejemplo n.º 5
0
/* fin de la session courante, et annonce du vainqueur */
void vainqueur(){
  client_list *l = clients;
  char buffer[MAX_SIZE];

  /* Annulation des threads de phase et de timer */
  pthread_mutex_lock(&mutex_phase);
  pthread_cancel(tid_phase);
  pthread_cancel(tid_timer);
  set_phase("nulle");
  pthread_mutex_unlock(&mutex_phase);

  /* Envoi du nom de vainqueur à tous les joueurs */
  sprintf(buffer, "VAINQUEUR/%s/\n", bilan());
  pthread_mutex_lock(&mutex_clients);
  while(l != NULL){
    write(l->socket, buffer, strlen(buffer));
    l = l->next;
  }
  pthread_mutex_unlock(&mutex_clients);
}
Ejemplo n.º 6
0
Archivo: main.c Proyecto: khalilH/PC2R
int main(){
  int sock_connexion, sock_com;
  pthread_t tid;
    
  struct sockaddr_in sin; /* Nom de la socket de connexion */
  struct sockaddr_in exp; /* Nom de la socket de communication pour un client */

  int fromlen = sizeof(exp);

  /* initialisation de la variable plateaux */
  plateaux = (char**) malloc(3*sizeof(char*));
  plateaux[0] = strdup("(0,3,D)(0,11,D)(1,13,G)(1,13,H)(2,5,D)(2,5,B)(2,9,D)(2,9,B)(4,0,B)(4,2,D)(4,2,H)(4,15,H)(5,7,G)(5,7,B)(5,14,G)(5,14,B)(6,1,G)(6,1,H)(6,7,B)(6,8,B)(6,11,H)(6,11,D)(7,6,D)(7,9,G)(8,5,H)(8,5,D)(8,6,D)(8,9,G)(9,1,B)(9,1,D)(9,12,H)(9,12,D)(10,4,G)(10,4,B)(10,15,H)(12,0,H)(12,9,G)(12,9,H)(13,5,H)(13,5,D)(13,14,G)(13,14,B)(14,3,G)(14,3,H)(14,11,D)(14,11,B)(15,6,D)(15,13,D)(8,7,B)(8,8,B)");
  plateaux[1] = strdup("(0,4,D)(0,9,D)(1,6,D)(1,6,B)(1,14,H)(1,14,G)(2,1,H)(2,1,G)(2,11,G)(2,11,B)(3,15,B)(5,0,B)(5,6,H)(5,6,D)(6,3,G)(6,3,B)(6,7,B)(6,8,B)(6,13,B)(6,13,D)(7,6,D)(7,9,G)(7,10,H)(7,10,D)(8,5,B)(8,5,D)(8,6,D)(8,9,G)(8,12,G)(8,12,H)(9,7,H)(9,8,H)(9,10,G)(9,10,B)(10,2,H)(10,2,D)(10,15,B)(11,0,B)(11,9,B)(11,9,D)(12,14,H)(12,14,D)(13,4,G)(13,4,H)(14,6,G)(14,6,B)(14,13,G)(14,13,H)(15,4,D)(15,10,D)");
  plateaux[2] = strdup("(0,1,D)(0,9,D)(1,4,G)(1,4,H)(1,14,G)(1,14,H)(2,1,H)(2,1,D)(2,11,G)(2,11,B)(3,6,B)(3,6,D)(3,15,B)(5,0,B)(6,3,G)(6,3,B)(6,7,B)(6,8,B)(6,13,B)(6,13,D)(7,6,D)(7,9,G)(7,10,H)(7,10,D)(8,5,H)(8,5,D)(8,6,D)(8,9,G)(9,1,B)(9,1,D)(9,7,H)(9,8,H)(9,14,G)(9,14,H)(10,4,G)(10,4,B)(10,11,G)(10,11,B)(10,15,B)(12,0,H)(12,9,H)(12,9,D)(13,5,H)(13,5,D)(14,3,G)(14,3,H)(14,13,B)(14,13,D)(15,7,G)(15,11,D)");

  /* Liste de clients vide */
  /*  clients = NULL;
  file_attente = NULL;*/

  /* Phase est nulle */
  set_phase("nulle");
  
  /* Création de la socket */
  if((sock_connexion = socket(AF_INET, SOCK_STREAM, 0)) < 0){
    perror("socket");
    return EXIT_FAILURE;
  }

  /* Initialisation de la variable sin */
  memset((char *) &sin, 0, sizeof(sin));
  sin.sin_addr.s_addr = htonl(INADDR_ANY); /* INADDR_ANY = machine locale */
  sin.sin_port = htons(PORT);
  sin.sin_family = AF_INET;

  /* Pour réutiliser le port et l'adresse */
  if(setsockopt(sock_connexion, SOL_SOCKET, SO_REUSEADDR, &(int){ 1 }, sizeof(int)) < 0)
Ejemplo n.º 7
0
proc_t *scheduler_next(proc_t *current, int reds_left)
{
	set_phase(PHASE_NEXT);
	uint32_t reds_used = SLICE_REDUCTIONS -reds_left;
	ssi(SYS_STATS_CTX_SWITCHES);
	ssa(SYS_STATS_REDUCTIONS, reds_used);
	current->total_reds += reds_used;
	proc_t *next_proc = 0;
	uint64_t ticks = monotonic_clock(); // freeze time

	assert(current->my_queue == MY_QUEUE_NONE);

#ifdef PROFILE_HARNESS
static uint64_t proc_started_ns = 0;
	if (proc_started_ns != 0)
		prof_slice_complete(current->pid,
			current->result.what, current->cap.ip, proc_started_ns, ticks);
#endif

	proc_t *expired;
	while ((expired = wait_list_expired(&queues.on_timed_receive, ticks)) != 0)
	{
		expired->cap.ip = expired->result.jump_to;
		if (scheduler_park_runnable_N(expired) < 0)
			scheduler_exit_process(expired, A_NO_MEMORY);
	}

	int memory_exhausted = 0;
	switch (current->result.what)
	{
	case SLICE_RESULT_YIELD:
		if (scheduler_park_runnable_N(current) < 0)
			memory_exhausted = 1;
		break;
	case SLICE_RESULT_WAIT:
		if (current->result.until_when == LING_INFINITY)
		{
			if (proc_list_put_N(&queues.on_infinite_receive, current) < 0)
				memory_exhausted = 1;
			else
				current->my_queue = MY_QUEUE_INF_WAIT;
		}
		else
		{
			if (wait_list_put_N(&queues.on_timed_receive,
					current, current->result.until_when) < 0)
				memory_exhausted = 1;
			else
				current->my_queue = MY_QUEUE_TIMED_WAIT;
		}
		break;
	case SLICE_RESULT_DONE:
		scheduler_exit_process(current, A_NORMAL);
		break;

	case SLICE_RESULT_PURGE_PROCS:
		// purge_module() call may have detected processes lingering on the old
		// code - terminate them
		if (scheduler_park_runnable_N(current) < 0)
			memory_exhausted = 1;
		for (int i = 0; i < num_purged; i++)
			if (scheduler_signal_exit_N(purgatory[i], current->pid, A_KILL) < 0)
				memory_exhausted = 1;
		num_purged = 0;
		break;

	case SLICE_RESULT_EXIT:
		scheduler_exit_process(current, current->result.reason);
		// what about the returned value when main function just returns?
		break;
	case SLICE_RESULT_EXIT2:
		// only needed to implement erlang:exit/2
		if (scheduler_park_runnable_N(current) < 0 ||
				(scheduler_signal_exit_N(current->result.victim,
								         current->pid, 
								         current->result.reason2) < 0))
			memory_exhausted = 1;
		break;
	case SLICE_RESULT_ERROR:
		scheduler_exit_process(current, current->result.reason);
		// how is this different from SLICE_RESULT_EXIT?
		break;
	case SLICE_RESULT_THROW:
		scheduler_exit_process(current, current->result.reason);
		// how is this different from SLICE_RESULT_EXIT?
		break;
	default:
	{
		assert(current->result.what == SLICE_RESULT_OUTLET_CLOSE);
		if (scheduler_park_runnable_N(current) < 0)
			memory_exhausted = 1;
		outlet_t *closing = current->result.closing;
		//assert(is_atom(current->result.why));
		outlet_close(closing, current->result.why);
		break;
	}
	}

	if (memory_exhausted)
		scheduler_exit_process(current, A_NO_MEMORY);

do_pending:

	ticks = monotonic_clock();
	while ((expired = wait_list_expired(&queues.on_timed_receive, ticks)) != 0)
	{
		expired->cap.ip = expired->result.jump_to;
		if (scheduler_park_runnable_N(expired) < 0)
			scheduler_exit_process(expired, A_NO_MEMORY);
	}

	set_phase(PHASE_EVENTS);
	// software events/timeouts
	net_check_timeouts();
	etimer_expired(ticks);
	// 'hardware' events
	int nr_fired = events_do_pending();
	update_event_times(nr_fired, ticks);
	set_phase(PHASE_NEXT);

	// select_runnable
	if (!proc_queue_is_empty(&queues.high_prio))
		next_proc = proc_queue_get(&queues.high_prio);
	else if (normal_count < NORMAL_ADVANTAGE)
	{
		if (!proc_queue_is_empty(&queues.normal_prio))
			next_proc = proc_queue_get(&queues.normal_prio);
		else if (!proc_queue_is_empty(&queues.low_prio))
			next_proc = proc_queue_get(&queues.low_prio);
		normal_count++;
	}
	else
	{
		if (!proc_queue_is_empty(&queues.low_prio))
			next_proc = proc_queue_get(&queues.low_prio);
		else if (!proc_queue_is_empty(&queues.normal_prio))
			next_proc = proc_queue_get(&queues.normal_prio);
		normal_count = 0;
	}

	if (next_proc == 0)
	{
		// no runnable processes; poll for events from all three sources

		// Beware that events_poll() reports events 5us after they occur. If
		// a new event is expected very soon we are better off polling event
		// bits manually (using events_do_pending())

		// Devote a portion of time until the next event to gc waiting processes
		garbage_collect_waiting_processes(expect_event_in_ns /2);

		if (expect_event_in_ns < MANUAL_POLLING_THRESHOLD)
			goto do_pending;

		uint64_t next_ticks = wait_list_timeout(&queues.on_timed_receive);
		uint64_t closest_timeout = etimer_closest_timeout();
		if (closest_timeout < next_ticks)
			next_ticks = closest_timeout;

		closest_timeout = lwip_closest_timeout();
		if (closest_timeout < next_ticks)
			next_ticks = closest_timeout;

		scheduler_runtime_update();
		events_poll(next_ticks);		// LING_INFINITY is big enough
		scheduler_runtime_start();

		goto do_pending;
	}

	next_proc->my_queue = MY_QUEUE_NONE;
	
	//TODO: update stats

#ifdef PROFILE_HARNESS
	proc_started_ns = ticks;
#endif

	set_phase(PHASE_ERLANG);
	return next_proc;
}
Ejemplo n.º 8
0
static int
set_new_event( int t )
{
    int ptr;
    unsigned char *data;
    int count;
    int follower;
    __GETMDX;

    data = mdx->data;
    ptr = mdx->track[t].current_mml_ptr;
    count = 0;
    follower = 0;

#if 0
    if ( ptr+1 <= mdx->length && t>7 ) {
        fprintf(stderr,"%2d %2x %2x\n",t,data[ptr],data[ptr+1]);
        fflush(stderr);
    }
#endif

    if ( data[ptr] <= MDX_MAX_REST ) {  /* rest */
        note_off(t);
        count = data[ptr]+1;
        mdx->track[t].gate = count+1;
        follower=0;

    } else if ( data[ptr] <= MDX_MAX_NOTE ) { /* note */
        note_on( t, data[ptr]);
        count = data[ptr+1]+1;
        do_quantize( t, count );
        follower = 1;

    } else {
        switch ( data[ptr] ) {

        case MDX_SET_TEMPO:
            set_tempo( data[ptr+1] );
            follower = 1;
            break;

        case MDX_SET_OPM_REG:
            set_opm_reg( t, data[ptr+1], data[ptr+2] );
            follower = 2;
            break;

        case MDX_SET_VOICE:
            set_voice( t, data[ptr+1] );
            follower = 1;
            break;

        case MDX_SET_PHASE:
            set_phase( t, data[ptr+1] );
            follower = 1;
            break;

        case MDX_SET_VOLUME:
            set_volume( t, data[ptr+1] );
            follower = 1;
            break;

        case MDX_VOLUME_DEC:
            dec_volume( t );
            follower = 0;
            break;

        case MDX_VOLUME_INC:
            inc_volume( t );
            follower = 0;
            break;

        case MDX_SET_QUANTIZE:
            set_quantize( t, data[ptr+1] );
            follower = 1;
            break;

        case MDX_SET_KEYOFF:
            set_keyoff( t );
            follower = 0;
            break;

        case MDX_REPEAT_START:
            mdx->track[t].loop_counter[mdx->track[t].loop_depth] = data[ptr+1];
            if ( mdx->track[t].loop_depth < MDX_MAX_LOOP_DEPTH )
                mdx->track[t].loop_depth++;
            follower = 2;
            break;

        case MDX_REPEAT_END:
            if (--mdx->track[t].loop_counter[mdx->track[t].loop_depth-1] == 0 ) {
                if ( --mdx->track[t].loop_depth < 0 ) mdx->track[t].loop_depth=0;
            } else {
                if ( data[ptr+1] >= 0x80 ) {
                    ptr = ptr+2 - (0x10000-(data[ptr+1]*256 + data[ptr+2])) - 2;
                } else {
                    ptr = ptr+2 + data[ptr+1]*256 + data[ptr+2] - 2;
                }
            }
            follower = 2;
            break;

        case MDX_REPEAT_BREAK:
            if ( mdx->track[t].loop_counter[mdx->track[t].loop_depth-1] == 1 ) {
                if ( --mdx->track[t].loop_depth < 0 ) mdx->track[t].loop_depth=0;
                ptr = ptr+2 + data[ptr+1]*256 + data[ptr+2] -2 +2;
            }
            follower = 2;
            break;

        case MDX_SET_DETUNE:
            set_detune( t, data[ptr+1], data[ptr+2] );
            follower = 2;
            break;

        case MDX_SET_PORTAMENT:
            set_portament( t, data[ptr+1], data[ptr+2] );
            follower = 2;
            break;

        case MDX_DATA_END:
            if ( data[ptr+1] == 0x00 ) {
                count = -1;
                note_off(t);
                follower = 1;
            } else {
                ptr = ptr+2 - (0x10000-(data[ptr+1]*256 + data[ptr+2])) - 2;
                mdx->track[t].infinite_loop_times++;
                follower = 2;
            }
            break;

        case MDX_KEY_ON_DELAY:
            follower = 1;
            break;

        case MDX_SEND_SYNC:
            send_sync( data[ptr+1] );
            follower = 1;
            break;

        case MDX_RECV_SYNC:
            recv_sync( t );
            follower = 0;
            count = 1;
            break;

        case MDX_SET_FREQ:
            set_freq( t, data[ptr+1] );
            follower = 1;
            break;

        case MDX_SET_PLFO:
            if ( data[ptr+1] == 0x80 || data[ptr+1] == 0x81 ) {
                set_plfo_onoff( t, data[ptr+1]-0x80 );
                follower = 1;
            } else {
                set_plfo( t,
                          data[ptr+1], data[ptr+2], data[ptr+3],
                          data[ptr+4], data[ptr+5] );
                follower = 5;
            }
            break;

        case MDX_SET_ALFO:
            if ( data[ptr+1] == 0x80 || data[ptr+1] == 0x81 ) {
                set_alfo_onoff( t, data[ptr+1]-0x80 );
                follower = 1;
            } else {
                set_alfo( t,
                          data[ptr+1], data[ptr+2], data[ptr+3],
                          data[ptr+4], data[ptr+5] );
                follower = 5;
            }
            break;

        case MDX_SET_OPMLFO:
            if ( data[ptr+1] == 0x80 || data[ptr+1] == 0x81 ) {
                set_hlfo_onoff( t, data[ptr+1]-0x80 );
                follower = 1;
            } else {
                set_hlfo( t,
                          data[ptr+1], data[ptr+2], data[ptr+3],
                          data[ptr+4], data[ptr+5] );
                follower = 5;
            }
            break;

        case MDX_SET_LFO_DELAY:
            set_lfo_delay( t, data[ptr+1] );
            follower = 1;
            break;

        case MDX_SET_PCM8_MODE:
            follower = 0;
            break;

        case MDX_FADE_OUT:
            if ( data[ptr+1]==0x00 ) {
                follower = 1;
                set_fade_out( 5 );
            } else {
                follower = 2;
                set_fade_out( data[ptr+2] );
            }
            break;

        default:
            count = -1;
            break;
        }
    }

    ptr += 1+follower;
    mdx->track[t].current_mml_ptr = ptr;

    return count;
}
static void next_phase(TyonXceleratorCalibrationAssistant *cal_assistant) {
	TyonXceleratorCalibrationAssistantPrivate *priv = cal_assistant->priv;
	set_phase(cal_assistant, next_phases[priv->phase]);
}