mirror of
https://github.com/TomHarte/CLK.git
synced 2025-02-18 16:30:29 +00:00
Causes GUI LEDs to reflect their underlying activity.
This commit is contained in:
parent
292e02702a
commit
17702bfb89
@ -28,7 +28,7 @@
|
|||||||
<constraints>
|
<constraints>
|
||||||
<constraint firstAttribute="width" secondItem="ySY-ir-hzb" secondAttribute="height" multiplier="1:1" id="UX0-hT-7Td"/>
|
<constraint firstAttribute="width" secondItem="ySY-ir-hzb" secondAttribute="height" multiplier="1:1" id="UX0-hT-7Td"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<levelIndicatorCell key="cell" alignment="left" doubleValue="1" maxValue="1" warningValue="2" criticalValue="2" levelIndicatorStyle="continuousCapacity" id="DhQ-Di-tRT"/>
|
<levelIndicatorCell key="cell" alignment="left" maxValue="1" warningValue="2" criticalValue="2" levelIndicatorStyle="continuousCapacity" id="DhQ-Di-tRT"/>
|
||||||
</levelIndicator>
|
</levelIndicator>
|
||||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Tah-UQ-vdf">
|
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Tah-UQ-vdf">
|
||||||
<rect key="frame" x="44" y="94" width="59" height="17"/>
|
<rect key="frame" x="44" y="94" width="59" height="17"/>
|
||||||
@ -43,7 +43,7 @@
|
|||||||
<constraints>
|
<constraints>
|
||||||
<constraint firstAttribute="width" secondItem="ncQ-wN-C61" secondAttribute="height" multiplier="1:1" id="176-v3-mVW"/>
|
<constraint firstAttribute="width" secondItem="ncQ-wN-C61" secondAttribute="height" multiplier="1:1" id="176-v3-mVW"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<levelIndicatorCell key="cell" alignment="left" doubleValue="1" maxValue="1" warningValue="2" criticalValue="2" levelIndicatorStyle="continuousCapacity" id="jlb-bk-FPd"/>
|
<levelIndicatorCell key="cell" alignment="left" maxValue="1" warningValue="2" criticalValue="2" levelIndicatorStyle="continuousCapacity" id="jlb-bk-FPd"/>
|
||||||
</levelIndicator>
|
</levelIndicator>
|
||||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="14O-Lq-Npx">
|
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="14O-Lq-Npx">
|
||||||
<rect key="frame" x="44" y="69" width="61" height="17"/>
|
<rect key="frame" x="44" y="69" width="61" height="17"/>
|
||||||
@ -58,7 +58,7 @@
|
|||||||
<constraints>
|
<constraints>
|
||||||
<constraint firstAttribute="width" secondItem="0rV-Th-Zwt" secondAttribute="height" multiplier="1:1" id="Ai8-b3-Nn5"/>
|
<constraint firstAttribute="width" secondItem="0rV-Th-Zwt" secondAttribute="height" multiplier="1:1" id="Ai8-b3-Nn5"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<levelIndicatorCell key="cell" alignment="left" doubleValue="1" maxValue="1" warningValue="2" criticalValue="2" levelIndicatorStyle="continuousCapacity" id="CJy-Jn-eCL"/>
|
<levelIndicatorCell key="cell" alignment="left" maxValue="1" warningValue="2" criticalValue="2" levelIndicatorStyle="continuousCapacity" id="CJy-Jn-eCL"/>
|
||||||
</levelIndicator>
|
</levelIndicator>
|
||||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Acy-tT-OFH">
|
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Acy-tT-OFH">
|
||||||
<rect key="frame" x="44" y="44" width="61" height="17"/>
|
<rect key="frame" x="44" y="44" width="61" height="17"/>
|
||||||
@ -73,7 +73,7 @@
|
|||||||
<constraints>
|
<constraints>
|
||||||
<constraint firstAttribute="width" secondItem="bvH-EJ-TYb" secondAttribute="height" multiplier="1:1" id="cKc-q1-2Q4"/>
|
<constraint firstAttribute="width" secondItem="bvH-EJ-TYb" secondAttribute="height" multiplier="1:1" id="cKc-q1-2Q4"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<levelIndicatorCell key="cell" alignment="left" doubleValue="1" maxValue="1" warningValue="2" criticalValue="2" levelIndicatorStyle="continuousCapacity" id="eoN-hl-30l"/>
|
<levelIndicatorCell key="cell" alignment="left" maxValue="1" warningValue="2" criticalValue="2" levelIndicatorStyle="continuousCapacity" id="eoN-hl-30l"/>
|
||||||
</levelIndicator>
|
</levelIndicator>
|
||||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="R0g-Oa-VB5">
|
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="R0g-Oa-VB5">
|
||||||
<rect key="frame" x="44" y="19" width="62" height="17"/>
|
<rect key="frame" x="44" y="19" width="62" height="17"/>
|
||||||
|
@ -304,7 +304,15 @@ class MachineDocument:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Activity display.
|
// MARK: Activity display.
|
||||||
fileprivate var activityLevelIndicators: [String: NSLevelIndicator] = [:]
|
class LED {
|
||||||
|
let levelIndicator: NSLevelIndicator
|
||||||
|
init(levelIndicator: NSLevelIndicator) {
|
||||||
|
self.levelIndicator = levelIndicator
|
||||||
|
}
|
||||||
|
var isLit = false
|
||||||
|
var isBlinking = false
|
||||||
|
}
|
||||||
|
fileprivate var leds: [String: LED] = [:]
|
||||||
func setupActivityDisplay() {
|
func setupActivityDisplay() {
|
||||||
var leds = machine.leds
|
var leds = machine.leds
|
||||||
if leds.count > 0 {
|
if leds.count > 0 {
|
||||||
@ -337,9 +345,39 @@ class MachineDocument:
|
|||||||
activityIndicators[c].removeFromSuperview()
|
activityIndicators[c].removeFromSuperview()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply labels.
|
// Apply labels and create leds entries.
|
||||||
for c in 0 ..< leds.count {
|
for c in 0 ..< leds.count {
|
||||||
textFields[c].stringValue = leds[c]
|
textFields[c].stringValue = leds[c]
|
||||||
|
self.leds[leds[c]] = LED(levelIndicator: activityIndicators[c])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func machine(_ machine: CSMachine, ledShouldBlink ledName: String) {
|
||||||
|
// If there is such an LED, switch it off for 0.03 of a second; if it's meant
|
||||||
|
// to be off at the end of that, leave it off. Don't allow the blinks to
|
||||||
|
// pile up — allow there to be only one in flight at a time.
|
||||||
|
if let led = leds[ledName] {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
if !led.isBlinking {
|
||||||
|
led.levelIndicator.floatValue = 0.0
|
||||||
|
led.isBlinking = true
|
||||||
|
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.03) {
|
||||||
|
led.levelIndicator.floatValue = led.isLit ? 1.0 : 0.0
|
||||||
|
led.isBlinking = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func machine(_ machine: CSMachine, led ledName: String, didChangeToLit isLit: Bool) {
|
||||||
|
// If there is such an LED, switch it appropriately.
|
||||||
|
if let led = leds[ledName] {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
led.levelIndicator.floatValue = isLit ? 1.0 : 0.0
|
||||||
|
led.isLit = isLit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
@class CSMachine;
|
@class CSMachine;
|
||||||
@protocol CSMachineDelegate
|
@protocol CSMachineDelegate
|
||||||
- (void)machineSpeakerDidChangeInputClock:(nonnull CSMachine *)machine;
|
- (void)machineSpeakerDidChangeInputClock:(nonnull CSMachine *)machine;
|
||||||
|
- (void)machine:(nonnull CSMachine *)machine led:(nonnull NSString *)led didChangeToLit:(BOOL)isLit;
|
||||||
|
- (void)machine:(nonnull CSMachine *)machine ledShouldBlink:(nonnull NSString *)led;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
typedef NS_ENUM(NSInteger, CSMachineVideoSignal) {
|
typedef NS_ENUM(NSInteger, CSMachineVideoSignal) {
|
||||||
|
@ -61,9 +61,11 @@ struct ActivityObserver: public Activity::Observer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void set_led_status(const std::string &name, bool lit) override {
|
void set_led_status(const std::string &name, bool lit) override {
|
||||||
|
[machine.delegate machine:machine led:[NSString stringWithUTF8String:name.c_str()] didChangeToLit:lit];
|
||||||
}
|
}
|
||||||
|
|
||||||
void announce_drive_event(const std::string &name, DriveEvent event) override {
|
void announce_drive_event(const std::string &name, DriveEvent event) override {
|
||||||
|
[machine.delegate machine:machine ledShouldBlink:[NSString stringWithUTF8String:name.c_str()]];
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_drive_motor_status(const std::string &name, bool is_on) override {
|
void set_drive_motor_status(const std::string &name, bool is_on) override {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user