1141cc406Sopenharmony_ci/* sane - Scanner Access Now Easy.
2141cc406Sopenharmony_ci
3141cc406Sopenharmony_ci   Copyright (C) 2019 Povilas Kanapickas <povilas@radix.lt>
4141cc406Sopenharmony_ci
5141cc406Sopenharmony_ci   This file is part of the SANE package.
6141cc406Sopenharmony_ci
7141cc406Sopenharmony_ci   This program is free software; you can redistribute it and/or
8141cc406Sopenharmony_ci   modify it under the terms of the GNU General Public License as
9141cc406Sopenharmony_ci   published by the Free Software Foundation; either version 2 of the
10141cc406Sopenharmony_ci   License, or (at your option) any later version.
11141cc406Sopenharmony_ci
12141cc406Sopenharmony_ci   This program is distributed in the hope that it will be useful, but
13141cc406Sopenharmony_ci   WITHOUT ANY WARRANTY; without even the implied warranty of
14141cc406Sopenharmony_ci   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15141cc406Sopenharmony_ci   General Public License for more details.
16141cc406Sopenharmony_ci
17141cc406Sopenharmony_ci   You should have received a copy of the GNU General Public License
18141cc406Sopenharmony_ci   along with this program.  If not, see <https://www.gnu.org/licenses/>.
19141cc406Sopenharmony_ci*/
20141cc406Sopenharmony_ci
21141cc406Sopenharmony_ci#define DEBUG_DECLARE_ONLY
22141cc406Sopenharmony_ci
23141cc406Sopenharmony_ci#include "tests.h"
24141cc406Sopenharmony_ci#include "tests_printers.h"
25141cc406Sopenharmony_ci#include "minigtest.h"
26141cc406Sopenharmony_ci
27141cc406Sopenharmony_ci#include "../../../backend/genesys/low.h"
28141cc406Sopenharmony_ci#include "../../../backend/genesys/enums.h"
29141cc406Sopenharmony_ci
30141cc406Sopenharmony_cinamespace genesys {
31141cc406Sopenharmony_ci
32141cc406Sopenharmony_civoid test_create_slope_table_small_full_step()
33141cc406Sopenharmony_ci{
34141cc406Sopenharmony_ci    unsigned max_table_size = 1024;
35141cc406Sopenharmony_ci
36141cc406Sopenharmony_ci    // created approximately from LIDE 110 slow table: { 62464, 7896, 2632, 0 }
37141cc406Sopenharmony_ci    MotorSlope slope;
38141cc406Sopenharmony_ci    slope.initial_speed_w = 62464;
39141cc406Sopenharmony_ci    slope.max_speed_w = 2632;
40141cc406Sopenharmony_ci    slope.acceleration = 1.2e-8;
41141cc406Sopenharmony_ci
42141cc406Sopenharmony_ci    auto table = create_slope_table_for_speed(slope, 5000, StepType::FULL, 4, 8, max_table_size);
43141cc406Sopenharmony_ci
44141cc406Sopenharmony_ci    std::vector<std::uint16_t> expected_table = {
45141cc406Sopenharmony_ci        62464, 62464, 6420, 5000, 5000, 5000, 5000, 5000
46141cc406Sopenharmony_ci    };
47141cc406Sopenharmony_ci    ASSERT_EQ(table.table, expected_table);
48141cc406Sopenharmony_ci    ASSERT_EQ(table.table.size(), 8u);
49141cc406Sopenharmony_ci    ASSERT_EQ(table.pixeltime_sum(), 156348u);
50141cc406Sopenharmony_ci
51141cc406Sopenharmony_ci
52141cc406Sopenharmony_ci    table = create_slope_table_for_speed(slope, 3000, StepType::FULL, 4, 8, max_table_size);
53141cc406Sopenharmony_ci
54141cc406Sopenharmony_ci    expected_table = {
55141cc406Sopenharmony_ci        62464, 62464, 6420, 4552, 3720, 3223, 3000, 3000
56141cc406Sopenharmony_ci    };
57141cc406Sopenharmony_ci    ASSERT_EQ(table.table, expected_table);
58141cc406Sopenharmony_ci    ASSERT_EQ(table.table.size(), 8u);
59141cc406Sopenharmony_ci    ASSERT_EQ(table.pixeltime_sum(), 148843u);
60141cc406Sopenharmony_ci}
61141cc406Sopenharmony_ci
62141cc406Sopenharmony_civoid test_create_slope_table_small_full_step_target_speed_too_high()
63141cc406Sopenharmony_ci{
64141cc406Sopenharmony_ci    unsigned max_table_size = 1024;
65141cc406Sopenharmony_ci
66141cc406Sopenharmony_ci    // created approximately from LIDE 110 slow table: { 62464, 7896, 2632, 0 }
67141cc406Sopenharmony_ci    MotorSlope slope;
68141cc406Sopenharmony_ci    slope.initial_speed_w = 62464;
69141cc406Sopenharmony_ci    slope.max_speed_w = 2632;
70141cc406Sopenharmony_ci    slope.acceleration = 1.2e-8;
71141cc406Sopenharmony_ci
72141cc406Sopenharmony_ci    auto table = create_slope_table_for_speed(slope, 2000, StepType::FULL, 4, 8, max_table_size);
73141cc406Sopenharmony_ci
74141cc406Sopenharmony_ci    std::vector<std::uint16_t> expected_table = {
75141cc406Sopenharmony_ci        62464, 62464, 6420, 4552, 3720, 3223, 2883, 2632
76141cc406Sopenharmony_ci    };
77141cc406Sopenharmony_ci    ASSERT_EQ(table.table, expected_table);
78141cc406Sopenharmony_ci    ASSERT_EQ(table.table.size(), 8u);
79141cc406Sopenharmony_ci    ASSERT_EQ(table.pixeltime_sum(), 148358u);
80141cc406Sopenharmony_ci}
81141cc406Sopenharmony_ci
82141cc406Sopenharmony_civoid test_create_slope_table_small_half_step()
83141cc406Sopenharmony_ci{
84141cc406Sopenharmony_ci    unsigned max_table_size = 1024;
85141cc406Sopenharmony_ci
86141cc406Sopenharmony_ci    // created approximately from LIDE 110 slow table: { 62464, 7896, 2632, 0 }
87141cc406Sopenharmony_ci    MotorSlope slope;
88141cc406Sopenharmony_ci    slope.initial_speed_w = 62464;
89141cc406Sopenharmony_ci    slope.max_speed_w = 2632;
90141cc406Sopenharmony_ci    slope.acceleration = 1.2e-8;
91141cc406Sopenharmony_ci
92141cc406Sopenharmony_ci    auto table = create_slope_table_for_speed(slope, 5000, StepType::HALF, 4, 8, max_table_size);
93141cc406Sopenharmony_ci
94141cc406Sopenharmony_ci    std::vector<std::uint16_t> expected_table = {
95141cc406Sopenharmony_ci        31232, 31232, 3210, 2500, 2500, 2500, 2500, 2500
96141cc406Sopenharmony_ci    };
97141cc406Sopenharmony_ci    ASSERT_EQ(table.table, expected_table);
98141cc406Sopenharmony_ci    ASSERT_EQ(table.table.size(), 8u);
99141cc406Sopenharmony_ci    ASSERT_EQ(table.pixeltime_sum(), 78174u);
100141cc406Sopenharmony_ci
101141cc406Sopenharmony_ci
102141cc406Sopenharmony_ci    table = create_slope_table_for_speed(slope, 3000, StepType::HALF, 4, 8, max_table_size);
103141cc406Sopenharmony_ci
104141cc406Sopenharmony_ci    expected_table = {
105141cc406Sopenharmony_ci        31232, 31232, 3210, 2276, 1860, 1611, 1500, 1500
106141cc406Sopenharmony_ci    };
107141cc406Sopenharmony_ci    ASSERT_EQ(table.table, expected_table);
108141cc406Sopenharmony_ci    ASSERT_EQ(table.table.size(), 8u);
109141cc406Sopenharmony_ci    ASSERT_EQ(table.pixeltime_sum(), 74421u);
110141cc406Sopenharmony_ci}
111141cc406Sopenharmony_ci
112141cc406Sopenharmony_civoid test_create_slope_table_large_full_step()
113141cc406Sopenharmony_ci{
114141cc406Sopenharmony_ci    unsigned max_table_size = 1024;
115141cc406Sopenharmony_ci
116141cc406Sopenharmony_ci    /* created approximately from Canon 8600F table:
117141cc406Sopenharmony_ci    54612, 54612, 34604, 26280, 21708, 18688, 16564, 14936, 13652, 12616,
118141cc406Sopenharmony_ci    11768, 11024, 10400, 9872, 9392, 8960, 8584, 8240, 7940, 7648,
119141cc406Sopenharmony_ci    7404, 7160, 6948, 6732, 6544, 6376, 6208, 6056, 5912, 5776,
120141cc406Sopenharmony_ci    5644, 5520, 5408, 5292, 5192, 5092, 5000, 4908, 4820, 4736,
121141cc406Sopenharmony_ci    4660, 4580, 4508, 4440, 4368, 4304, 4240, 4184, 4124, 4068,
122141cc406Sopenharmony_ci    4012, 3960, 3908, 3860, 3808, 3764, 3720, 3676, 3636, 3592,
123141cc406Sopenharmony_ci    3552, 3516, 3476, 3440, 3400, 3368, 3332, 3300, 3268, 3236,
124141cc406Sopenharmony_ci    3204, 3176, 3148, 3116, 3088, 3060, 3036, 3008, 2984, 2956,
125141cc406Sopenharmony_ci    2932, 2908, 2884, 2860, 2836, 2816, 2796, 2772, 2752, 2732,
126141cc406Sopenharmony_ci    2708, 2692, 2672, 2652, 2632, 2616, 2596, 2576, 2560, 2544,
127141cc406Sopenharmony_ci    2528, 2508, 2492, 2476, 2460, 2444, 2432, 2416, 2400, 2384,
128141cc406Sopenharmony_ci    2372, 2356, 2344, 2328, 2316, 2304, 2288, 2276, 2260, 2252,
129141cc406Sopenharmony_ci    2236, 2224, 2212, 2200, 2188, 2176, 2164, 2156, 2144, 2132,
130141cc406Sopenharmony_ci    2120, 2108, 2100, 2088, 2080, 2068, 2056, 2048, 2036, 2028,
131141cc406Sopenharmony_ci    2020, 2008, 2000, 1988, 1980, 1972, 1964, 1952, 1944, 1936,
132141cc406Sopenharmony_ci    1928, 1920, 1912, 1900, 1892, 1884, 1876, 1868, 1860, 1856,
133141cc406Sopenharmony_ci    1848, 1840, 1832, 1824, 1816, 1808, 1800, 1796, 1788, 1780,
134141cc406Sopenharmony_ci    1772, 1764, 1760, 1752, 1744, 1740, 1732, 1724, 1720, 1712,
135141cc406Sopenharmony_ci    1708, 1700, 1692, 1688, 1680, 1676, 1668, 1664, 1656, 1652,
136141cc406Sopenharmony_ci    1644, 1640, 1636, 1628, 1624, 1616, 1612, 1608, 1600, 1596,
137141cc406Sopenharmony_ci    1592, 1584, 1580, 1576, 1568, 1564, 1560, 1556, 1548, 1544,
138141cc406Sopenharmony_ci    1540, 1536, 1528, 1524, 1520, 1516, 1512, 1508, 1500,
139141cc406Sopenharmony_ci    */
140141cc406Sopenharmony_ci    MotorSlope slope;
141141cc406Sopenharmony_ci    slope.initial_speed_w = 54612;
142141cc406Sopenharmony_ci    slope.max_speed_w = 1500;
143141cc406Sopenharmony_ci    slope.acceleration = 1.013948e-9;
144141cc406Sopenharmony_ci
145141cc406Sopenharmony_ci    auto table = create_slope_table_for_speed(slope, 3000, StepType::FULL, 4, 8, max_table_size);
146141cc406Sopenharmony_ci
147141cc406Sopenharmony_ci    std::vector<std::uint16_t> expected_table = {
148141cc406Sopenharmony_ci        54612, 54612, 20570, 15090, 12481, 10880, 9770, 8943, 8295, 7771,
149141cc406Sopenharmony_ci        7335, 6964, 6645, 6366, 6120, 5900, 5702, 5523, 5359, 5210,
150141cc406Sopenharmony_ci        5072, 4945, 4826, 4716, 4613, 4517, 4426, 4341, 4260, 4184,
151141cc406Sopenharmony_ci        4111, 4043, 3977, 3915, 3855, 3799, 3744, 3692, 3642, 3594,
152141cc406Sopenharmony_ci        3548, 3503, 3461, 3419, 3379, 3341, 3304, 3268, 3233, 3199,
153141cc406Sopenharmony_ci        3166, 3135, 3104, 3074, 3045, 3017, 3000, 3000, 3000, 3000,
154141cc406Sopenharmony_ci    };
155141cc406Sopenharmony_ci    ASSERT_EQ(table.table, expected_table);
156141cc406Sopenharmony_ci    ASSERT_EQ(table.table.size(), 60u);
157141cc406Sopenharmony_ci    ASSERT_EQ(table.pixeltime_sum(), 412616u);
158141cc406Sopenharmony_ci
159141cc406Sopenharmony_ci
160141cc406Sopenharmony_ci    table = create_slope_table_for_speed(slope, 1500, StepType::FULL, 4, 8, max_table_size);
161141cc406Sopenharmony_ci
162141cc406Sopenharmony_ci    expected_table = {
163141cc406Sopenharmony_ci        54612, 54612, 20570, 15090, 12481, 10880, 9770, 8943, 8295, 7771,
164141cc406Sopenharmony_ci        7335, 6964, 6645, 6366, 6120, 5900, 5702, 5523, 5359, 5210,
165141cc406Sopenharmony_ci        5072, 4945, 4826, 4716, 4613, 4517, 4426, 4341, 4260, 4184,
166141cc406Sopenharmony_ci        4111, 4043, 3977, 3915, 3855, 3799, 3744, 3692, 3642, 3594,
167141cc406Sopenharmony_ci        3548, 3503, 3461, 3419, 3379, 3341, 3304, 3268, 3233, 3199,
168141cc406Sopenharmony_ci        3166, 3135, 3104, 3074, 3045, 3017, 2989, 2963, 2937, 2911,
169141cc406Sopenharmony_ci        2886, 2862, 2839, 2816, 2794, 2772, 2750, 2729, 2709, 2689,
170141cc406Sopenharmony_ci        2670, 2651, 2632, 2614, 2596, 2578, 2561, 2544, 2527, 2511,
171141cc406Sopenharmony_ci        2495, 2480, 2464, 2449, 2435, 2420, 2406, 2392, 2378, 2364,
172141cc406Sopenharmony_ci        2351, 2338, 2325, 2313, 2300, 2288, 2276, 2264, 2252, 2241,
173141cc406Sopenharmony_ci        2229, 2218, 2207, 2196, 2186, 2175, 2165, 2155, 2145, 2135,
174141cc406Sopenharmony_ci        2125, 2115, 2106, 2096, 2087, 2078, 2069, 2060, 2051, 2042,
175141cc406Sopenharmony_ci        2034, 2025, 2017, 2009, 2000, 1992, 1984, 1977, 1969, 1961,
176141cc406Sopenharmony_ci        1953, 1946, 1938, 1931, 1924, 1917, 1910, 1903, 1896, 1889,
177141cc406Sopenharmony_ci        1882, 1875, 1869, 1862, 1855, 1849, 1843, 1836, 1830, 1824,
178141cc406Sopenharmony_ci        1818, 1812, 1806, 1800, 1794, 1788, 1782, 1776, 1771, 1765,
179141cc406Sopenharmony_ci        1760, 1754, 1749, 1743, 1738, 1733, 1727, 1722, 1717, 1712,
180141cc406Sopenharmony_ci        1707, 1702, 1697, 1692, 1687, 1682, 1677, 1673, 1668, 1663,
181141cc406Sopenharmony_ci        1659, 1654, 1649, 1645, 1640, 1636, 1631, 1627, 1623, 1618,
182141cc406Sopenharmony_ci        1614, 1610, 1606, 1601, 1597, 1593, 1589, 1585, 1581, 1577,
183141cc406Sopenharmony_ci        1573, 1569, 1565, 1561, 1557, 1554, 1550, 1546, 1542, 1539,
184141cc406Sopenharmony_ci        1535, 1531, 1528, 1524, 1520, 1517, 1513, 1510, 1506, 1503,
185141cc406Sopenharmony_ci        1500, 1500, 1500, 1500,
186141cc406Sopenharmony_ci    };
187141cc406Sopenharmony_ci    ASSERT_EQ(table.table, expected_table);
188141cc406Sopenharmony_ci    ASSERT_EQ(table.table.size(), 224u);
189141cc406Sopenharmony_ci    ASSERT_EQ(table.pixeltime_sum(), 734910u);
190141cc406Sopenharmony_ci}
191141cc406Sopenharmony_ci
192141cc406Sopenharmony_civoid test_create_slope_table_large_half_step()
193141cc406Sopenharmony_ci{
194141cc406Sopenharmony_ci    unsigned max_table_size = 1024;
195141cc406Sopenharmony_ci
196141cc406Sopenharmony_ci    // created approximately from Canon 8600F table, see the full step test for the data
197141cc406Sopenharmony_ci
198141cc406Sopenharmony_ci    MotorSlope slope;
199141cc406Sopenharmony_ci    slope.initial_speed_w = 54612;
200141cc406Sopenharmony_ci    slope.max_speed_w = 1500;
201141cc406Sopenharmony_ci    slope.acceleration = 1.013948e-9;
202141cc406Sopenharmony_ci
203141cc406Sopenharmony_ci    auto table = create_slope_table_for_speed(slope, 3000, StepType::HALF, 4, 8, max_table_size);
204141cc406Sopenharmony_ci
205141cc406Sopenharmony_ci    std::vector<std::uint16_t> expected_table = {
206141cc406Sopenharmony_ci        27306, 27306, 10285, 7545, 6240, 5440, 4885, 4471, 4147, 3885,
207141cc406Sopenharmony_ci        3667, 3482, 3322, 3183, 3060, 2950, 2851, 2761, 2679, 2605,
208141cc406Sopenharmony_ci        2536, 2472, 2413, 2358, 2306, 2258, 2213, 2170, 2130, 2092,
209141cc406Sopenharmony_ci        2055, 2021, 1988, 1957, 1927, 1899, 1872, 1846, 1821, 1797,
210141cc406Sopenharmony_ci        1774, 1751, 1730, 1709, 1689, 1670, 1652, 1634, 1616, 1599,
211141cc406Sopenharmony_ci        1583, 1567, 1552, 1537, 1522, 1508, 1500, 1500, 1500, 1500,
212141cc406Sopenharmony_ci    };
213141cc406Sopenharmony_ci    ASSERT_EQ(table.table, expected_table);
214141cc406Sopenharmony_ci    ASSERT_EQ(table.table.size(), 60u);
215141cc406Sopenharmony_ci    ASSERT_EQ(table.pixeltime_sum(), 206294u);
216141cc406Sopenharmony_ci
217141cc406Sopenharmony_ci
218141cc406Sopenharmony_ci    table = create_slope_table_for_speed(slope, 1500, StepType::HALF, 4, 8, max_table_size);
219141cc406Sopenharmony_ci
220141cc406Sopenharmony_ci    expected_table = {
221141cc406Sopenharmony_ci        27306, 27306, 10285, 7545, 6240, 5440, 4885, 4471, 4147, 3885,
222141cc406Sopenharmony_ci        3667, 3482, 3322, 3183, 3060, 2950, 2851, 2761, 2679, 2605,
223141cc406Sopenharmony_ci        2536, 2472, 2413, 2358, 2306, 2258, 2213, 2170, 2130, 2092,
224141cc406Sopenharmony_ci        2055, 2021, 1988, 1957, 1927, 1899, 1872, 1846, 1821, 1797,
225141cc406Sopenharmony_ci        1774, 1751, 1730, 1709, 1689, 1670, 1652, 1634, 1616, 1599,
226141cc406Sopenharmony_ci        1583, 1567, 1552, 1537, 1522, 1508, 1494, 1481, 1468, 1455,
227141cc406Sopenharmony_ci        1443, 1431, 1419, 1408, 1397, 1386, 1375, 1364, 1354, 1344,
228141cc406Sopenharmony_ci        1335, 1325, 1316, 1307, 1298, 1289, 1280, 1272, 1263, 1255,
229141cc406Sopenharmony_ci        1247, 1240, 1232, 1224, 1217, 1210, 1203, 1196, 1189, 1182,
230141cc406Sopenharmony_ci        1175, 1169, 1162, 1156, 1150, 1144, 1138, 1132, 1126, 1120,
231141cc406Sopenharmony_ci        1114, 1109, 1103, 1098, 1093, 1087, 1082, 1077, 1072, 1067,
232141cc406Sopenharmony_ci        1062, 1057, 1053, 1048, 1043, 1039, 1034, 1030, 1025, 1021,
233141cc406Sopenharmony_ci        1017, 1012, 1008, 1004, 1000, 996, 992, 988, 984, 980,
234141cc406Sopenharmony_ci        976, 973, 969, 965, 962, 958, 955, 951, 948, 944,
235141cc406Sopenharmony_ci        941, 937, 934, 931, 927, 924, 921, 918, 915, 912,
236141cc406Sopenharmony_ci        909, 906, 903, 900, 897, 894, 891, 888, 885, 882,
237141cc406Sopenharmony_ci        880, 877, 874, 871, 869, 866, 863, 861, 858, 856,
238141cc406Sopenharmony_ci        853, 851, 848, 846, 843, 841, 838, 836, 834, 831,
239141cc406Sopenharmony_ci        829, 827, 824, 822, 820, 818, 815, 813, 811, 809,
240141cc406Sopenharmony_ci        807, 805, 803, 800, 798, 796, 794, 792, 790, 788,
241141cc406Sopenharmony_ci        786, 784, 782, 780, 778, 777, 775, 773, 771, 769,
242141cc406Sopenharmony_ci        767, 765, 764, 762, 760, 758, 756, 755, 753, 751,
243141cc406Sopenharmony_ci        750, 750, 750, 750,
244141cc406Sopenharmony_ci    };
245141cc406Sopenharmony_ci    ASSERT_EQ(table.table, expected_table);
246141cc406Sopenharmony_ci    ASSERT_EQ(table.table.size(), 224u);
247141cc406Sopenharmony_ci    ASSERT_EQ(table.pixeltime_sum(), 367399u);
248141cc406Sopenharmony_ci}
249141cc406Sopenharmony_ci
250141cc406Sopenharmony_civoid test_motor()
251141cc406Sopenharmony_ci{
252141cc406Sopenharmony_ci    test_create_slope_table_small_full_step();
253141cc406Sopenharmony_ci    test_create_slope_table_small_full_step_target_speed_too_high();
254141cc406Sopenharmony_ci    test_create_slope_table_small_half_step();
255141cc406Sopenharmony_ci    test_create_slope_table_large_full_step();
256141cc406Sopenharmony_ci    test_create_slope_table_large_half_step();
257141cc406Sopenharmony_ci}
258141cc406Sopenharmony_ci
259141cc406Sopenharmony_ci} // namespace genesys
260