All Downloads are FREE. Search and download functionalities are using the official Maven repository.

osgi.enroute.iot.pi.provider.PiModelDetector Maven / Gradle / Ivy

Go to download

This bundle wraps Pi4j (http://pi4j.com) that wraps the native code Wiring Pi (http://wiringpi.com). It wraps these libraries to make them OSGi friendly and allow them to work together with the OSGi enRoute IoT circuit library (osgi.enroute.iot.circuit). The bundle will first use Pi4J to detect on what hardware it runs. If it runs on an appropriate type, it will register a component that can be configured with Metatype. The Metatype defines a full blown configuration template for all the Pi's functions. The GPIO's are registered as components for the circuit. Regardless of the success of the configuration, this bundle will also register a GpioController service, which is the main Pi4J class.

There is a newer version: 2.1.0
Show newest version
package osgi.enroute.iot.pi.provider;

import java.io.IOException;
import java.util.Hashtable;

import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;

import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.system.SystemInfo;
import com.pi4j.wiringpi.GpioInterruptEvent;

/**
 * This component detects the type of Pi and registers an appropriate service.
 * This service contains a number of service properties that identify the
 * hardware. The purpose of this component is to get an appropriate component
 * started.
 */
@Component(immediate = true)
public class PiModelDetector {
	GpioController gpio;
	ServiceRegistration registration;

	@Activate
	void activate(BundleContext context) throws IOException,
			InterruptedException {

		// For some reason we need to preload this class
		new GpioInterruptEvent("SS", 0, false);

		gpio = GpioFactory.getInstance();
		Hashtable props = new Hashtable();
		props.put("serial.number", SystemInfo.getSerial());
		props.put("cpu.revision", SystemInfo.getCpuRevision());
		props.put("cpu.model", SystemInfo.getModelName());
		props.put("hardware.revision", SystemInfo.getRevision());
		props.put("board.type", SystemInfo.getBoardType().name());
		registration = context.registerService(GpioController.class, gpio,
				props);
	}

	@Deactivate
	void deactivate() {
		registration.unregister();
		gpio.shutdown();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy