-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbadge.h
More file actions
145 lines (112 loc) · 3.53 KB
/
Copy pathbadge.h
File metadata and controls
145 lines (112 loc) · 3.53 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* Simple control API for the Xanes (?) USB LED Badge
* Copyright (C) 2017 HappyCodingRobot
*
* This code is licensed under the Simplified BSD License.
* See the LICENSE file for details.
*/
#ifndef BADGE_H
#define BADGE_H
/**
* Message types
*/
#define BADGE_MSG_TYPE_TEXT 0
#define BADGE_MSG_TYPE_BITMAP 1
/**
* Bounds for the badge
*/
#define MIN_SPEED 1
#define DEF_SPEED 4
#define MAX_SPEED 8
#define MIN_BRIGHTNESS 3
#define MAX_BRIGHTNESS 0
#define N_MESSAGES 8
#define MAX_STR 255
#define BADGE_MSG_FONT 1
#define BADGE_MSG_FONT_HEIGHT 11
//#define DISP_SIZE (MAX_STR*11*N_MESSAGES)+64
#define DISP_SIZE 32767
typedef enum e_effects {
E_left = 0,
E_right,
E_up,
E_down,
E_freeze,
E_animation,
E_snow,
E_volume,
E_laser
} effects_t;
typedef enum e_brightness {
BR_100 = 0,
BR_75,
BR_50,
BR_25
} brightness_t;
// ???
extern bool badgeIsOpen;
/** \brief Open HID and prepares structures
*
* \return 0 or debug result on success, -1 on error.
*/
int badgeOpen(void);
/** \brief Add text messages to the message struct
*
* \param msg_num - Message number [0..7]
* \param msg - A pointer to the message text (characters)
* \param msg_len - Length of the message
* \return 0 or debug result on success, -1 on error.
*/
int badgeAddTextMessage(uint8_t msg_num, char *msg, int msg_len);
/** \brief Add graphic to the message struct
*
* \param msg_num - Message number [0..7]
* \param gfx - A pointer to the graphics
* \param gfx_width - Length of the graphic (in pixel)
* \return 0 or debug result on success, -1 on error.
*
* Converts and adds an image to a message struct. Excepts data as c array with
* 1 byte/px, stored from left to right and top to bottom, a height of 11 pixels
* (more than 11 are ignored).
*/
int badgeAddGfxMessage(uint8_t msg_num, char *gfx, int gfx_width);
/** \brief Sets the message effects and behavior to the message struct
*
* \param msg_num - Message number [0..7]
* \param msg_pat - Message effect (see: enum e_effects)
* \param msg_spd - Scrolling/effect speed [1..8]
* \param msg_blink - Blink message [true,false]
* \param msg_frame - Frame around message [true, false]
*/
void badgeSetEffects(uint8_t msg_num, effects_t msg_pat, uint8_t msg_spd, bool msg_blink, bool msg_frame);
/** \brief Sets the message brightness in 4 steps
*
* \param msg_br - Brightness value Message number [0..3: 100%..25%]
*/
void badgeSetBrightness(uint8_t msg_br);
/** \brief build the report buffer from the complete message struct and send it to the device
*
* \return number of reports send on success, -1 on error.
*/
int badgeSend(void);
/** \brief Close HID
*
* \return 0 on success, -1 on error.
*/
int badgeClose(void);
/**< helper functions */
//void badgeClear(void); // needed ??
//void badgeDrawChar(uint8_t id, char c, char *target);
void badgeSetEffectsPat(uint8_t msg_num, effects_t msg_pat);
void badgeSetEffectsSpd(uint8_t msg_num, uint8_t msg_spd);
void badgeSetEffectsBlink(uint8_t msg_num, bool msg_blink);
void badgeSetEffectsFrame(uint8_t msg_num, bool msg_frame);
void badgeSetFont(uint8_t msg_num, uint8_t font_num); // testing, use before badgeAddTextMessage()
int gfx_transform_to_bits(char* data_out, int len, char* data_in);
/**< debug functions */
#ifdef DEBUG_VERBOSE
void hex_out(unsigned char *data, int len);
void test_out_print_byte(char *data, int len, int h);
void test_out_print_bit(unsigned char *data, int len_byte, int h);
#endif // DEBUG_VERBOSE
#endif /* BADGE_H */