Exemplo n.º 1
0
int main (void) {
  // initialize system
  system_init();

  // endless loop
  while (1) {
    // current time
    uint16_t time;
    uint8_t  minutes;
    uint8_t  seconds;

    // update current time
    time = tick_get();
    minutes = tick_tomin(time);
    seconds = tick_tosec(time);


    // print result to uart0
    string_from_const(uart0_send, "current time - ");
    string_from_uint (uart0_send, minutes, 2);
    string_from_const(uart0_send, ":");
    string_from_uint (uart0_send, seconds, 2);
    string_from_const(uart0_send, "\r\n");

    // wait for 0.25 seconds
    tick_delay(250);
  }

  return (0);
}
Exemplo n.º 2
0
//**************************[system_tick_print]******************************** 27.09.2015
void system_tick_print(void (*out)(uint8_t)) {

    string_from_const(out, "tick:"                                    "\r\n");

    string_from_const_length(out, "  tics" , 15); string_from_const(out, ": ");
    string_from_uint(out, system_tick_time,5); string_from_const(out, "\r\n");

    string_from_const(out,                                             "\r\n");
}
Exemplo n.º 3
0
//**************************[system_adc_print]********************************* 16.09.2014
void system_adc_print(void (*out)(uint8_t)) {
  string_from_const(out, "adc:"                                        "\r\n");

  string_from_const_length(out, "  enabled", 15); string_from_const(out, ": ");
  string_from_bool(out, adc_is_enabled());      string_from_const(out, "\r\n");

  uint8_t nr;
  for (nr = 0; nr < 8; nr++) {
    string_from_const(out, "  channel["); out(nr + 48);
    string_from_const_length(out, "]", 15 - 11);
    string_from_const(out, ": ");
    string_from_uint(out, system_adc_values[nr], 4);
    string_from_const(out, "\r\n");
  }

  string_from_const(out,                                               "\r\n");
}
Exemplo n.º 4
0
static int
render_import_glsl_shader(stream_t* stream, const uuid_t uuid, const char* type,
                          size_t type_length) {
	resource_source_t source;
	void* blob = 0;
	size_t size;
	size_t read;
	size_t begin;
	size_t next;
	hash_t checksum;
	tick_t timestamp;
	uint64_t platform;
	size_t maxtokens;
	size_t parameter;
	string_const_t* token = 0;
	string_const_t valstr;
	char buffer[128];
	int ret = 0;
	resource_platform_t platformdecl = { -1, -1, RENDERAPIGROUP_OPENGL, -1, -1, -1};

	resource_source_initialize(&source);
	resource_source_read(&source, uuid);

	read = 0;
	size = stream_size(stream);
	blob = memory_allocate(HASH_RESOURCE, size, 0, MEMORY_PERSISTENT);

	size = stream_read(stream, blob, size);

	platform = resource_platform(platformdecl);
	timestamp = time_system();
	checksum = hash(blob, size);
	if (resource_source_write_blob(uuid, timestamp, HASH_SOURCE,
	                               platform, checksum, blob, size)) {
		resource_source_set_blob(&source, timestamp, HASH_SOURCE,
		                         platform, checksum, size);
	}
	else {
		ret = -1;
		goto finalize;
	}

	//Parse source and set parameters
	maxtokens = 256;
	token = memory_allocate(HASH_RESOURCE, sizeof(string_const_t) * maxtokens, 0, MEMORY_PERSISTENT);
	begin = 0;
	parameter = 0;
	do {
		string_const_t tokens[64], line;
		size_t itok, ntokens;

		next = string_find_first_of(blob, size, STRING_CONST("\n\r"), begin);
		line = string_substr(blob, size, begin, next - begin);
		ntokens = string_explode(STRING_ARGS(line), STRING_CONST(GLSL_TOKEN_DELIM),
		                        tokens, maxtokens, false);

		for (itok = 0; itok < ntokens; ++itok) {
			if ((string_equal(STRING_ARGS(tokens[itok]), STRING_CONST("attribute")) ||
			        string_equal(STRING_ARGS(tokens[itok]), STRING_CONST("uniform"))) &&
			        (itok + 2 < ntokens)) {
				char typebuf[16], dimbuf[16];
				string_const_t typestr = tokens[itok + 1];
				string_const_t namestr = tokens[itok + 2];
				string_const_t dimstr;

				int parameter_type = glsl_type_to_parameter_type(typestr);
				if (parameter_type < 0)
					continue;

				int parameter_dim = glsl_dim_from_token(typestr);
				if (parameter_dim == 1)
					parameter_dim = glsl_dim_from_token(namestr);

				namestr = glsl_name_from_token(namestr);
				typestr = string_to_const(string_from_uint(typebuf, sizeof(typebuf), (unsigned int)parameter_type, false, 0, 0));
				dimstr = string_to_const(string_from_uint(dimbuf, sizeof(dimbuf), (unsigned int)parameter_dim, false, 0, 0));

				log_debugf(HASH_RESOURCE, STRING_CONST("parameter: %.*s type %.*s dim %.*s"),
				           STRING_FORMAT(namestr), STRING_FORMAT(typestr), STRING_FORMAT(dimstr));

				string_t param = string_format(buffer, sizeof(buffer), STRING_CONST("parameter_type_%" PRIsize),
				                               parameter);
				resource_source_set(&source, timestamp, hash(STRING_ARGS(param)),
				                    platform, STRING_ARGS(typestr));

				param = string_format(buffer, sizeof(buffer), STRING_CONST("parameter_name_%" PRIsize),
				                      parameter);
				resource_source_set(&source, timestamp, hash(STRING_ARGS(param)),
				                    platform, STRING_ARGS(namestr));

				param = string_format(buffer, sizeof(buffer), STRING_CONST("parameter_dim_%" PRIsize),
				                      parameter);
				resource_source_set(&source, timestamp, hash(STRING_ARGS(param)),
				                    platform, STRING_ARGS(dimstr));
				++parameter;
			}
		}

		begin = string_find_first_not_of(blob, size, STRING_CONST(STRING_WHITESPACE), next);
	}
	while (next != STRING_NPOS);

	valstr = string_from_uint_static(parameter, false, 0, 0);
	resource_source_set(&source, timestamp, HASH_PARAMETER_COUNT,
	                    platform, STRING_ARGS(valstr));

	resource_source_set(&source, timestamp, HASH_RESOURCE_TYPE,
	                    0, type, type_length);

	if (!resource_source_write(&source, uuid, false)) {
		string_const_t uuidstr = string_from_uuid_static(uuid);
		log_warnf(HASH_RESOURCE, WARNING_SUSPICIOUS, STRING_CONST("Failed writing imported GLSL shader: %.*s"),
		          STRING_FORMAT(uuidstr));
		ret = -1;
		goto finalize;
	}
	else {
		string_const_t uuidstr = string_from_uuid_static(uuid);
		log_infof(HASH_RESOURCE, STRING_CONST("Wrote imported GLSL shader: %.*s"),
		          STRING_FORMAT(uuidstr));
	}

finalize:
	memory_deallocate(blob);
	memory_deallocate(token);
	resource_source_finalize(&source);

	return ret;
}