Example #1
0
void task_send_data(volatile struct state_t *st)
{
	if (millis() - 3000 > st->last_send_time) {
		printf("WAKESEND...\n");
		simrf_immediate_wakeup();
		kpacket2 kp;
		kp.header = 'x';
		int sensor_count = 2;

		ksensor s1 = {KPS_SENSOR_TEMPERATURE, st->last_temperature * 1000};
		ksensor s2 = {KPS_SENSOR_RELATIVE_HUMIDITY, st->last_relative_humidity * 1000};
		ksensor ch1 = {0, 0};
		ksensor ch2 = {0, 0};
		if (jack_connected(&jack1)) {
			sensor_count++;
			ch1.type = jack1.sensor_type;
			ch1.value = st->jack_machine1.last_value;
		}
		if (jack_connected(&jack2)) {
			sensor_count++;
			ch2.type = jack2.sensor_type;
			ch2.value = st->jack_machine2.last_value;
		}
		kp.ksensors[0] = s1;
		kp.ksensors[1] = s2;
		kp.ksensors[2] = ch1;
		kp.ksensors[3] = ch2;
		kp.versionCount = VERSION_COUNT(2, sensor_count);

		simrf_send16(state.rf_dest_id, sizeof (kp), (void*) &kp);
		st->last_send_time = millis();
	}
}
Example #2
0
/**
 * NOTE this is a state machine, but it expects to run often enough for millis()
 * @param machine
 * @param res
 */
void jack_run_task(volatile struct jacks_machine_t *machine, struct jacks_result_t *res)
{
	res->ready = false;
	if (!jack_connected(machine->jack)) {
		return;
	}
	switch (machine->step) {
	case jack_machine_step_off:
		// is it time to do a reading yet?
		if (millis() - 3000 > machine->last_read_millis) {
			printf("switching power on: channel %u\n", (unsigned int) machine->jack->val_channel);
			gpio_set(machine->jack->power_port, machine->jack->power_pin);
			machine->step = jack_machine_step_powered;
			machine->step_entry_millis = millis();
		}
		break;

	case jack_machine_step_powered:
		// have we been powered up long enough yet?
		if (millis() - machine->jack->power_on_time_millis > machine->step_entry_millis) {
			printf("power stable!\n");
			machine->step = jack_machine_step_ready;
			// not really necessary... machine->step_entry_millis = millis();
		} else {
			printf(".");
		}
		break;

	case jack_machine_step_ready:
		// TODO - this should actually start a dma sequence and go to a next step 
		// that decimates/averages and finally returns.
		// ok! do a few readings and call it good
		adc_disable_scan_mode(ADC1);
		adc_set_single_conversion_mode(ADC1);
		adc_set_sample_time_on_all_channels(ADC1, ADC_SMPR_SMP_28DOT5CYC);
		//adc_set_single_channel(ADC1, machine->jack->val_channel);
		adc_set_regular_sequence(ADC1, 1, (u8*)&(machine->jack->val_channel));

		adc_enable_external_trigger_regular(ADC1, ADC_CR2_EXTSEL_SWSTART);
		adc_start_conversion_regular(ADC1);
		printf("ok, doing reading on channel!\n");
		while(!adc_eoc(ADC1)) {
			;
		}
		res->ready = true;
		res->value = adc_read_regular(ADC1);
		machine->last_value = res->value;
		machine->last_read_millis = millis();
		gpio_clear(machine->jack->power_port, machine->jack->power_pin);
		machine->step = jack_machine_step_off;
		break;
	}
	return;
}
Example #3
0
void xapi_psync(void *d) {
	int ss =0;
#if defined (HAVE_LTCSMPTE) || defined (HAVE_LTC)
	if (ltcjack_connected()) ss=3;
	else
#endif
#ifdef HAVE_MIDI
	if (midi_connected()) ss=2;
	else
#endif
	if (jack_connected()) ss=1;
	remote_printf(201,"syncsource=%i",ss);
}
Example #4
0
int main (int argc, char **argv) {
	int run;
	char *filename = NULL;
	long frame, pframe;
	program_name = argv[0];

	if (argc>3) usage(1);
	if (argc==3) {
		filename=argv[2];
		frames=atol(argv[1]);
	}
	else if (argc>1) filename=argv[1];

	if (frames < 1 || duration < 1) usage(1);
	if (!filename) usage(1);

	framerate = (double) frames / (double) duration;

	struct timeval tv;
	fd_set set;

	//TODO: trap some signals.. -> run=0;

	if (jack) {
		open_jack();
		run= jack_connected();
	} else{
#ifdef HAVE_MIDI
		midi_open(midiid);
#endif
		run= midi_connected();
		
	}

	printf ("jack disconnect\n");
	printf ("load %s\n",filename);
	printf ("window mouse off\n");
	printf ("window letterbox on\n");
	printf ("window fullscreen on\n");
//	printf ("window resize 880x545\n");
	printf ("osd font /usr/share/fonts/truetype/freefont/FreeMonoBold.ttf\n");
	printf ("osd off\n");
	printf ("osd smpte 100\n");
	printf ("set fps %.0f\n",framerate);

	pframe=-1;
	while (run) {
		tv.tv_sec = 0;
		tv.tv_usec = 1000000/framerate;
		FD_ZERO(&set);
		if (readfromstdin) FD_SET(0, &set);

		if (select(0+readfromstdin, &set, NULL, NULL, &tv) ) if (readfromstdin) {
			size_t rv;
			char buf[BUFSIZ];
			if ((rv=read(0,buf,BUFSIZ)) > 0) {
				if (!strncmp(buf,"exit",3)) { 
					printf ("quit\n");
					run=0;
				}else 
					write(1,buf,rv);
			}
		}

		if (jack) frame= jack_poll_frame(NULL);
#ifdef HAVE_MIDI
		else frame= midi_poll_frame();
#else
		else exit (1);
#endif
		if (pframe!=frame)
			printf ("seek %li\n",frame);
		pframe=frame;

		fflush(stdout);
	}