Skip to content

Commit 62db5b1

Browse files
Finished LiveWindow implementation
1 parent f46e5be commit 62db5b1

File tree

20 files changed

+149
-58
lines changed

20 files changed

+149
-58
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
An abstraction of NetworkTables, Shuffleboard, SmartDashboard, and LiveWindow
33

44
### TODO
5-
* Have master object to hold instances of important stuff
5+
* Nothing right now!

core/src/main/java/com/first1444/dashboard/advanced/ActuatorActiveComponent.kt

Lines changed: 0 additions & 8 deletions
This file was deleted.

core/src/main/java/com/first1444/dashboard/advanced/ActuatorSendable.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ import com.first1444.dashboard.ActiveComponent
44
import com.first1444.dashboard.BasicDashboard
55
import com.first1444.dashboard.enable.EnabledProvider
66

7-
class ActuatorSendable(
7+
class ActuatorSendable
8+
/**
9+
* @param sendable The [Sendable] that will be used
10+
* @param enabledProvider The [EnabledProvider] that that enables or disabled [sendable]
11+
* @param reportActuator true to set `.actuator` to true, false to leave unspecified.
12+
*/
13+
constructor(
814
private val sendable: Sendable<*>,
915
private val enabledProvider: EnabledProvider,
1016
private val reportActuator: Boolean

core/src/main/java/com/first1444/dashboard/advanced/BasicAdvancedDashboard.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class BasicAdvancedDashboard(
2525
while(iterator.hasNext()){
2626
val (name, component) = iterator.next()
2727
if(component == activeComponent){
28-
basicDashboard.delete(name)
2928
activeComponent.onRemove()
30-
iterator.remove()
29+
basicDashboard.delete(name) // deletes the dashboard that activeComponent was using
30+
iterator.remove() // removes from componentMap
3131
return true
3232
}
3333
}

core/src/main/java/com/first1444/dashboard/advanced/SendableDashboard.kt

Lines changed: 0 additions & 9 deletions
This file was deleted.

core/src/main/java/com/first1444/dashboard/advanced/SendableHelper.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ open class SendableHelper(
1919
* Sets the dashboard type. AKA the SmartDashboard type
2020
*/
2121
@set:JvmSynthetic
22-
var dashboardType: String
22+
var type: String
2323
get() = dashboard[".type"].getter.getString("")
2424
set(value) { dashboard[".type"].strictSetter.setString(value) }
2525

26-
fun setDashboardType(value: String): SendableHelper {
27-
dashboardType = value
26+
fun setType(value: String): SendableHelper {
27+
type = value
2828
return this
2929
}
3030

core/src/main/java/com/first1444/dashboard/advanced/implementations/chooser/ChooserSendable.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ constructor(
3434

3535
override fun init(title: String, dashboard: BasicDashboard): ActiveComponent {
3636
SendableHelper(dashboard)
37-
.setDashboardType("String Chooser")
37+
.setType("String Chooser")
3838
dashboard[INSTANCE].strictSetter.setDouble(instanceNumber.toDouble())
3939

4040
return ActiveComponentMultiplexer(title, listOf(

core/src/main/java/com/first1444/dashboard/bundle/DashboardBundle.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ import com.first1444.dashboard.BasicDashboard
44
import com.first1444.dashboard.advanced.AdvancedDashboard
55
import com.first1444.dashboard.livewindow.LiveWindow
66
import com.first1444.dashboard.shuffleboard.Shuffleboard
7+
import com.first1444.dashboard.smartdashboard.SmartDashboard
78

89
interface DashboardBundle {
910
val rootDashboard: BasicDashboard
1011

1112
val shuffleboard: Shuffleboard
12-
13-
val smartDashboard: AdvancedDashboard
14-
val smartDashboardBasic: BasicDashboard
15-
13+
val smartDashboard: SmartDashboard
1614
val liveWindow: LiveWindow
1715
}

core/src/main/java/com/first1444/dashboard/bundle/DefaultDashboardBundle.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,27 @@ import com.first1444.dashboard.advanced.BasicAdvancedDashboard
66
import com.first1444.dashboard.livewindow.DefaultLiveWindow
77
import com.first1444.dashboard.livewindow.LiveWindow
88
import com.first1444.dashboard.shuffleboard.implementations.DefaultShuffleboard
9+
import com.first1444.dashboard.smartdashboard.DefaultSmartDashboard
10+
import com.first1444.dashboard.smartdashboard.SmartDashboard
911

1012
class DefaultDashboardBundle(
1113
override val rootDashboard: BasicDashboard
1214
) : ActiveDashboardBundle {
1315
override val title: String = "Default Dashboard Bundle"
1416

1517
override val shuffleboard = DefaultShuffleboard(rootDashboard)
16-
17-
override val smartDashboardBasic: BasicDashboard = rootDashboard.getSubDashboard("SmartDashboard")
18-
override val smartDashboard = BasicAdvancedDashboard("Smart Dashboard", smartDashboardBasic)
19-
20-
override val liveWindow: LiveWindow = DefaultLiveWindow(rootDashboard)
18+
override val smartDashboard = DefaultSmartDashboard(rootDashboard)
19+
override val liveWindow = DefaultLiveWindow(rootDashboard)
2120

2221
override fun update() {
2322
shuffleboard.update()
2423
smartDashboard.update()
24+
liveWindow.update()
2525
}
2626

2727
override fun onRemove() {
2828
shuffleboard.onRemove()
2929
smartDashboard.onRemove()
30+
liveWindow.onRemove()
3031
}
3132
}

core/src/main/java/com/first1444/dashboard/enable/EnabledProvider.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,12 @@ package com.first1444.dashboard.enable
22

33
interface EnabledProvider {
44
val isEnabled: Boolean
5+
6+
companion object {
7+
@JvmSynthetic
8+
operator fun invoke(lambda: () -> Boolean) = object : EnabledProvider {
9+
override val isEnabled: Boolean
10+
get() = lambda()
11+
}
12+
}
513
}
Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
package com.first1444.dashboard.livewindow
22

3+
import com.first1444.dashboard.ActiveComponent
34
import com.first1444.dashboard.BasicDashboard
4-
import com.first1444.dashboard.advanced.SendableDashboard
5+
import com.first1444.dashboard.advanced.ActuatorSendable
6+
import com.first1444.dashboard.advanced.Sendable
7+
import com.first1444.dashboard.enable.EnabledProvider
8+
import com.first1444.dashboard.enable.MutableEnabledProvider
9+
import com.first1444.dashboard.enable.SimpleEnabledProvider
510

611
class DefaultLiveWindow(
712
rootDashboard: BasicDashboard
@@ -10,20 +15,70 @@ class DefaultLiveWindow(
1015
private val statusDashboard = dashboard.getSubDashboard(".status")
1116
private val enabledEntry = statusDashboard["LW Enabled"]
1217

18+
private val map = HashMap<Sendable<*>, Pair<ActiveComponent, MutableEnabledProvider>>()
19+
20+
override val title: String = "Live Window"
1321
override var isEnabled: Boolean = false
1422
set(value) {
1523
field = value
1624
enabledEntry.strictSetter.setBoolean(value)
1725
}
18-
override val sendableDashboard: SendableDashboard
19-
get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
26+
override fun delete(key: String): Boolean {
27+
val iterator = map.iterator()
28+
while(iterator.hasNext()){
29+
val (_, pair) = iterator.next()
30+
val (activeComponent, _) = pair
31+
if(activeComponent.title == key){
32+
iterator.remove()
33+
doRemove(activeComponent)
34+
return true
35+
}
36+
}
37+
return false
38+
}
39+
40+
override fun delete(sendable: Sendable<*>): Boolean {
41+
val (activeComponent, _) = map.remove(sendable) ?: return false
42+
doRemove(activeComponent)
43+
return true
44+
}
45+
private fun doRemove(activeComponent: ActiveComponent){
46+
activeComponent.onRemove()
47+
dashboard.delete(activeComponent.title)
48+
}
49+
50+
override fun add(key: String, data: Sendable<*>): Boolean {
51+
if(data in map){
52+
return false
53+
}
54+
val sendableDashboard = dashboard.getSubDashboard(key)
55+
val telemetryProvider = SimpleEnabledProvider(false)
56+
val sendable = ActuatorSendable(data, EnabledProvider { isEnabled || telemetryProvider.isEnabled }, false)
57+
val activeComponent = sendable.init(key, sendableDashboard)
58+
map[data] = Pair(activeComponent, telemetryProvider)
59+
return true
60+
}
61+
62+
override fun setTelemetryEnabled(sendable: Sendable<*>, enabled: Boolean) {
63+
val (_, telemetryProvider) = map[sendable] ?: throw NoSuchElementException("No element found with sendable=$sendable")
64+
telemetryProvider.isEnabled = enabled
65+
}
2066

21-
override val title: String = "Live Window"
2267

2368
override fun update() {
69+
for((activeComponent, _) in map.values){
70+
activeComponent.update()
71+
}
2472
}
2573

2674
override fun onRemove() {
75+
try {
76+
for((activeComponent, _) in map.values){
77+
activeComponent.onRemove()
78+
}
79+
} finally {
80+
map.clear()
81+
}
2782
}
2883

2984
}
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.first1444.dashboard.livewindow
22

3-
import com.first1444.dashboard.advanced.SendableDashboard
3+
import com.first1444.dashboard.advanced.Sendable
44
import com.first1444.dashboard.enable.MutableEnabledProvider
55

66
interface LiveWindow : MutableEnabledProvider {
@@ -10,5 +10,18 @@ interface LiveWindow : MutableEnabledProvider {
1010
telemetry can override this for certain Sendable objects.
1111
*/
1212

13-
val sendableDashboard: SendableDashboard
13+
fun delete(key: String): Boolean
14+
fun delete(sendable: Sendable<*>): Boolean
15+
16+
/**
17+
* @return true if it was added, false otherwise
18+
*/
19+
fun add(key: String, data: Sendable<*>): Boolean
20+
21+
/**
22+
* When set to true, [sendable] will still update even if [isEnabled] is false.
23+
* @param sendable The [Sendable] to enable or disable
24+
* @param enabled true to enable telemetry, false to disable telemetry
25+
*/
26+
fun setTelemetryEnabled(sendable: Sendable<*>, enabled: Boolean)
1427
}

core/src/main/java/com/first1444/dashboard/shuffleboard/implementations/DefaultShuffleboardContainer.kt

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,17 @@ class DefaultShuffleboardContainer(
4545

4646
override fun remove(title: String): Boolean {
4747
checkRemoved()
48-
val component = componentMap[title] ?: return false
48+
val component = componentMap.remove(title) ?: return false
4949
component.onRemove()
50-
componentMap.remove(title)
50+
dashboard.delete(title) // may be removing an entry or removes a sub dashboard
51+
metadataDashboard.delete(title) // removes the sub dashboard that contains the metadata
5152
return true
5253
}
5354

5455
override fun remove(component: ActiveComponent): Boolean {
55-
checkRemoved()
56-
val iterator = componentMap.iterator()
57-
while(iterator.hasNext()){
58-
val (_, iteratorComponent) = iterator.next()
59-
if(iteratorComponent == component){
60-
iteratorComponent.onRemove()
61-
iterator.remove()
62-
return true
63-
}
64-
}
65-
return false
56+
return remove(component.title)
6657
}
6758

68-
6959
override fun update() {
7060
checkRemoved()
7161
for(component in componentMap.values){
@@ -88,6 +78,7 @@ class DefaultShuffleboardContainer(
8878
val componentMetadata = metadataDashboard.getSubDashboard(title)
8979
metadataEditor.editMetadata(componentMetadata)
9080
val r = component.init(title, dashboard, componentMetadata)
81+
check(r.title == title) { "The title of the ActiveComponent must be the same as the passed title!" }
9182
componentMap[title] = r
9283
return r
9384
}

core/src/main/java/com/first1444/dashboard/shuffleboard/implementations/ShuffleboardLayoutComponent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ShuffleboardLayoutComponent(
2121
override fun init(title: String, parentDashboard: BasicDashboard, metadataDashboard: BasicDashboard): ActiveShuffleboardContainer {
2222
val dashboard = parentDashboard.getSubDashboard(title)
2323
SendableHelper(dashboard)
24-
.setDashboardType("ShuffleboardLayout")
24+
.setType("ShuffleboardLayout")
2525
ComponentMetadataHelper(metadataDashboard)
2626
.setPreferredComponent(layoutName)
2727

core/src/main/java/com/first1444/dashboard/shuffleboard/implementations/ShuffleboardTabComponent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import com.first1444.dashboard.shuffleboard.ShuffleboardComponent
88
object ShuffleboardTabComponent : ShuffleboardComponent<ActiveShuffleboardContainer> {
99
override fun init(title: String, parentDashboard: BasicDashboard, metadataDashboard: BasicDashboard): ActiveShuffleboardContainer {
1010
val dashboard = parentDashboard.getSubDashboard(title)
11-
SendableHelper(dashboard).setDashboardType("ShuffleboardTab")
11+
SendableHelper(dashboard).setType("ShuffleboardTab")
1212
return DefaultShuffleboardContainer(title, dashboard, metadataDashboard)
1313
}
1414
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.first1444.dashboard.smartdashboard
2+
3+
import com.first1444.dashboard.ActiveComponent
4+
5+
interface ActiveSmartDashboard : SmartDashboard, ActiveComponent
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.first1444.dashboard.smartdashboard
2+
3+
import com.first1444.dashboard.BasicDashboard
4+
import com.first1444.dashboard.advanced.BasicAdvancedDashboard
5+
6+
class DefaultSmartDashboard(
7+
rootDashboard: BasicDashboard
8+
) : ActiveSmartDashboard {
9+
override val title: String = "SmartDashboard"
10+
11+
override val basicDashboard: BasicDashboard = rootDashboard.getSubDashboard("SmartDashboard")
12+
override val dashboard = BasicAdvancedDashboard("SmartDashboard", basicDashboard)
13+
14+
override fun update() {
15+
dashboard.update()
16+
}
17+
18+
override fun onRemove() {
19+
dashboard.onRemove()
20+
}
21+
22+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.first1444.dashboard.smartdashboard
2+
3+
import com.first1444.dashboard.BasicDashboard
4+
import com.first1444.dashboard.advanced.AdvancedDashboard
5+
6+
interface SmartDashboard {
7+
val dashboard: AdvancedDashboard
8+
val basicDashboard: BasicDashboard
9+
}

core/src/main/java/com/first1444/dashboard/value/implementations/PropertyActiveComponent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class PropertyActiveComponent(
1616

1717
private val listener: EntryListener? = if(property.supportsSetting){
1818
EntryListener {
19-
property.setValue(it.value!!) // TODO think about handling nulls
19+
property.setValue(it.value!!) // value shouldn't be null because we don't expect the property to be removed // We may change this in the future
2020
}
2121
} else null
2222

wpi/src/main/java/com/first1444/dashboard/wpi/NetworkTableHelper.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ val NetworkTableValue.asBasicValue: BasicValue?
1212
return null
1313
}
1414
return BasicValue(when (type) {
15-
NetworkTableType.kUnassigned -> throw AssertionError()
15+
NetworkTableType.kUnassigned -> throw AssertionError("We just checked this above!")
1616
NetworkTableType.kBoolean -> BasicValueType.BOOLEAN
1717
NetworkTableType.kDouble -> BasicValueType.DOUBLE
1818
NetworkTableType.kString -> BasicValueType.STRING

0 commit comments

Comments
 (0)