forked from realPy/dothat-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdothat-sn3218-sysfs.c
271 lines (156 loc) · 5.37 KB
/
dothat-sn3218-sysfs.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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/*
* * Copyright 2015-2016
* *
* * Author: Manuel BARRAUD <[email protected]>
* *
* * This file is subject to the terms and conditions of version 2 of
* * the GNU General Public License. See the file COPYING in the main
* * directory of this archive for more details.
*
* SN3218 SYS FS
*/
#include "dothat-sn3218.h"
#include "dothat-sn3218-sysfs.h"
#define DOTHATMAJOR 64
static ssize_t show_sn3218_enable_callback(struct device *dev, struct device_attribute *attr,
char *buf) {
struct psn3218 *pData=dev_get_drvdata(dev);
if(pData&&pData->state) {
return scnprintf(buf, PAGE_SIZE, "1");
}
return scnprintf(buf, PAGE_SIZE, "0");
}
static ssize_t store_sn3218_enable_callback(struct device* dev ,struct device_attribute* attr,const char* buf,size_t count)
{
u8 enable;
int cnt;
struct psn3218 *pData=dev_get_drvdata(dev);
if(pData) {
cnt = sscanf(buf, "%hhd", &enable);
if(cnt==1) {
sn3218_enable(pData->client,enable);
}
}
//kstrtol
return count;
}
static ssize_t show_sn3218_lcd_callback(struct device *dev, struct device_attribute *attr,
char *buf) {
int color,i,cnt;
char BGR[]= {'B','G','R'};
struct psn3218 *pData=dev_get_drvdata(dev);
if(pData) {
buf[0]=0;
for(color=0;color<3;color++) {
cnt=scnprintf(buf,PAGE_SIZE,"%s %c:",buf,BGR[color]);
for(i=0;i<6;i++) {
cnt=scnprintf(buf,PAGE_SIZE,"%s 0x%02x",buf,pData->ledColor[i*3+color]);
}
cnt=scnprintf(buf,PAGE_SIZE,"%s \n",buf);
}
return cnt;
}
return 0;
}
static ssize_t store_sn3218_lcd_callback(struct device* dev ,struct device_attribute* attr,const char* buf,size_t count)
{
u8 segment;
int b,g,r;
int cnt;
struct psn3218 *pData=dev_get_drvdata(dev);
if(pData) {
cnt = sscanf(buf, "%hhd %02x%02x%02x", &segment,&b,&g,&r);
if(segment>=0&&segment<6) {
pData->ledColor[3*segment]=(u8)b;
pData->ledColor[3*segment+1]=(u8)g;
pData->ledColor[3*segment+2]=(u8)r;
sn3218_output(pData->client,pData->ledColor);
return count;
}
}
return count;
}
static ssize_t store_sn3218_lcd_raw_callback(struct device* dev ,struct device_attribute* attr,const char* buf,size_t count)
{
int i;
u8 b,g,r;
int cnt;
char data[7];
memset(data,0,7);
struct psn3218 *pData=dev_get_drvdata(dev);
if(pData) {
pr_info("store raw: %s %d",buf,count);
//cnt = sscanf(buf, "%02hhx%02hhx%02hhx",&b,&g,&r);
//pr_info("info: %d %d %d",b,g,r);
if(count>=36) {
for(i=0;i<6;i++) {
memcpy(data,buf+6*i,6);
//pr_info("info data : %s",data);
cnt = sscanf(data, "%02hhx%02hhx%02hhx",&b,&g,&r);
pData->ledColor[3*i]=(u8)b;
pData->ledColor[3*i+1]=(u8)g;
pData->ledColor[3*i+2]=(u8)r;
//pr_info("RGB:%d %d %d %d",i,b,g,r);
}
sn3218_output(pData->client,pData->ledColor);
return count;
}
}
return count;
}
static ssize_t store_sn3218_lcd_monocolor_callback(struct device* dev ,struct device_attribute* attr,const char* buf,size_t count)
{
int cnt;
u8 color[3];
struct psn3218 *pData=dev_get_drvdata(dev);
if(pData) {
cnt = sscanf(buf,"%02hhx%02hhx%02hhx",color,color+1,color+2);
sn3218_output_monocolor(pData,color);
return count;
}
return count;
}
static ssize_t show_sn3218_lcd_mask_callback(struct device *dev, struct device_attribute *attr,
char *buf) {
struct psn3218 *pData=dev_get_drvdata(dev);
if(pData) {
return scnprintf(buf,PAGE_SIZE,"%05x\n",pData->mask);
}
return 0;
}
static ssize_t store_sn3218_lcd_mask_callback(struct device* dev ,struct device_attribute* attr,const char* buf,size_t count)
{
int cnt;
u32 value;
struct psn3218 *pData=dev_get_drvdata(dev);
if(pData) {
cnt = sscanf(buf,"%05x",&value);
sn3218_enable_leds(pData->client,value);
return count;
}
return count;
}
static DEVICE_ATTR(sn3218_enable,0660, show_sn3218_enable_callback,store_sn3218_enable_callback);
static DEVICE_ATTR(sn3218_lcd,0660, show_sn3218_lcd_callback,store_sn3218_lcd_callback);
static DEVICE_ATTR(sn3218_lcd_raw,0660, show_sn3218_lcd_callback,store_sn3218_lcd_raw_callback);
static DEVICE_ATTR(sn3218_lcd_monocolor,0660, show_sn3218_lcd_callback,store_sn3218_lcd_monocolor_callback);
static DEVICE_ATTR(sn3218_lcd_mask,0660, show_sn3218_lcd_mask_callback,store_sn3218_lcd_mask_callback);
void sn3218_init_sysfs(struct class *s_pDeviceClass,struct psn3218 *data)
{
int result;
data->sysfsdevice = device_create(s_pDeviceClass, NULL, MKDEV(DOTHATMAJOR,0), NULL, "sn3218");
dev_set_drvdata(data->sysfsdevice,data);
dev_attr_sn3218_enable.attr.name="enable";
dev_attr_sn3218_lcd.attr.name="lcd";
dev_attr_sn3218_lcd_raw.attr.name="lcd_raw";
dev_attr_sn3218_lcd_monocolor.attr.name="monocolor";
dev_attr_sn3218_lcd_mask.attr.name="mask";
result = device_create_file(data->sysfsdevice, &dev_attr_sn3218_enable);
result = device_create_file(data->sysfsdevice, &dev_attr_sn3218_lcd);
result = device_create_file(data->sysfsdevice, &dev_attr_sn3218_lcd_raw);
result = device_create_file(data->sysfsdevice, &dev_attr_sn3218_lcd_monocolor);
result = device_create_file(data->sysfsdevice, &dev_attr_sn3218_lcd_mask);
}
void sn3218_exit_sysfs(struct psn3218 *data)
{
}