gboolean On_VolDown_ButtonPress(GIOChannel *source, GIOCondition condition, gpointer data)
{
	IoT_Error_t rc = NONE_ERROR;
	GError *error=0;
	char buf[10];
	char payload[MAX_PAYLOAD];
	struct input_event event;
	gsize bytes_read;

	//read and clear the event
	g_io_channel_seek_position(source, 0, G_SEEK_SET, 0);
	g_io_channel_read_chars(source, (gchar*) &event, sizeof(event), &bytes_read, NULL);

//	if(bytes_read >0)
//	    printf("Event0: keypress value=%x, type=%x, code=%x\n", event.value, event.type, event.code);

	if(event.code == 0x72 && event.value == 0x1)
	{
		INFO("Vol_Down Button pressed!");

		char* thingID = (char*) data;
		sprintf(payload, "{\n\"timestamp\": %lu, \"volume\": \"%s\" \n}\n", GetTimeSinceEpoch(), "decrease");
		printf("%s", payload);

		/**/
		char topic[512];
        	sprintf(topic, vol_button_topic, thingID);        
		rc = MQTT_Send_Message(topic, payload, strlen(payload));
		if (NONE_ERROR != rc)
			ERROR("Could not publish event: ");
	}
	return 1;	//indicate event handled
}
Пример #2
0
ParticleEmitterComponent::ParticleEmitterComponent()
	: particleEmitInterval_s(0), lastTimeOfEmission_s(0), particlesPerEmission(0),
	  IComponent(CTYPE_PARTICLE_EMITTER)
{
	lastTimeOfEmission_s = GetTimeSinceEpoch();
}