Skip to content
Permalink
Browse files

Add screen mute command

This adds support to blank the screen while leaving the audio enabled.
  • Loading branch information...
rattboi committed Jan 25, 2017
1 parent 8712106 commit 307ec2000400871e7d0f7cff46b73a4186f038ef
Showing with 120 additions and 1 deletion.
  1. +15 −0 commands.proto
  2. +35 −0 message-commands.c
  3. +51 −0 serial-commands.c
  4. +9 −0 serial-commands.h
  5. +10 −1 tv-client.py
@@ -34,15 +34,30 @@ message SetInput {

message GetInput {}

enum ScreenMuteState {
SCREENMUTE_OFF = 0;
SCREENMUTE_ON = 1;
}

message SetScreenMute {
required ScreenMuteState screenmute_state = 1;
}

message GetScreenMute {}

message Command {
optional GetPower get_power = 1;
optional SetPower set_power = 2;
optional GetInput get_input = 3;
optional SetInput set_input = 4;
optional GetScreenMute get_screenmute = 5;
optional SetScreenMute set_screenmute = 6;

}

message CommandResult {
required CommandStatus command_status = 1;
optional PowerState power_state = 2;
optional InputState input_state = 3;
optional ScreenMuteState screenmute_state = 4;
}
@@ -52,6 +52,33 @@ void handle_set_input_command(InputState input_state,
reply->command_status = command_status;
}

void handle_get_screenmute_command(CommandResult *reply, int fd) {
COMMAND_STATUS command_status;
SCREENMUTE screenmute;

command_status = tv_screenmute_status(fd, &screenmute);
reply->command_status = command_status;
if (command_status == SUCCESS) {
reply->has_screenmute_state = 1;
reply->screenmute_state = screenmute;
}
}

void handle_set_screenmute_command(ScreenMuteState screenmute_state,
CommandResult *reply,
int fd
) {
COMMAND_STATUS command_status;
SCREENMUTE screenmute;

if (screenmute_state == SCREEN_MUTE_STATE__SCREENMUTE_ON) {
command_status = tv_screenmute_on(fd);
} else {
command_status = tv_screenmute_off(fd);
}
reply->command_status = command_status;
}

size_t execute_command(Command *command, uint8_t *reply_buffer, size_t reply_buffer_length, int fd) {
POWER power;
INPUT input;
@@ -76,6 +103,14 @@ size_t execute_command(Command *command, uint8_t *reply_buffer, size_t reply_buf
&reply,
fd
);
} else if (command->get_screenmute) {
handle_get_screenmute_command(&reply, fd);
} else if (command->set_screenmute) {
handle_set_screenmute_command(
command->set_screenmute->screenmute_state,
&reply,
fd
);
}

reply_length = command_result__get_packed_size(&reply);
@@ -240,3 +240,54 @@ COMMAND_STATUS tv_input_status(int fd, INPUT *input) {
return TIMEOUT;
}
}

COMMAND_STATUS tv_screenmute_on(int fd) {
const char cmd[] = "kd 0 01\r";
struct Response expected;

expected.partial_command = 'd';
expected.television_id = 0;
expected.data = 1;

return write_and_verify_command(fd, cmd, expected);
}

COMMAND_STATUS tv_screenmute_off(int fd) {
const char cmd[] = "kd 0 00\r";
struct Response expected;

expected.partial_command = 'd';
expected.television_id = 0;
expected.data = 0;

return write_and_verify_command(fd, cmd, expected);
}

COMMAND_STATUS tv_screenmute_status(int fd, SCREENMUTE *screenmute) {
const char cmd[] = "kd 0 FF\r";
char buf[32];
struct Response response;
int read_result;

write_command(fd, cmd);
read_result = timed_read(fd, buf, 32);
if (read_result) {
response = parse_response(buf);
if (status_is_okay(response)) {
if (response.data == 0) {
*screenmute = SCREENMUTE_OFF;
return SUCCESS;
} else if (response.data == 1) {
*screenmute = SCREENMUTE_ON;
return SUCCESS;
} else {
return FAILURE;
}
} else {
return FAILURE;
}
} else {
*screenmute = SCREENMUTE_OFF;
return TIMEOUT;
}
}
@@ -14,11 +14,20 @@ typedef enum {
POWER_ON = 1
} POWER;

typedef enum {
SCREENMUTE_OFF = 0,
SCREENMUTE_ON = 1,
} SCREENMUTE;

COMMAND_STATUS tv_power_on(int fd);
COMMAND_STATUS tv_power_off(int fd);
COMMAND_STATUS tv_power_status(int fd, POWER *power);

COMMAND_STATUS tv_input_set(int fd, INPUT input);
COMMAND_STATUS tv_input_status(int fd, INPUT *input);

COMMAND_STATUS tv_screenmute_on(int fd);
COMMAND_STATUS tv_screenmute_off(int fd);
COMMAND_STATUS tv_screenmute_status(int fd, SCREENMUTE *screenmute);

#endif
@@ -11,7 +11,7 @@ def parse_args():
'Send a command to the daemon controlling the television '
'and print its reponse.')
parser = argparse.ArgumentParser(description=description)
parser.add_argument('command', choices=['power', 'input'], help='Command to send')
parser.add_argument('command', choices=['power', 'input', 'screenmute'], help='Command to send')
parser.add_argument('argument', choices=['on', 'off', 'status', 'AV1', 'PC', 'HDMI1', 'HDMI2'])
parser.add_argument('--verbose', '-v', action='count', help='Log more details. Only one level currently.')
return parser.parse_args()
@@ -41,6 +41,15 @@ def build_command_message(command, argument):
elif argument in ['AV1', 'PC', 'HDMI1', 'HDMI2']:
message.set_input.SetInParent()
message.set_input.input_state = getattr(commands_pb2, argument)
elif command == 'screenmute':
if argument == 'status':
message.get_screenmute.SetInParent()
elif argument == 'on':
message.set_screenmute.SetInParent()
message.set_screenmute.screenmute_state = commands_pb2.SCREENMUTE_ON
elif argument == 'off':
message.set_screenmute.SetInParent()
message.set_screenmute.screenmute_state = commands_pb2.SCREENMUTE_OFF
return message


0 comments on commit 307ec20

Please sign in to comment.
You can’t perform that action at this time.