NXT/Constants.pm

filter: Statementstmt 100% 101 / 101 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 104 / 104 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« NXT/BlueComm.pm ↑ Summary
1 # vim: sts=2 sw=2
2 package LEGO::NXT::Constants;
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 our @EXPORT;
9  
10 =head1 NAME
11  
12 LEGO::NXT::Constants - Low-level constants for the Direct Commands API.
13  
14 =head1 SYNOPSIS
15  
16 use LEGO::NXT::Constants;
17  
18 =head1 DESCRIPTION
19  
20 This module exports a bunch of constants in to your namespace for you to
21 use with the various low-level methods in the L<LEGO::NXT> module.
22  
23 =head1 CONSTANTS
24  
25 All of the following constants are exported in to your namespace by
26 default.
27  
28 =head2 RET and NORET
29  
30 For each request of the NXT, you must specify whether you want the NXT to
31 send a return value.
32  
33 $NXT_RET
34 $NXT_NORET
35  
36 Use $NXT_RET only when you really need a return value as it does have some
37 overhead because it has do do a second request to retrieve response
38 data from NXT and then parses that data.
39  
40 =cut
41  
42 1 our $NXT_RET = 0x00;
43 1 our $NXT_NORET = 0x80;
44 1 our $NXT_SYSOP = 0x01;
45  
46 1 push @EXPORT, qw( $NXT_RET $NXT_NORET $NXT_SYSOP );
47  
48 =head2 IO Port
49  
50 $NXT_SENSOR1
51 $NXT_SENSOR2
52 $NXT_SENSOR3
53 $NXT_SENSOR4
54
55 $NXT_MOTOR_A
56 $NXT_MOTOR_B
57 $NXT_MOTOR_C
58 $NXT_MOTOR_ALL
59  
60 =cut
61  
62 1 our $NXT_SENSOR_1 = 0x00;
63 1 our $NXT_SENSOR_2 = 0x01;
64 1 our $NXT_SENSOR_3 = 0x02;
65 1 our $NXT_SENSOR_4 = 0x03;
66  
67 1 our $NXT_MOTOR_A = 0x00;
68 1 our $NXT_MOTOR_B = 0x01;
69 1 our $NXT_MOTOR_C = 0x02;
70 1 our $NXT_MOTOR_ALL = 0xFF;
71  
72 1 push @EXPORT, qw(
73 $NXT_SENSOR_1 $NXT_SENSOR_2 $NXT_SENSOR_3 $NXT_SENSOR_4
74 $NXT_MOTOR_A $NXT_MOTOR_B $NXT_MOTOR_C $NXT_MOTOR_ALL
75 );
76  
77 =head2 Motor Control
78  
79 Output mode:
80  
81 $NXT_MOTOR_ON
82 $NXT_BRAKE
83 $NXT_REGULATED
84  
85 Output regulation modes:
86  
87 $NXT_REGULATION_MODE_IDLE
88 $NXT_REGULATION_MODE_MOTOR_SPEED
89 $NXT_REGULATION_MODE_MOTOR_SYNC
90  
91 Output run states:
92  
93 $NXT_MOTOR_RUN_STATE_IDLE
94 $NXT_MOTOR_RUN_STATE_RAMPUP
95 $NXT_MOTOR_RUN_STATE_RUNNING
96 $NXT_MOTOR_RUN_STATE_RAMPDOWN
97  
98 =cut
99  
100 1 our $NXT_MOTOR_ON = 0x01;
101 1 our $NXT_BRAKE = 0x02;
102 1 our $NXT_REGULATED = 0x04;
103  
104 1 our $NXT_REGULATION_MODE_IDLE = 0x00;
105 1 our $NXT_REGULATION_MODE_MOTOR_SPEED = 0x01;
106 1 our $NXT_REGULATION_MODE_MOTOR_SYNC = 0x02;
107  
108 1 our $NXT_MOTOR_RUN_STATE_IDLE = 0x00;
109 1 our $NXT_MOTOR_RUN_STATE_RAMPUP = 0x10;
110 1 our $NXT_MOTOR_RUN_STATE_RUNNING = 0x20;
111 1 our $NXT_MOTOR_RUN_STATE_RAMPDOWN = 0x40;
112  
113 1 push @EXPORT, qw(
114 $NXT_MOTOR_ON $NXT_BRAKE $NXT_REGULATED
115 $NXT_REGULATION_MODE_IDLE $NXT_REGULATION_MODE_MOTOR_SPEED $NXT_REGULATION_MODE_MOTOR_SYNC
116 $NXT_MOTOR_RUN_STATE_IDLE $NXT_MOTOR_RUN_STATE_RAMPUP $NXT_MOTOR_RUN_STATE_RUNNING $NXT_MOTOR_RUN_STATE_RAMPDOWN
117 );
118  
119 =head2 Sensor Type
120  
121 $NXT_NO_SENSOR
122 $NXT_SWITCH
123 $NXT_TEMPERATURE
124 $NXT_REFLECTION
125 $NXT_ANGLE
126 $NXT_LIGHT_ACTIVE
127 $NXT_LIGHT_INACTIVE
128 $NXT_SOUND_DB
129 $NXT_SOUND_DBA
130 $NXT_CUSTOM
131 $NXT_LOW_SPEED
132 $NXT_LOW_SPEED_9V
133 $NXT_NO_OF_SENSOR_TYPES
134  
135 =cut
136  
137 1 our $NXT_NO_SENSOR = 0x00;
138 1 our $NXT_SWITCH = 0x01;
139 1 our $NXT_TEMPERATURE = 0x02;
140 1 our $NXT_REFLECTION = 0x03;
141 1 our $NXT_ANGLE = 0x04;
142 1 our $NXT_LIGHT_ACTIVE = 0x05;
143 1 our $NXT_LIGHT_INACTIVE = 0x06;
144 1 our $NXT_SOUND_DB = 0x07;
145 1 our $NXT_SOUND_DBA = 0x08;
146 1 our $NXT_CUSTOM = 0x09;
147 1 our $NXT_LOW_SPEED = 0x0A;
148 1 our $NXT_LOW_SPEED_9V = 0x0B;
149 1 our $NXT_NO_OF_SENSOR_TYPES = 0x0C;
150  
151 1 push @EXPORT, qw(
152 $NXT_NO_SENSOR $NXT_SWITCH $NXT_TEMPERATURE $NXT_REFLECTION $NXT_ANGLE
153 $NXT_LIGHT_ACTIVE $NXT_LIGHT_INACTIVE $NXT_SOUND_DB $NXT_SOUND_DBA
154 $NXT_CUSTOM $NXT_LOW_SPEED $NXT_LOW_SPEED_9V $NXT_NO_OF_SENSOR_TYPES
155 );
156  
157 =head2 Sensor Mode
158  
159 $NXT_RAW_MODE
160 $NXT_BOOLEAN_MODE
161 $NXT_TRANSITION_CNT_MODE
162
163 $NXT_PERIOD_COUNTER_MODE
164 $NXT_PCT_FULL_SCALE_MODE
165
166 $NXT_CELSIUS_MODE
167 $NXT_FAHRENHEIT_MODE
168
169 $NXT_ANGLE_STEPS_MODE
170 $NXT_SLOPE_MASK
171 $NXT_MODE_MASK
172  
173 =cut
174  
175 1 our $NXT_RAW_MODE = 0x00;
176 1 our $NXT_BOOLEAN_MODE = 0x20;
177 1 our $NXT_TRANSITION_CNT_MODE = 0x40;
178  
179 1 our $NXT_PERIOD_COUNTER_MODE = 0x60;
180 1 our $NXT_PCT_FULL_SCALE_MODE = 0x80;
181  
182 1 our $NXT_CELSIUS_MODE = 0xA0;
183 1 our $NXT_FAHRENHEIT_MODE = 0xC0;
184  
185 1 our $NXT_ANGLE_STEPS_MODE = 0xE0;
186 1 our $NXT_SLOPE_MASK = 0x1F;
187 1 our $NXT_MODE_MASK = 0xE0;
188  
189 1 push @EXPORT, qw(
190 $NXT_RAW_MODE $NXT_BOOLEAN_MODE $NXT_TRANSITION_CNT_MODE
191 $NXT_PERIOD_COUNTER_MODE $NXT_PCT_FULL_SCALE_MODE
192 $NXT_CELSIUS_MODE $NXT_FAHRENHEIT_MODE
193 $NXT_ANGLE_STEPS_MODE $NXT_SLOPE_MASK $NXT_MODE_MASK
194 );
195  
196 =head2 Op Codes
197  
198 Generally you will not need to use these constants
199 since L<LEGO::NXT> provides easy to use wrappers around
200 all of these actions.
201  
202 $NXT_START_PROGRAM
203 $NXT_STOP_PROGRAM
204 $NXT_PLAY_SOUND_FILE
205 $NXT_PLAY_TONE
206 $NXT_SET_OUTPUT_STATE
207 $NXT_SET_INPUT_MODE
208 $NXT_GET_OUTPUT_STATE
209 $NXT_GET_INPUT_VALUES
210 $NXT_RESET_SCALED_INPUT_VALUE
211 $NXT_MESSAGE_WRITE
212 $NXT_RESET_MOTOR_POSITION
213 $NXT_GET_BATTERY_LEVEL
214 $NXT_STOP_SOUND_PLAYBACK
215 $NXT_KEEP_ALIVE
216 $NXT_LSGET_STATUS
217 $NXT_LSWRITE
218 $NXT_LSREAD
219 $NXT_GET_CURRENT_PROGRAM_NAME
220 $NXT_MESSAGE_READ
221  
222 =cut
223  
224 1 our $NXT_START_PROGRAM = 0x00;
225 1 our $NXT_STOP_PROGRAM = 0x01;
226 1 our $NXT_PLAY_SOUND_FILE = 0x02;
227 1 our $NXT_PLAY_TONE = 0x03;
228 1 our $NXT_SET_OUTPUT_STATE = 0x04;
229 1 our $NXT_SET_INPUT_MODE = 0x05;
230 1 our $NXT_GET_OUTPUT_STATE = 0x06;
231 1 our $NXT_GET_INPUT_VALUES = 0x07;
232 1 our $NXT_RESET_SCALED_INPUT_VALUE = 0x08;
233 1 our $NXT_MESSAGE_WRITE = 0x09;
234 1 our $NXT_RESET_MOTOR_POSITION = 0x0A;
235 1 our $NXT_GET_BATTERY_LEVEL = 0x0B;
236 1 our $NXT_STOP_SOUND_PLAYBACK = 0x0C;
237 1 our $NXT_KEEP_ALIVE = 0x0D;
238 1 our $NXT_LSGET_STATUS = 0x0E;
239 1 our $NXT_LSWRITE = 0x0F;
240 1 our $NXT_LSREAD = 0x10;
241 1 our $NXT_GET_CURRENT_PROGRAM_NAME = 0x11;
242 1 our $NXT_MESSAGE_READ = 0x13;
243  
244 1 push @EXPORT, qw(
245 $NXT_START_PROGRAM $NXT_STOP_PROGRAM
246 $NXT_PLAY_SOUND_FILE $NXT_PLAY_TONE
247 $NXT_SET_OUTPUT_STATE $NXT_SET_INPUT_MODE $NXT_GET_OUTPUT_STATE
248 $NXT_GET_INPUT_VALUES $NXT_RESET_SCALED_INPUT_VALUE $NXT_MESSAGE_WRITE
249 $NXT_RESET_MOTOR_POSITION $NXT_GET_BATTERY_LEVEL $NXT_STOP_SOUND_PLAYBACK
250 $NXT_KEEP_ALIVE $NXT_LSGET_STATUS $NXT_LSWRITE $NXT_LSREAD
251 $NXT_GET_CURRENT_PROGRAM_NAME $NXT_MESSAGE_READ
252 );
253  
254 =head2 SYS OPCODES
255  
256 $NXT_SYS_OPEN_READ
257 $NXT_SYS_OPEN_WRITE
258 $NXT_SYS_READ
259 $NXT_SYS_WRITE
260 $NXT_SYS_CLOSE
261 $NXT_SYS_DELETE
262 $NXT_SYS_FIND_FIRST
263 $NXT_SYS_FIND_NEXT
264 $NXT_SYS_GET_FIRMWARE_VERSION
265 $NXT_SYS_OPEN_WRITE_LINEAR
266 $NXT_SYS_OPEN_READ_LINEAR
267 $NXT_SYS_OPEN_WRITE_DATA
268 $NXT_SYS_OPEN_APPEND_DATA
269 $NXT_SYS_BOOT
270 $NXT_SYS_SET_BRICK_NAME
271 $NXT_SYS_GET_DEVICE_INFO
272 $NXT_SYS_DELETE_USER_FLASH
273 $NXT_SYS_POLL_COMMAND_LENGTH
274 $NXT_SYS_POLL_COMMAND
275 $NXT_SYS_BLUETOOTH_FACTORY_RESET
276  
277 =cut
278  
279 1 our $NXT_SYS_OPEN_READ = 0x80;
280 1 our $NXT_SYS_OPEN_WRITE = 0x81;
281 1 our $NXT_SYS_READ = 0x82;
282 1 our $NXT_SYS_WRITE = 0x83;
283 1 our $NXT_SYS_CLOSE = 0x84;
284 1 our $NXT_SYS_DELETE = 0x85;
285 1 our $NXT_SYS_FIND_FIRST = 0x86;
286 1 our $NXT_SYS_FIND_NEXT = 0x87;
287 1 our $NXT_SYS_GET_FIRMWARE_VERSION = 0x88;
288 1 our $NXT_SYS_OPEN_WRITE_LINEAR = 0x89;
289 1 our $NXT_SYS_OPEN_READ_LINEAR = 0x8A;
290 1 our $NXT_SYS_OPEN_WRITE_DATA = 0x8B;
291 1 our $NXT_SYS_OPEN_APPEND_DATA = 0x8C;
292 1 our $NXT_SYS_BOOT = 0x97;
293 1 our $NXT_SYS_SET_BRICK_NAME = 0x98;
294 1 our $NXT_SYS_GET_DEVICE_INFO = 0x9B;
295 1 our $NXT_SYS_DELETE_USER_FLASH = 0xA0;
296 1 our $NXT_SYS_POLL_COMMAND_LENGTH = 0xA1;
297 1 our $NXT_SYS_POLL_COMMAND = 0xA2;
298 1 our $NXT_SYS_BLUETOOTH_FACTORY_RESET = 0xA4;
299  
300 1 push @EXPORT, qw(
301 $NXT_SYS_OPEN_READ
302 $NXT_SYS_OPEN_WRITE
303 $NXT_SYS_READ
304 $NXT_SYS_WRITE
305 $NXT_SYS_CLOSE
306 $NXT_SYS_DELETE
307 $NXT_SYS_FIND_FIRST
308 $NXT_SYS_FIND_NEXT
309 $NXT_SYS_GET_FIRMWARE_VERSION
310 $NXT_SYS_OPEN_WRITE_LINEAR
311 $NXT_SYS_OPEN_READ_LINEAR
312 $NXT_SYS_OPEN_WRITE_DATA
313 $NXT_SYS_OPEN_APPEND_DATA
314 $NXT_SYS_BOOT
315 $NXT_SYS_SET_BRICK_NAME
316 $NXT_SYS_GET_DEVICE_INFO
317 $NXT_SYS_DELETE_USER_FLASH
318 $NXT_SYS_POLL_COMMAND_LENGTH
319 $NXT_SYS_POLL_COMMAND
320 $NXT_SYS_BLUETOOTH_FACTORY_RESET
321 );
322  
323 1 1;
324  
325 __END__
« NXT/BlueComm.pm ↑ Summary