initial commit
This commit is contained in:
commit
3aca31de74
40 changed files with 1701 additions and 0 deletions
26
clock/src/ClockMain.java
Normal file
26
clock/src/ClockMain.java
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import clock.AlarmClockEmulator;
|
||||
import clock.io.Choice;
|
||||
import clock.io.ClockInput;
|
||||
import clock.io.ClockInput.UserInput;
|
||||
import clock.io.ClockOutput;
|
||||
|
||||
public class ClockMain {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
AlarmClockEmulator emulator = new AlarmClockEmulator();
|
||||
|
||||
ClockInput in = emulator.getInput();
|
||||
ClockOutput out = emulator.getOutput();
|
||||
|
||||
out.displayTime(15, 2, 37); // arbitrary time: just an example
|
||||
|
||||
while (true) {
|
||||
UserInput userInput = in.getUserInput();
|
||||
Choice c = userInput.choice();
|
||||
int h = userInput.hours();
|
||||
int m = userInput.minutes();
|
||||
int s = userInput.seconds();
|
||||
|
||||
System.out.println("choice=" + c + " h=" + h + " m=" + m + " s=" + s);
|
||||
}
|
||||
}
|
||||
}
|
||||
7
clock/src/clock/io/Choice.java
Normal file
7
clock/src/clock/io/Choice.java
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
package clock.io;
|
||||
|
||||
public enum Choice {
|
||||
SET_TIME, // user set new clock time
|
||||
SET_ALARM, // user set new alarm time
|
||||
TOGGLE_ALARM; // user pressed both buttons simultaneously
|
||||
}
|
||||
43
clock/src/clock/io/ClockInput.java
Normal file
43
clock/src/clock/io/ClockInput.java
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package clock.io;
|
||||
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
/**
|
||||
* Input signals from clock hardware.
|
||||
*
|
||||
* NOTE: you are not expected to modify this interface,
|
||||
* nor to implement it yourself. Instead, to read from
|
||||
* the emulated hardware, do as follows:
|
||||
*
|
||||
* AlarmClockEmulator emulator = new AlarmClockEmulator();
|
||||
* ClockInput in = emulator.getInput();
|
||||
*
|
||||
* Then use the reference 'in' to read the input signals.
|
||||
*/
|
||||
public interface ClockInput {
|
||||
|
||||
/** @return semaphore signaled on user input (via hardware interrupt) */
|
||||
Semaphore getSemaphore();
|
||||
|
||||
/** @return an item of user input (available only when semaphore is signaled) */
|
||||
UserInput getUserInput();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** An item of input, entered by the user. */
|
||||
interface UserInput {
|
||||
/** @return a value indicating the type of choice made by the user. */
|
||||
Choice choice();
|
||||
|
||||
/**
|
||||
* These methods return a time set by the user (clock time or alarm time).
|
||||
*
|
||||
* If choice() returns SET_TIME, these return the time the user entered.
|
||||
* If choice() returns SET_ALARM, these return the alarm time the user entered.
|
||||
* If choice() returns TOGGLE_ALARM, these return an invalid value.
|
||||
*/
|
||||
int hours();
|
||||
int minutes();
|
||||
int seconds();
|
||||
}
|
||||
}
|
||||
26
clock/src/clock/io/ClockOutput.java
Normal file
26
clock/src/clock/io/ClockOutput.java
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package clock.io;
|
||||
|
||||
/**
|
||||
* Output signals to clock hardware.
|
||||
*
|
||||
* NOTE: you are not expected to modify this interface,
|
||||
* nor to implement it yourself. Instead, to control
|
||||
* the emulated hardware, do as follows:
|
||||
*
|
||||
* AlarmClockEmulator emulator = new AlarmClockEmulator();
|
||||
* ClockInput out = emulator.getoutput();
|
||||
*
|
||||
* Then use the reference 'out' to control the output signals.
|
||||
*/
|
||||
public interface ClockOutput {
|
||||
|
||||
/** Display the given time on the display, for example (15, 2, 37) for
|
||||
15 hours, 2 minutes and 37 seconds since midnight. */
|
||||
void displayTime(int hours, int mins, int secs);
|
||||
|
||||
/** Indicate on the display whether the alarm is on or off. */
|
||||
void setAlarmIndicator(boolean on);
|
||||
|
||||
/** Signal the alarm. (In the emulator, only a visual alarm is given.) */
|
||||
void alarm();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue