Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "BaSyx / Introductory Examples / Java / Example Heater"

m (Heater stub)
m
 
Line 30: Line 30:
 
  *
 
  *
 
  */
 
  */
public class Heater implments IHeater {
+
public class Heater implements IHeater {
 
private boolean isActive = false;
 
private boolean isActive = false;
  

Latest revision as of 10:58, 21 April 2021

Heater stub

This stub code realizes an interface to an oven and a dummy implementation for the example code that can be executed without any hardware.


The heater interface defines common interface functions to control the oven.

/**
 * The heater enables controlling of the oven
 */
public interface IHeater {
 
	public void activate();
 
	public void deactivate();
 
	public boolean isActive();
}


The heater stub is used during the example.

Heater Code

/**
 * Simple heater with two states: activated or deactivated
 *
 */
public class Heater implements IHeater {
	private boolean isActive = false;
 
	public void activate() {
		if (!isActive) {
			System.out.println("Heater: activated");
			isActive = true;
		}
	}
 
	public void deactivate() {
		if (isActive) {
			System.out.println("Heater: deactivated");
			isActive = false;
		}
	}
 
	public boolean isActive() {
		return isActive;
	}
}

Back to the top