-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint.c
79 lines (67 loc) · 1.57 KB
/
print.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* Copyright (C) 2017 Sebastian Meiling <[email protected]>
*
* This file is part of uMorse, see
* https://github.com/smlng/uMorse
*
* This file is subject to the terms and conditions of the MIT License.
* See the file LICENSE in the top level directory for more details.
*
* If you did not receive a copy of the license file, see
* https://choosealicense.com/licenses/mit/
*/
/**
* @ingroup umorse
* @{
* @file
* @brief Implementation of uMorse output interface printing to stdout
*
* @author Sebastian Meiling <[email protected]>
* @}
*/
#include <stdint.h>
#ifndef UMORSE_PRINT
#include <stdio.h>
#define UMORSE_PRINT(...) printf(__VA_ARGS__)
#endif
#ifndef UMORSE_MSLEEP
#include <unistd.h>
#define UMORSE_MSLEEP(m) usleep(m * 1000U)
#endif
#include "print.h"
#include "umorse.h"
void umorse_print_dit(void *args, uint8_t flags)
{
(void) args;
UMORSE_PRINT(".");
if (!(flags & UMORSE_FLAG_NODELAY)) {
UMORSE_MSLEEP(UMORSE_DELAY_DIT);
}
}
void umorse_print_dah(void *args, uint8_t flags)
{
(void) args;
UMORSE_PRINT("_");
if (!(flags & UMORSE_FLAG_NODELAY)) {
UMORSE_MSLEEP(UMORSE_DELAY_DAH);
}
}
void umorse_print_nil(void *args, uint8_t flags)
{
(void) args;
uint8_t cnt = flags & UMORSE_MASK_COUNT;
if (cnt > 7) {
UMORSE_PRINT("\n");
}
else if (cnt > 3) {
UMORSE_PRINT(" / ");
}
else if (cnt > 1) {
UMORSE_PRINT(" ");
}
if (!(flags & UMORSE_FLAG_NODELAY)) {
while (cnt--) {
UMORSE_MSLEEP(UMORSE_DELAY_DIT);
}
}
}