@dotpi/tools 2.6.0 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/.history/dotpi_root/dist/@dotpi/javascript/index_20250224110150.js +0 -0
  2. package/.history/dotpi_root/dist/@dotpi/javascript/index_20250429123336.js +6 -0
  3. package/.history/dotpi_root/dist/@dotpi/javascript/package_20250224111859.json +15 -0
  4. package/.history/dotpi_root/dist/@dotpi/javascript/package_20250429101520.json +16 -0
  5. package/.history/dotpi_root/share/dotpi_functions/dotpi_functions_audio_device_20250117162542.bash +556 -0
  6. package/.history/dotpi_root/share/dotpi_functions/dotpi_functions_audio_device_20250428182930.bash +556 -0
  7. package/.history/dotpi_root/share/dotpi_functions/dotpi_functions_audio_device_20250428183019.bash +561 -0
  8. package/.history/dotpi_root/share/dotpi_functions/dotpi_functions_audio_device_20250428183434.bash +563 -0
  9. package/.history/dotpi_root/share/dotpi_functions/dotpi_functions_audio_device_20250428183737.bash +563 -0
  10. package/.history/dotpi_root/share/dotpi_functions/dotpi_functions_audio_device_20250428183826.bash +563 -0
  11. package/.history/test/utils.spec_20241114125309.js +48 -0
  12. package/.history/test/utils.spec_20250428183107.js +50 -0
  13. package/.history/test/utils.spec_20250428183349.js +50 -0
  14. package/.history/test/utils.spec_20250428183620.js +49 -0
  15. package/.history/test/utils.spec_20250428183631.js +50 -0
  16. package/.history/test/utils.spec_20250428183753.js +50 -0
  17. package/.history/test/utils.spec_20250428183813.js +50 -0
  18. package/dotpi_root/dist/@dotpi/avahi-monitor-module/package.json +1 -2
  19. package/dotpi_root/dist/@dotpi/javascript/index.js +6 -0
  20. package/dotpi_root/dist/@dotpi/javascript/package.json +7 -2
  21. package/dotpi_root/dist/@dotpi/module/package.json +3 -3
  22. package/dotpi_root/dist/@dotpi/module-module/package.json +5 -4
  23. package/dotpi_root/etc/dotpi_modules.json +2 -1
  24. package/dotpi_root/share/dotpi_functions/dotpi_functions_audio_device.bash +25 -18
  25. package/package.json +3 -3
  26. package/test/utils.spec.js +15 -13
  27. /package/dotpi_root/dist/@dotpi/{avahi-monitor-module → javascript}/LICENSE +0 -0
