From ca01e2e6e69fd702ed2f4cf56d6323593bea3278 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 12 Nov 2019 12:34:14 +0100 Subject: Add test IO --- Kod/bilbana/yc4/display/get_package.m | 10 ++------ Kod/bilbana/yc4/display/get_response.m | 34 ++++++++++++++++++++++++++ Kod/bilbana/yc4/display/get_smallpackage.m | 8 ++++++ Kod/bilbana/yc4/display/send_data_to_display.m | 4 +++ 4 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 Kod/bilbana/yc4/display/get_response.m create mode 100644 Kod/bilbana/yc4/display/get_smallpackage.m (limited to 'Kod/bilbana/yc4/display') diff --git a/Kod/bilbana/yc4/display/get_package.m b/Kod/bilbana/yc4/display/get_package.m index 7c3a01e..efaf311 100644 --- a/Kod/bilbana/yc4/display/get_package.m +++ b/Kod/bilbana/yc4/display/get_package.m @@ -1,10 +1,4 @@ -function [pkg] = get_package(code, args) - DC1 = 17; +function pkg = get_package(code, args) ESC = 27; - - data = [ESC, double(code), args]; - len = length(data); - initStr = [DC1, len, data]; - bcc = mod(sum(initStr), 256); - pkg = [initStr, bcc]; + pkg = [ESC, double(code), args]; end diff --git a/Kod/bilbana/yc4/display/get_response.m b/Kod/bilbana/yc4/display/get_response.m new file mode 100644 index 0000000..9714a43 --- /dev/null +++ b/Kod/bilbana/yc4/display/get_response.m @@ -0,0 +1,34 @@ +function [ack, start_code, data] get_response(display_data) +% GET RESPONSE +% In-depth explanation +% [flag, display_data] = matlabclient(2) + +ack = false; +start_code = ''; +data = []; + +len = -1; + +if display_data[0] == 6 + ack = true; +else + return +end + +display_data[0] = []; + +if display_data[0] == 17 + start_code = 'DC1'; +elseif display_data[0] == 18 + start_code = 'DC2'; +end + +display_data[0] = []; + +len = display_data[0]; + +while len > 0 + +end + +end diff --git a/Kod/bilbana/yc4/display/get_smallpackage.m b/Kod/bilbana/yc4/display/get_smallpackage.m new file mode 100644 index 0000000..1c0835c --- /dev/null +++ b/Kod/bilbana/yc4/display/get_smallpackage.m @@ -0,0 +1,8 @@ +function pkg = get_smallpackage(data) + DC1 = 17; + + len = length(data); + initStr = [DC1, len, data]; + bcc = mod(sum(initStr), 256); + pkg = [initStr, bcc]; +end diff --git a/Kod/bilbana/yc4/display/send_data_to_display.m b/Kod/bilbana/yc4/display/send_data_to_display.m index c5d70c7..50af84f 100644 --- a/Kod/bilbana/yc4/display/send_data_to_display.m +++ b/Kod/bilbana/yc4/display/send_data_to_display.m @@ -20,6 +20,10 @@ function [] = send_data_to_display() %% SEND DATA % disp('sending data'); % disp(display_data) + + data = []; + + matlabclient(1, display_data{1}); last_send = clock; display_data(1) = []; -- cgit v1.2.1 From f735459829046e9e2a9911d8cf31546a5bebefee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 12 Nov 2019 12:34:58 +0100 Subject: fix func name --- Kod/bilbana/yc4/display/define_touch_switch.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Kod/bilbana/yc4/display') diff --git a/Kod/bilbana/yc4/display/define_touch_switch.m b/Kod/bilbana/yc4/display/define_touch_switch.m index 47d3cd9..4dfc764 100644 --- a/Kod/bilbana/yc4/display/define_touch_switch.m +++ b/Kod/bilbana/yc4/display/define_touch_switch.m @@ -1,4 +1,4 @@ -function pkg = define_touch_key(x1, y1, x2, y2, down_code, up_code, just, text) +function pkg = define_touch_switch(x1, y1, x2, y2, down_code, up_code, just, text) arg_location = [get_bytes(x1), get_bytes(y1), get_bytes(x2), get_bytes(y2)]; arg_text = double(strjoin({just; text}, '')); arg_null = 0; -- cgit v1.2.1 From 83c1ee0a3f2d57d887d38fafb74f4967271c4a84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Thor=C3=A9n?= Date: Wed, 13 Nov 2019 12:32:01 +0100 Subject: Add function to convert bytes -> num --- Kod/bilbana/yc4/display/get_num.m | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Kod/bilbana/yc4/display/get_num.m (limited to 'Kod/bilbana/yc4/display') diff --git a/Kod/bilbana/yc4/display/get_num.m b/Kod/bilbana/yc4/display/get_num.m new file mode 100644 index 0000000..e90e0c7 --- /dev/null +++ b/Kod/bilbana/yc4/display/get_num.m @@ -0,0 +1,3 @@ +function num = get_num(bytes) +num = bytes(1) + bytes(2) * 256; +end \ No newline at end of file -- cgit v1.2.1 From 2f0a6f442b8103a95839f0e37d5689ca9cf0fe71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Thor=C3=A9n?= Date: Wed, 13 Nov 2019 12:32:46 +0100 Subject: Working communication from display --- Kod/bilbana/yc4/display/get_response.m | 47 +++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 15 deletions(-) (limited to 'Kod/bilbana/yc4/display') diff --git a/Kod/bilbana/yc4/display/get_response.m b/Kod/bilbana/yc4/display/get_response.m index 9714a43..1e3e6af 100644 --- a/Kod/bilbana/yc4/display/get_response.m +++ b/Kod/bilbana/yc4/display/get_response.m @@ -1,34 +1,51 @@ -function [ack, start_code, data] get_response(display_data) +function [ack, start_code, responses] = get_response(display_data) % GET RESPONSE % In-depth explanation % [flag, display_data] = matlabclient(2) ack = false; start_code = ''; -data = []; +bcc = display_data(length(display_data)); +responses = []; -len = -1; +pointer = 1; -if display_data[0] == 6 +if display_data(pointer) == 6 ack = true; else return end -display_data[0] = []; +if pointer > length(display_data) + return +end -if display_data[0] == 17 +pointer = pointer + 1; +if display_data(1) == 17 start_code = 'DC1'; -elseif display_data[0] == 18 +elseif display_data(1) == 18 start_code = 'DC2'; end -display_data[0] = []; - -len = display_data[0]; - -while len > 0 - -end - +pointer = pointer + 1; +% total length + +data = struct; +while pointer < length(display_data) - 1 % last value is bcc + pointer = pointer + 1; + if display_data(pointer) ~= 27 + % TODO: no ESC? + end + pointer = pointer + 1; + data.id = char(display_data(pointer)); + + pointer = pointer + 1; + data.length = display_data(pointer); + if data.id == 'A' + pointer = pointer + 1; + data.data = display_data(pointer); + else + pointer = pointer + data.length; + end + responses = [responses, data]; end -- cgit v1.2.1