コード例 #1
0
ファイル: 7segled_test.c プロジェクト: toru-ver4/raspberry
int main(void)
{
	unsigned int value = 0;
	
	// GPIO初期化
	if( ! rpi_gpio_init() )
		return -1;
	
	led_init();
	
	for( value = 0; value < 10; value++ ) {
		printf("LED = %d\n", value );
		led_put(value);
		sleep(1);
	}
	// mmap開放
	rpi_gpio_deinit();
	
	return 1;
}
コード例 #2
0
OCEntityHandlerResult LedOCEntityHandlerCb(OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest,
                                        void *callbackParam)
{
	OCEntityHandlerResult ehRet = OC_EH_OK;
	OCEntityHandlerResponse response = {0};
	OCRepPayload* payload = OCRepPayloadCreate();
	if(!payload) {
		OC_LOG(ERROR, TAG, ("Failed to allocate Payload"));
		return OC_EH_ERROR;
	}

	if(entityHandlerRequest && (flag & OC_REQUEST_FLAG)) {
		OC_LOG (INFO, TAG, ("Flag includes OC_REQUEST_FLAG"));

		if(OC_REST_GET == entityHandlerRequest->method) {
			OCRepPayloadSetUri(payload, "/grove/led");
			OCRepPayloadSetPropInt(payload, "status", led.status);
		} else if(OC_REST_PUT == entityHandlerRequest->method) {
			int64_t status;
			OCRepPayload *rep = (OCRepPayload *)entityHandlerRequest->payload;
			OC_LOG(INFO, TAG, ("PUT request"));
			OCRepPayloadGetPropInt(rep, "status", &status);
			if(status > 255)
				status = 255;
			else if(status < 0)
				status = 0;
			led.status = (int)status;
			led_put();
			OCRepPayloadSetPropInt(payload, "status", led.status);
		}

		if (ehRet == OC_EH_OK) {
			// Format the response.  Note this requires some info about the request
			response.requestHandle = entityHandlerRequest->requestHandle;
			response.resourceHandle = entityHandlerRequest->resource;
			response.ehResult = ehRet;
			response.payload = (OCPayload*) payload;
			response.numSendVendorSpecificHeaderOptions = 0;
			memset(response.sendVendorSpecificHeaderOptions, 0, sizeof response.sendVendorSpecificHeaderOptions);
			memset(response.resourceUri, 0, sizeof response.resourceUri);
			// Indicate that response is NOT in a persistent buffer
			response.persistentBufferFlag = 0;

			// Send the response
			if (OCDoResponse(&response) != OC_STACK_OK) {
				OC_LOG(ERROR, TAG, "Error sending response");
				ehRet = OC_EH_ERROR;
			}
		}
	}

	if (entityHandlerRequest && (flag & OC_OBSERVE_FLAG)) {
		if (OC_OBSERVE_REGISTER == entityHandlerRequest->obsInfo.action) {
			OC_LOG (INFO, TAG, ("Received OC_OBSERVE_REGISTER from client"));
			gLightUnderObservation = 1;
		} else if (OC_OBSERVE_DEREGISTER == entityHandlerRequest->obsInfo.action) {
			OC_LOG (INFO, TAG, ("Received OC_OBSERVE_DEREGISTER from client"));
			gLightUnderObservation = 0;
		}
	}
	OCRepPayloadDestroy(payload);
	return ehRet;
}