@@ -0,0 +1,563 @@
1
+ #!/bin/bash
2
+
3
+ dotpi_audio_device_supported=(
4
+ 'default'
5
+ 'none'
6
+ 'headphones'
7
+ 'bluetooth'
8
+ 'hifiberry amp+'
9
+ 'hifiberry amp2'
10
+ 'hifiberry amp3'
11
+ 'hifiberry amp4 pro'
12
+ 'hifiberry amp4'
13
+ 'hifiberry beocreate'
14
+ 'hifiberry dac for raspberry pi 1'
15
+ 'hifiberry dac zero'
16
+ 'hifiberry dac+ adc pro'
17
+ 'hifiberry dac+ adc'
18
+ 'hifiberry dac+ dsp'
19
+ 'hifiberry dac+ light'
20
+ 'hifiberry dac+ rtc'
21
+ 'hifiberry dac+ standard'
22
+ 'hifiberry dac2 hd'
23
+ 'hifiberry digi+ pro'
24
+ 'hifiberry digi+'
25
+ 'hifiberry miniamp'
26
+ 'hifiberry pro'
27
+ 'iqaudio codec zero'
28
+ 'iqaudio dac pro'
29
+ 'iqaudio dac+'
30
+ 'iqaudio digiamp+'
31
+ 'raspberry pi codec zero'
32
+ 'raspberry pi dac pro'
33
+ 'raspberry pi dac+'
34
+ 'raspberry pi digiamp+'
35
+ 'ue boom 2'
36
+ 'ue boom 3'
37
+ 'ue megaboom 2'
38
+ 'ue megaboom 3'
39
+ )
40
+
41
+ dotpi_audio_device_is_analog() {
42
+ audio_device="${1:-$dotpi_audio_device}"
43
+ case "$audio_device" in
44
+ 'headphones')
45
+ return 0
46
+ ;;
47
+ *)
48
+ return 1
49
+ ;;
50
+ esac
51
+ }
52
+
53
+ _dotpi_audio_device_get_options() {
54
+
55
+ _echo_empty_option_error() {
56
+ dotpi_echo_error "$1 requires a non-empty option argument."
57
+ }
58
+
59
+ # From http://mywiki.wooledge.org/BashFAQ/035
60
+
61
+ while true ; do
62
+ case $1 in
63
+
64
+ -h|-\?|--help)
65
+ _dotpi_usage # Display a usage synopsis.
66
+ return 0
67
+ ;;
68
+
69
+ -m|--model) # Takes an option argument; ensure it has been specified.
70
+ if [ -z "$2" ] ; then
71
+ _dotpi_usage
72
+ _echo_empty_option_error "$1"
73
+ return 1
74
+ else
75
+ model="$2"
76
+ shift
77
+ fi
78
+ ;;
79
+
80
+ -c|--config) # Takes an option argument; ensure it has been specified.
81
+ if [ -z "$2" ] ; then
82
+ _dotpi_usage
83
+ _echo_empty_option_error "$1"
84
+ return 1
85
+ else
86
+ config_file="$2"
87
+ shift
88
+ fi
89
+ ;;
90
+
91
+ --) # End of all options.
92
+ shift
93
+ break
94
+ ;;
95
+
96
+ -?*) # Unknown
97
+ _dotpi_usage
98
+ dotpi_echo_error "Unknown option: $1"
99
+ return 1
100
+ ;;
101
+
102
+ *) # Default case: No more options, so break out of the loop.
103
+ break
104
+
105
+ esac
106
+
107
+ shift
108
+ done
109
+
110
+ }
111
+
112
+ dotpi_audio_device_model_normalise() {
113
+ echo "$1" | tr '[:upper:]' '[:lower:]'
114
+ }
115
+
116
+ # Usage: sudo dotpi audio_device_select --model <model> [--config <config_file_path>]
117
+ # if --config is not provided, it will use the system default config file
118
+ dotpi_audio_device_select() (
119
+ # sub-shell to keep everything local (functions and variables)
120
+
121
+ _dotpi_command="$(basename -- "${FUNCNAME[0]:-"$0"}")"
122
+ _dotpi_usage() {
123
+ echo "Usage: ${_dotpi_command} --model <model> [--config <config_file_path>]"
124
+ }
125
+
126
+ # Initialize all the option variables.
127
+ # This ensures we are not contaminated by variables from the environment.
128
+ model=
129
+ config_file=
130
+
131
+ if ! _dotpi_audio_device_get_options "${@}" ; then
132
+ return $?
133
+ fi
134
+
135
+ if [ -z "$model" ] ; then
136
+ _dotpi_usage
137
+ dotpi_echo_error "missing model option"
138
+ return 1
139
+ fi
140
+
141
+ if [ -z "$config_file" ] ; then
142
+ config_path="$(dotpi_system_get_bootfs_path)"
143
+ if [ -z "$config_path" ] ; then
144
+ dotpi_echo_error "Unable to get default system path for config file"
145
+ _dotpi_usage
146
+ return 1
147
+ fi
148
+ config_filename='config.txt'
149
+ config_file="${config_path}/${config_filename}"
150
+ dotpi_echo_warning "Using default config file ${config_file}"
151
+ fi
152
+
153
+
154
+ if ! [ -w "$config_file" ] ; then
155
+ dotpi_echo_error "Unable to access config file ${config_file} for writing"
156
+ return 1
157
+ fi
158
+
159
+ # lowercase everything
160
+ model_normalised="$(dotpi_audio_device_model_normalise "$model")"
161
+
162
+ case "$model_normalised" in
163
+
164
+ ######## Generic devices
165
+
166
+ 'default')
167
+ dotpi_echo_warning "Not installing a specific audio device, keeping defaults"
168
+ ;;
169
+
170
+ 'none')
171
+ _dotpi_audio_device_disable_all
172
+ ;;
173
+
174
+ 'headphones')
175
+ _dotpi_audio_device_select_headphones
176
+ ;;
177
+
178
+ 'bluetooth')
179
+ dotpi_echo_info "Installing generic bluetooth device"
180
+ _dotpi_audio_device_select_bluetooth
181
+ ;;
182
+
183
+ ######## Specific devices
184
+
185
+ # Raspberry
186
+ # Cf. https://www.raspberrypi.com/documentation/accessories/audio.html#configuration
187
+
188
+ 'raspberry pi dac pro'|'iqaudio dac pro')
189
+ dtoverlay=rpi-dacpro
190
+ _dotpi_audio_device_select_raspberry_pi
191
+ ;;
192
+
193
+ 'raspberry pi dac+'|'iqaudio dac+')
194
+ dtoverlay='rpi-dacplus,auto_mute_amp'
195
+ _dotpi_audio_device_select_raspberry_pi
196
+ ;;
197
+
198
+ 'raspberry pi digiamp+'|'iqaudio digiamp+')
199
+ dtoverlay='rpi-digiampplus,auto_mute_amp'
200
+ _dotpi_audio_device_select_raspberry_pi
201
+ ;;
202
+
203
+ 'raspberry pi codec zero'|'iqaudio codec zero')
204
+ dtoverlay=rpi-codeczero
205
+ _dotpi_audio_device_select_raspberry_pi
206
+ ;;
207
+
208
+ # HiFiBerry
209
+ # Cf. https://www.hifiberry.com/docs/software/configuring-linux-3-18-x/
210
+
211
+ 'hifiberry dac for raspberry pi 1'|'hifiberry dac+ light'|'hifiberry dac zero'|'hifiberry miniamp'|'hifiberry beocreate'|'hifiberry dac+ dsp'|'hifiberry dac+ rtc')
212
+ dtoverlay=hifiberry-dac
213
+ _dotpi_audio_device_select_hifiberry
214
+ ;;
215
+
216
+ 'hifiberry dac+ standard'|'hifiberry pro'|'hifiberry amp2'|'hifiberry amp4')
217
+ dtoverlay=hifiberry-dacplus
218
+ _dotpi_audio_device_select_hifiberry
219
+ ;;
220
+
221
+ 'hifiberry dac2 hd')
222
+ dtoverlay=hifiberry-dacplushd
223
+ _dotpi_audio_device_select_hifiberry
224
+ ;;
225
+
226
+ 'hifiberry dac+ adc')
227
+ dtoverlay=hifiberry-dacplusadc
228
+ _dotpi_audio_device_select_hifiberry
229
+ ;;
230
+
231
+ 'hifiberry dac+ adc pro')
232
+ dtoverlay=hifiberry-dacplusadcpro
233
+ _dotpi_audio_device_select_hifiberry
234
+ ;;
235
+
236
+ 'hifiberry digi+')
237
+ dtoverlay=hifiberry-digi
238
+ _dotpi_audio_device_select_hifiberry
239
+ ;;
240
+
241
+ 'hifiberry digi+ pro')
242
+ dtoverlay=hifiberry-digi-pro
243
+ _dotpi_audio_device_select_hifiberry
244
+ ;;
245
+
246
+ 'hifiberry amp+')
247
+ dtoverlay=hifiberry-amp
248
+ _dotpi_audio_device_select_hifiberry
249
+ ;;
250
+
251
+ 'hifiberry amp3')
252
+ dtoverlay=hifiberry-amp3
253
+ _dotpi_audio_device_select_hifiberry
254
+ ;;
255
+
256
+ 'hifiberry amp4 pro')
257
+ dtoverlay=hifiberry-amp4pro
258
+ _dotpi_audio_device_select_hifiberry
259
+ ;;
260
+
261
+ ####### Ultimate Ears (UE)
262
+
263
+ 'ue boom 2'|'ue boom 3'|'ue megaboom 2'|'ue megaboom 3')
264
+ _dotpi_audio_device_select_bluetooth
265
+ ;;
266
+
267
+
268
+ ########### Unknown device
269
+
270
+ *) # other
271
+ _dotpi_usage
272
+ dotpi_echo_error "Unknown audio device model: ${model}"
273
+ return 1
274
+ ;;
275
+
276
+ esac
277
+
278
+ # use xargs to unquote value
279
+ model_project="$(dotpi_configuration_read \
280
+ --file "${DOTPI_ROOT}/etc/dotpi_environment_project.bash" \
281
+ --key dotpi_audio_device \
282
+ | xargs)"
283
+
284
+
285
+ if [[ "$model_normalised" == "$(dotpi_audio_device_model_normalise "$model_project")" ]] ; then
286
+ # no need to update environment
287
+ return 0;
288
+ fi
289
+
290
+ dotpi_echo_warning 'Audio device model is specific to this instance'
291
+
292
+ # comment setting in project
293
+ dotpi_configuration_comment --file "${DOTPI_ROOT}/etc/dotpi_environment_project.bash" \
294
+ --key dotpi_audio_device
295
+
296
+ # escape double-quote for now, to quote when writing later
297
+ model_value="$(echo "$model" | dotpi_sed 's/"/\\"/g')"
298
+
299
+ # write changed setting in instance
300
+ # be sure to quote value
301
+ dotpi_configuration_write --file "${DOTPI_ROOT}/etc/dotpi_environment_instance.bash" \
302
+ --key dotpi_audio_device \
303
+ --value \""${model_value}"\"
304
+ )
305
+
306
+ _dotpi_audio_device_disable_all() (
307
+ exception_family="$1"
308
+
309
+ if [[ "$exception_family" = "" ]] ; then
310
+ dotpi_echo_info "Disabling all audio devices"
311
+ else
312
+ dotpi_echo_info "Disabling all audio devices except ${exception_family}"
313
+ fi
314
+
315
+ if [[ ! "$exception_family" = "headphones" ]] ; then
316
+ _dotpi_audio_device_disable_headphones
317
+ fi
318
+
319
+ if [[ ! "$exception_family" = "hdmi" ]] ; then
320
+ _dotpi_audio_device_disable_hdmi
321
+ fi
322
+
323
+ if [[ ! "$exception_family" = "raspberry_pi" ]] ; then
324
+ _dotpi_audio_device_disable_raspberry_pi
325
+ fi
326
+
327
+ if [[ ! "$exception_family" = "hifiberry" ]] ; then
328
+ _dotpi_audio_device_disable_hifiberry
329
+ fi
330
+
331
+ )
332
+
333
+ _dotpi_audio_device_select_headphones() (
334
+ dotpi_echo_info "Installing Headphones (default) audio device"
335
+
336
+ _dotpi_audio_device_disable_all headphones
337
+
338
+ # un-comment dtparam=audio as it must be set first
339
+ # (setting at the end the the file fails)
340
+ pattern="$(dotpi_configuration_get_pattern --prefix "# dtparam=audio")"
341
+ perl -pe "s/${pattern}/"'dtparam=audio=on/' -i -- "$config_file"
342
+ )
343
+
344
+ _dotpi_audio_device_select_bluetooth() (
345
+ _dotpi_audio_device_disable_all bluetooth
346
+ )
347
+
348
+ _dotpi_audio_device_select_raspberry_pi() (
349
+ dotpi_echo_info "Configuring Raspberry Pi audio device '${model}'"
350
+
351
+ _dotpi_audio_device_disable_all raspberry_pi
352
+
353
+ mkdir -p "$(dirname -- "$config_file")"
354
+ cat >> "$config_file" << EOF
355
+
356
+ # dotpi: overlay for audio device '${model}'
357
+ dtoverlay=${dtoverlay}
358
+
359
+ EOF
360
+ )
361
+
362
+
363
+ _dotpi_audio_device_select_hifiberry() (
364
+ dotpi_echo_info "Configuring HiFiBerry audio device '${model}'"
365
+
366
+ _dotpi_audio_device_disable_all hifiberry
367
+
368
+ mkdir -p "$(dirname -- "$config_file")"
369
+ cat >> "$config_file" << EOF
370
+
371
+ # dotpi: overlay for audio device '${model}'
372
+ dtoverlay=${dtoverlay}
373
+
374
+ EOF
375
+ )
376
+
377
+ _dotpi_audio_device_disable_headphones() (
378
+ dotpi_echo_info "Disabling headphones"
379
+ # disable internal audio device
380
+ dotpi_configuration_comment --file "$config_file" --key 'dtparam=audio'
381
+ )
382
+
383
+ _dotpi_audio_device_disable_hdmi() (
384
+ dotpi_echo_info "Disabling HDMI audio"
385
+ # disable HDMI audio
386
+
387
+ # new systems
388
+ pattern="$(dotpi_configuration_get_pattern --prefix "dtoverlay=vc4-kms-v3d")"
389
+ perl -pe "s/${pattern}/"'${1}${2},noaudio/' -i -- "$config_file"
390
+
391
+ # old systems
392
+ pattern="$(dotpi_configuration_get_pattern --prefix "dtoverlay=vc4-fkms-v3d")"
393
+ perl -pe "s/${pattern}/"'${1}${2},audio=off/' -i -- "$config_file"
394
+ )
395
+
396
+ _dotpi_audio_device_disable_raspberry_pi() (
397
+ dotpi_echo_info "Disabling Raspberry Pi audio"
398
+
399
+ # disable hifiberry
400
+ pattern="$(dotpi_configuration_get_pattern --prefix "dtoverlay=rpi-")"
401
+ perl -pe "s/${pattern}/"'${1}# ${2}${3}/' -i -- "$config_file"
402
+ )
403
+
404
+ _dotpi_audio_device_disable_hifiberry() (
405
+ dotpi_echo_info "Disabling HiFiBerry audio"
406
+
407
+ # disable hifiberry
408
+ pattern="$(dotpi_configuration_get_pattern --prefix "dtoverlay=hifiberry-")"
409
+ perl -pe "s/${pattern}/"'${1}# ${2}${3}/' -i -- "$config_file"
410
+ )
411
+
412
+ _dotpi_audio_device_volume_set_alsa() (
413
+ amixer -- sset "$control" "$volume"
414
+ alsactl store
415
+
416
+ if [[ "$volume" == "$dotpi_audio_volume" ]] ; then
417
+ # no change to write
418
+ return 0
419
+ fi
420
+
421
+ # comment setting in project
422
+ dotpi_configuration_comment --file "${DOTPI_ROOT}/etc/dotpi_environment_project.bash" \
423
+ --key dotpi_audio_volume
424
+
425
+ # escape double-quote for now, to quote when writing later
426
+ model_value="$(echo "$model" | dotpi_sed 's/"/\\"/g')"
427
+
428
+ # write changed setting in instance
429
+ dotpi_configuration_write --file "${DOTPI_ROOT}/etc/dotpi_environment_instance.bash" \
430
+ --key dotpi_audio_volume \
431
+ --value "$volume"
432
+ )
433
+
434
+ dotpi_audio_device_init() (
435
+
436
+ if [[ -z "$dotpi_audio_device" ]] ; then
437
+ dotpi_echo_warning "dotpi_audio_device not set, keeping default audio device"
438
+ return 0
439
+ fi
440
+
441
+ model_normalised="$(dotpi_audio_device_model_normalise "$dotpi_audio_device")"
442
+
443
+ # hardware
444
+ case "$model_normalised" in
445
+ 'raspberry pi codec zero'|'iqaudio codec zero')
446
+
447
+ usr_repository="raspberrypi/Pi-Codec"
448
+ usr_directory="${DOTPI_ROOT}/usr/${usr_repository}"
449
+
450
+ # clone once to be able to init offline
451
+ if ! [[ -d "${usr_directory}" ]] ; then
452
+ mkdir -p "${usr_directory}"
453
+ git clone "https://github.com/${usr_repository}.git" "${usr_directory}" || {
454
+ dotpi_echo_error "Unable to clone repository ${usr_repository}"
455
+ return 1
456
+ }
457
+ fi
458
+
459
+ alsactl restore -f "${usr_directory}/Codec_Zero_StereoMIC_record_and_HP_playback.state"
460
+ ;;
461
+
462
+ esac
463
+
464
+ # alsa
465
+ case "$model_normalised" in
466
+
467
+ 'headphones')
468
+
469
+ amixer -D sysdefault sset -- 'PCM' 'on'
470
+ amixer -D sysdefault sset -- 'PCM' '0dB'
471
+ alsactl store
472
+ ;;
473
+
474
+ 'raspberry pi dac pro'|'iqaudio dac pro' \
475
+ | 'raspberry pi dac+'|'iqaudio dac+' \
476
+ | 'raspberry pi digiamp+'|'iqaudio digiamp+' \
477
+ | 'raspberry pi codec zero'|'iqaudio codec zero')
478
+
479
+ amixer -D sysdefault sset -- 'Headphone' 'on'
480
+ amixer -D sysdefault sset -- 'Headphone' '0dB'
481
+
482
+ amixer -D sysdefault sset -- 'Lineout' 'on'
483
+ amixer -D sysdefault sset -- 'Lineout' '0dB'
484
+
485
+ alsactl store
486
+ ;;
487
+
488
+ esac
489
+
490
+ )
491
+
492
+ # set and store volume for the current audio device
493
+ dotpi_audio_device_volume_set() (
494
+ volume="$1"
495
+
496
+ model="$dotpi_audio_device"
497
+ # lowercase everything
498
+ model_normalised="$(dotpi_audio_device_model_normalise "$model")"
499
+
500
+ case "$model_normalised" in
501
+
502
+ ####### Generic devices
503
+
504
+ 'headphones')
505
+ control='PCM'
506
+ _dotpi_audio_device_volume_set_alsa
507
+ ;;
508
+
509
+ 'bluetooth')
510
+ dotpi_audio_bluetooth_destination_volume_set "$volume"
511
+ ;;
512
+
513
+
514
+ ####### Specific devices
515
+
516
+ # HiFiBerry
517
+ # Cf. https://www.hifiberry.com/docs/archive/mixer-controls-on-the-hifiberry-boards/
518
+
519
+
520
+ 'hifiberry dac+ dsp'|'hifiberry dac+ rtc'|'hifiberry dac+ standard'|'hifiberry amp2'|'hifiberry dac+ adc'|'hifiberry dac+ adc pro'|'hifiberry amp3')
521
+ control='Digital'
522
+ _dotpi_audio_device_volume_set_alsa
523
+ ;;
524
+
525
+ 'hifiberry dac2 hd')
526
+ control='DAC'
527
+ _dotpi_audio_device_volume_set_alsa
528
+ ;;
529
+
530
+ 'hifiberry amp+')
531
+ control='Master'
532
+ _dotpi_audio_device_volume_set_alsa
533
+ ;;
534
+
535
+ ####### Ultimate Ears (UE)
536
+
537
+ 'ue boom 2'|'ue boom 3'|'ue megaboom 2'|'ue megaboom 3')
538
+ dotpi_audio_bluetooth_destination_volume_set "$volume"
539
+ ;;
540
+
541
+ ########### Unknown device
542
+
543
+ *) # other
544
+ dotpi_echo_error "Unable to set volume for unknown audio device model: ${model}"
545
+ return 1
546
+ ;;
547
+
548
+
549
+ esac
550
+ )
551
+
552
+ # restore volume for the current audio device
553
+ dotpi_audio_device_volume_init() (
554
+ if [[ -z "$dotpi_audio_volume" ]] ; then
555
+ dotpi_echo_warning "dotpi_audio_volume not set, keeping default volume"
556
+ return 0
557
+ fi
558
+
559
+ destination_volume="$dotpi_audio_volume"
560
+ dotpi_audio_device_volume_set "$destination_volume"
561
+ )
562
+
563
+
@@ -0,0 +1,48 @@
1
+ import assert from 'node:assert';
2
+ import { describe, it } from 'node:test';
3
+
4
+ import { readBashArray, readBashVariable, packageVersion } from '../js/utils.js';
5
+
6
+ describe('# utils', () => {
7
+ it('packageVersion()', () => {
8
+ const version = packageVersion();
9
+ console.log('package version:', version);
10
+ assert.equal(typeof version, 'string');
11
+ });
12
+
13
+ it('readBashVariable()', () => {
14
+ const value = readBashVariable('dotpi_audio_device');
15
+ assert.equal(value, 'default');
16
+ });
17
+
18
+ it('readBashArray()', () => {
19
+ const arr = readBashArray('dotpi_audio_device_supported');
20
+ assert.deepEqual(arr, [
21
+ 'default',
22
+ 'none',
23
+ 'headphones',
24
+ 'hifiberry dac+ adc pro',
25
+ 'hifiberry dac+ adc',
26
+ 'hifiberry dac+ standard',
27
+ 'hifiberry dac+ light',
28
+ 'hifiberry dac zero',
29
+ 'hifiberry miniamp',
30
+ 'hifiberry beocreate',
31
+ 'hifiberry dac+ dsp',
32
+ 'hifiberry dac+ rtc',
33
+ 'hifiberry pro',
34
+ 'hifiberry amp2',
35
+ 'hifiberry dac2 hd',
36
+ 'hifiberry digi+',
37
+ 'hifiberry digi+ pro',
38
+ 'hifiberry amp+',
39
+ 'hifiberry amp3',
40
+ 'bluetooth',
41
+ 'ue boom 2',
42
+ 'ue boom 3',
43
+ 'ue megaboom 2',
44
+ 'ue megaboom 3',
45
+ 'hifiberry dac for raspberry pi 1'
46
+ ]);
47
+ });
48
+ });
@@ -0,0 +1,50 @@
1
+ import assert from 'node:assert';
2
+ import { describe, it } from 'node:test';
3
+
4
+ import { readBashArray, readBashVariable, packageVersion } from '../js/utils.js';
5
+
6
+ describe('# utils', () => {
7
+ it('packageVersion()', () => {
8
+ const version = packageVersion();
9
+ console.log('package version:', version);
10
+ assert.equal(typeof version, 'string');
11
+ });
12
+
13
+ it('readBashVariable()', () => {
14
+ const value = readBashVariable('dotpi_audio_device');
15
+ assert.equal(value, 'default');
16
+ });
17
+
18
+ it('readBashArray()', () => {
19
+ const arr = readBashArray('dotpi_audio_device_supported');
20
+ assert.deepEqual(arr, [
21
+ 'default',
22
+ 'none',
23
+ 'headphones',
24
+ 'hifiberry dac+ adc pro',
25
+ 'hifiberry dac+ adc',
26
+ 'hifiberry dac+ standard',
27
+ 'hifiberry dac+ light',
28
+ 'hifiberry dac zero',
29
+ 'hifiberry miniamp',
30
+ 'hifiberry beocreate',
31
+ 'hifiberry dac+ dsp',
32
+ 'hifiberry dac+ rtc',
33
+ 'hifiberry pro',
34
+ 'hifiberry amp2',
35
+ 'hifiberry dac2 hd',
36
+ 'hifiberry digi+',
37
+ 'hifiberry digi+ pro',
38
+ 'hifiberry amp+',
39
+ 'hifiberry amp3',
40
+ 'hifiberry amp4',
41
+ 'hifiberry amp4 pro',
42
+ 'bluetooth',
43
+ 'ue boom 2',
44
+ 'ue boom 3',
45
+ 'ue megaboom 2',
46
+ 'ue megaboom 3',
47
+ 'hifiberry dac for raspberry pi 1'
48
+ ]);
49
+ });
50
+ });
@@ -0,0 +1,50 @@
1
+ import assert from 'node:assert';
2
+ import { describe, it } from 'node:test';
3
+
4
+ import { readBashArray, readBashVariable, packageVersion } from '../src/utils.js';
5
+
6
+ describe('# utils', () => {
7
+ it('packageVersion()', () => {
8
+ const version = packageVersion();
9
+ console.log('package version:', version);
10
+ assert.equal(typeof version, 'string');
11
+ });
12
+
13
+ it('readBashVariable()', () => {
14
+ const value = readBashVariable('dotpi_audio_device');
15
+ assert.equal(value, 'default');
16
+ });
17
+
18
+ it('readBashArray()', () => {
19
+ const arr = readBashArray('dotpi_audio_device_supported');
20
+ assert.deepEqual(arr, [
21
+ 'default',
22
+ 'none',
23
+ 'headphones',
24
+ 'hifiberry dac+ adc pro',
25
+ 'hifiberry dac+ adc',
26
+ 'hifiberry dac+ standard',
27
+ 'hifiberry dac+ light',
28
+ 'hifiberry dac zero',
29
+ 'hifiberry miniamp',
30
+ 'hifiberry beocreate',
31
+ 'hifiberry dac+ dsp',
32
+ 'hifiberry dac+ rtc',
33
+ 'hifiberry pro',
34
+ 'hifiberry amp2',
35
+ 'hifiberry dac2 hd',
36
+ 'hifiberry digi+',
37
+ 'hifiberry digi+ pro',
38
+ 'hifiberry amp+',
39
+ 'hifiberry amp3',
40
+ 'hifiberry amp4',
41
+ 'hifiberry amp4 pro',
42
+ 'bluetooth',
43
+ 'ue boom 2',
44
+ 'ue boom 3',
45
+ 'ue megaboom 2',
46
+ 'ue megaboom 3',
47
+ 'hifiberry dac for raspberry pi 1'
48
+ ]);
49
+ });
50
+ });