From 7aed3640c478389632a502f12f9f864ba78e9a3d Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 21 Jul 2017 03:39:25 +1000 Subject: [PATCH] tools: ratbagctl: hook up report rate argparsing Signed-off-by: Peter Hutterer --- tools/ratbagctl.in | 47 +++++++++++++++++++++++++++++++++++++++++ tools/ratbagctl.test.in | 37 ++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/tools/ratbagctl.in b/tools/ratbagctl.in index 2c486f61..348494c6 100755 --- a/tools/ratbagctl.in +++ b/tools/ratbagctl.in @@ -301,6 +301,16 @@ def func_dpi_set(r, args): r.resolution = (args.dpi_n, args.dpi_n) +def func_report_rate_get(r, args): + r, p, d = find_resolution(r, args) + print(r.report_rate) + + +def func_report_rate_set(r, args): + r, p, d = find_resolution(r, args) + r.report_rate = args.rate_n + + def func_resolution_get(r, args): r, p, d = find_resolution(r, args) print_resolution(d, p, r, 0) @@ -508,6 +518,10 @@ parser_def = [ of_type: link, dest: 'dpi', }, + { + of_type: link, + dest: 'rate', + }, { of_type: link, dest: 'button', @@ -570,6 +584,10 @@ parser_def = [ of_type: link, dest: 'dpi', }, + { + of_type: link, + dest: 'rate', + }, ], }, }, @@ -602,6 +620,35 @@ parser_def = [ }, ], }, + { + of_type: switch, + name: 'rate', + help_str: 'Access report rate information', + tag: 'rate', + switch: [ + { + of_type: command, + name: 'get', + help_str: 'Show current report rate', + func: func_report_rate_get, + }, + { + of_type: command, + name: 'set', + help_str: 'Set the report rate to N', + pos_args: [ + { + of_type: argument, + name: 'rate_n', + metavar: 'N', + help_str: 'The report rate to set as current', + arg_type: int, + }, + ], + func: func_report_rate_set, + }, + ], + }, { of_type: switch, name: 'button', diff --git a/tools/ratbagctl.test.in b/tools/ratbagctl.test.in index 656fdd9a..57a7b9c1 100755 --- a/tools/ratbagctl.test.in +++ b/tools/ratbagctl.test.in @@ -276,6 +276,43 @@ class TestRatbgagCtlDPI(TestRatbagCtl): self.launch_fail_test("Profile 1 Resolution 1 Resolution 2 DPI get test_device") +class TestRatbgagCtlReportRate(TestRatbagCtl): + @classmethod + def setUpClass(cls): + super(TestRatbgagCtlReportRate, cls).setUpClass() + cls.setProfile(0) + + def test_rate_get(self): + command = "rate get" + r = self.launch_good_test(command + " test_device") + self.assertEqual(int(r), 1000) + self.launch_fail_test(command) + self.launch_fail_test(command + " 1 test_device") + self.launch_fail_test(command + " test_device X") + + def test_rate_set(self): + command = "rate set" + r = self.launch_good_test("rate get test_device") + res = int(r) + 500 + r = self.launch_good_test(command + " {} test_device".format(res)) + self.assertEqual(r, '') + r = self.launch_good_test("rate get test_device") + self.assertEqual(int(r), res) + self.launch_fail_test(command) + self.launch_fail_test(command + " X test_device") + self.launch_fail_test(command + " 100 test_device X") + + def test_prefix_rate(self): + r = self.launch_good_test("Profile 1 rate get test_device") + self.assertEqual(int(r), 2000) + r = self.launch_good_test("Profile 1 Resolution 1 rate get test_device") + self.assertEqual(int(r), 2000) + r = self.launch_good_test("Resolution 2 rate get test_device") + self.assertEqual(int(r), 1000) + self.launch_fail_test("Profile 1 Profile 1 rate get test_device") + self.launch_fail_test("Profile 1 Resolution 1 Resolution 2 rate get test_device") + + class TestRatbgagCtlButton(TestRatbagCtl): @classmethod def setUpClass(cls):