source: roaraudio/roard/driver_pwmled.c @ 1978:8501a4e5fb9a

Last change on this file since 1978:8501a4e5fb9a was 1978:8501a4e5fb9a, checked in by phi, 15 years ago

got driver basicly working

File size: 2.7 KB
Line 
1//driver_pwmled.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009
5 *
6 *  This file is part of roard a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include "roard.h"
26
27int driver_pwmled_open_vio  (struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh) {
28 struct roar_vio_defaults def;
29 struct roar_vio_calls    * calls = malloc(sizeof(struct roar_vio_calls));
30
31 if ( calls == NULL )
32  return -1;
33
34 if ( fh == -1 ) {
35  if ( device == NULL )
36   device = "/dev/ttyS0";
37
38  if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_WRONLY, 0644) == -1 )
39   return -1;
40
41  if ( roar_vio_open_dstr(calls, device, &def, 1) == -1 ) {
42   free(calls);
43   return -1;
44  }
45
46  inst->inst = calls;
47 } else {
48/*
49  if ( roar_vio_open_fh(inst, fh) == -1 )
50   return -1;
51*/
52  return -1;
53 }
54
55 inst->read     = NULL;
56 inst->write    = driver_pwmled_write;
57 inst->lseek    = NULL;
58 inst->nonblock = NULL;
59 inst->sync     = NULL;
60 inst->ctl      = driver_pwmled_ctl;
61 inst->close    = driver_pwmled_close;
62
63 info->codec = ROAR_CODEC_DMX512;
64
65 return 0;
66}
67
68int     driver_pwmled_close (struct roar_vio_calls * vio) {
69 int ret = roar_vio_close(vio->inst);
70
71 if ( vio->inst != NULL )
72  free(vio->inst);
73
74 return ret;
75}
76
77// TODO: this function should be optimized.
78ssize_t driver_pwmled_write (struct roar_vio_calls * vio,  void *buf, size_t count) {
79 struct roar_lpwm_state state;
80
81 if ( vio == NULL || buf == NULL )
82  return -1;
83
84 if ( count != 512 )
85  return -1;
86
87 if ( roar_light_pwm_new(&state, 16) == -1 )
88  return -1;
89
90 if ( roar_light_pwm_set(&state, ((unsigned char*)buf)[0] / 16) == -1 )
91  return -1;
92
93 return roar_light_pwm_send(&state, vio->inst, 1) == 0 ? count : -1;
94}
95
96int driver_pwmled_ctl(struct roar_vio_calls * vio, int cmd, void * data) {
97
98 if ( vio == NULL )
99  return -1;
100
101 switch (cmd) {
102  case ROAR_VIO_CTL_SET_SSTREAM:
103    ROAR_STREAM(data)->dir = ROAR_DIR_LIGHT_OUT;
104    ROAR_STREAM_SERVER(data)->codec_orgi = ROAR_CODEC_DMX512;
105   break;
106  default:
107   return -1;
108 }
109
110 return 0;
111}
112
113//ll
Note: See TracBrowser for help on using the repository browser.