-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
95 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
smart-hub/src/main/scala/io/github/tassiLuca/smarthome/core/DashboardComponent.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.github.tassiLuca.smarthome.core | ||
|
||
trait DashboardComponent: | ||
|
||
enum HeaterState: | ||
case ON, OFF | ||
|
||
val dashboard: Dashboard | ||
|
||
trait Dashboard: | ||
def updateTemperature(entries: Seq[TemperatureEntry]): Unit | ||
def newHeaterState(state: HeaterState): Unit | ||
def newAlert(msg: String): Unit |
22 changes: 0 additions & 22 deletions
22
smart-hub/src/main/scala/io/github/tassiLuca/smarthome/core/HVACControllerComponent.scala
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
smart-hub/src/main/scala/io/github/tassiLuca/smarthome/core/HeaterComponent.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.github.tassiLuca.smarthome.core | ||
|
||
import gears.async.Async | ||
|
||
trait HeaterComponent: | ||
|
||
/** The instance in charge of controlling heater actuator. */ | ||
val heater: Heater | ||
|
||
/** Heater actuator controller. */ | ||
trait Heater: | ||
/** Turn on the heater. */ | ||
def on(using Async): Unit | ||
|
||
/** Turn off the heater. */ | ||
def off(using Async): Unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
smart-hub/src/main/scala/io/github/tassiLuca/smarthome/infrastructure/SwingDashboard.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.github.tassiLuca.smarthome.infrastructure | ||
|
||
import io.github.tassiLuca.smarthome.core.{DashboardComponent, TemperatureEntry} | ||
|
||
import java.awt.{BorderLayout, FlowLayout, Font, GridLayout} | ||
import javax.swing.{JFrame, JLabel, JPanel, JScrollPane, JTextArea, SwingUtilities, WindowConstants} | ||
|
||
trait SwingDashboard extends DashboardComponent: | ||
override val dashboard: Dashboard = new Dashboard: | ||
|
||
private val view: MainFrame = MainFrame() | ||
|
||
override def updateTemperature(entries: Seq[TemperatureEntry]): Unit = SwingUtilities.invokeLater { () => | ||
view.temperatureLabel.setText("NEW TEMP") | ||
} | ||
|
||
override def newHeaterState(state: HeaterState): Unit = SwingUtilities.invokeLater { () => | ||
view.heaterLabel.setText(state.toString) | ||
} | ||
|
||
override def newAlert(msg: String): Unit = SwingUtilities.invokeLater { () => | ||
view.alertTextArea.setText(msg) | ||
} | ||
|
||
private class MainFrame extends JFrame: | ||
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE) | ||
setSize(300, 200) | ||
setLayout(new GridLayout(3, 1)) | ||
val temperatureLabel = new JLabel("00°C") | ||
temperatureLabel.setFont(new Font("Arial", Font.BOLD, 20)) | ||
val heaterLabel = new JLabel("Off") | ||
heaterLabel.setFont(new Font("Arial", Font.BOLD, 20)) | ||
val alertTextArea = new JTextArea(5, 20) | ||
alertTextArea.setEditable(false) | ||
val tempPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)) | ||
tempPanel.add(new JLabel("Current Temperature:")) | ||
tempPanel.add(temperatureLabel) | ||
val heaterPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)) | ||
heaterPanel.add(new JLabel("Heater Status:")) | ||
heaterPanel.add(heaterLabel) | ||
val alertPanel = new JPanel(new BorderLayout()) | ||
alertPanel.add(new JLabel("Alerts:"), BorderLayout.NORTH) | ||
alertPanel.add(new JScrollPane(alertTextArea), BorderLayout.CENTER) | ||
add(tempPanel) | ||
add(heaterPanel) | ||
add(alertPanel) | ||
setVisible(true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters