Go to the documentation of this file.00001
00009 package org.rosmultimedia.player.onkyo;
00010
00011 import org.rosbuilding.common.media.ISpeaker;
00012 import org.rosmultimedia.player.onkyo.eiscp.OnkyoEiscp;
00013
00014 import de.csmp.jeiscp.eiscp.EiscpCommmandsConstants;
00015 import smarthome_media_msgs.MediaAction;
00016 import smarthome_media_msgs.SpeakerInfo;
00017 import smarthome_media_msgs.StateData;
00018 import smarthome_media_msgs.ToggleMuteSpeakerRequest;
00019 import smarthome_media_msgs.ToggleMuteSpeakerResponse;
00020
00021
00028 public class OnkyoSpeaker implements ISpeaker {
00032 private OnkyoNode onkyoNode;
00033
00037 private OnkyoEiscp onkyoEiscp;
00038
00044 public OnkyoSpeaker(OnkyoEiscp onkyoEiscp, OnkyoNode onkyoNode) {
00045 this.onkyoEiscp = onkyoEiscp;
00046 this.onkyoNode = onkyoNode;
00047 }
00048
00049 @Override
00050 public void load(StateData stateData) {
00051 this.load(stateData.getSpeaker());
00052 }
00053
00054 public void load(SpeakerInfo speakerInfo) {
00055 String muted = this.onkyoEiscp.sendCommand(
00056 EiscpCommmandsConstants.AUDIO_MUTING_QUERY_ISCP);
00057 String volume = this.onkyoEiscp.sendCommand(
00058 EiscpCommmandsConstants.MASTER_VOLUME_QUERY_ISCP);
00059 String channel = this.onkyoEiscp.sendCommand(
00060 EiscpCommmandsConstants.INPUT_SELECTOR_QUERY_ISCP);
00061
00062 speakerInfo.setMuted(muted.equals(
00063 EiscpCommmandsConstants.AUDIO_MUTING_ON_ISCP));
00064
00065 int vol = 0;
00066
00067 if (volume.length() >= 0 && volume.startsWith(
00068 EiscpCommmandsConstants.MASTER_VOLUME_ISCP)) {
00069 vol = Integer.valueOf(volume.substring(volume.length() - 2), 16);
00070 }
00071
00072 speakerInfo.setLevel(vol);
00073 speakerInfo.setChannel(channel);
00074 }
00075
00076 @Override
00077 public void callbackCmdAction(MediaAction message, StateData stateData) {
00078 this.onkyoNode.logD("Onkyo Speaker launch command : "
00079 + message.getMethod());
00080
00081 switch (message.getMethod()) {
00082 case OP_MUTE:
00083 case OP_MUTE_TOGGLE:
00084 this.onkyoEiscp.sendCommand(
00085 EiscpCommmandsConstants.AUDIO_MUTING_TOGGLE_ISCP);
00086 break;
00087 case OP_VOLUME_DOWN:
00088 this.onkyoEiscp.sendCommand(
00089 EiscpCommmandsConstants.MASTER_VOLUME_LEVEL_DOWN_ISCP);
00090 break;
00091 case OP_VOLUME_UP:
00092 this.onkyoEiscp.sendCommand(
00093 EiscpCommmandsConstants.MASTER_VOLUME_LEVEL_UP_ISCP);
00094 break;
00095 case OP_VOLUME_TO:
00096 if (!message.getData().isEmpty()) {
00097 this.onkyoEiscp.sendCommand(
00098 EiscpCommmandsConstants.MASTER_VOLUME_ISCP,
00099 message.getData().get(0));
00100 }
00101 break;
00102 case OP_CHANNEL:
00103 if (!message.getData().isEmpty()) {
00104 this.onkyoEiscp.sendCommand(
00105 message.getData().get(0));
00106 }
00107 break;
00108 }
00109 }
00110
00111 @Override
00112 public void handleSpeakerMuteToggle(ToggleMuteSpeakerRequest request,
00113 ToggleMuteSpeakerResponse response) {
00114 response.setState(!this.onkyoNode.getStateData().getSpeaker().getMuted());
00115
00116 this.onkyoNode.logI(String.format("Service call %s : %s",
00117 OnkyoNode.SRV_MUTE_SPEAKER_TOGGLE,
00118 this.onkyoNode.getStateData().getSpeaker().getMuted()));
00119
00120 MediaAction message = this.onkyoNode.getConnectedNode().getTopicMessageFactory()
00121 .newFromType(MediaAction._TYPE);
00122
00123 message.setMethod(OnkyoSpeaker.OP_MUTE_TOGGLE);
00124
00125 this.callbackCmdAction(message, this.onkyoNode.getStateData());
00126 }
00127 }