[1974] | 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 | |
---|
| 27 | int driver_pwmled_open_vio (struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh) { |
---|
| 28 | |
---|
| 29 | if ( fh == -1 ) { |
---|
| 30 | if ( device == NULL ) |
---|
| 31 | device = "/dev/ttyS0"; |
---|
| 32 | |
---|
| 33 | if ( roar_vio_open_file(inst, device, O_WRONLY, 0644) == -1 ) |
---|
| 34 | return -1; |
---|
| 35 | } else { |
---|
| 36 | if ( roar_vio_open_fh(inst, fh) == -1 ) |
---|
| 37 | return -1; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | inst->write = driver_pwmled_write; |
---|
| 41 | inst->ctl = driver_pwmled_ctl; |
---|
| 42 | inst->nonblock = NULL; |
---|
| 43 | |
---|
| 44 | info->codec = ROAR_CODEC_DMX512; |
---|
| 45 | |
---|
| 46 | return 0; |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | // TODO: this function should be optimized. |
---|
| 50 | ssize_t driver_pwmled_write (struct roar_vio_calls * vio, void *buf, size_t count) { |
---|
| 51 | struct roar_lpwm_state state; |
---|
| 52 | |
---|
| 53 | if ( vio == NULL || buf == NULL ) |
---|
| 54 | return -1; |
---|
| 55 | |
---|
| 56 | if ( count != 512 ) |
---|
| 57 | return -1; |
---|
| 58 | |
---|
| 59 | if ( roar_light_pwm_new(&state, 16) == -1 ) |
---|
| 60 | return -1; |
---|
| 61 | |
---|
| 62 | if ( roar_light_pwm_set(&state, ((unsigned char*)buf)[0] / 16) == -1 ) |
---|
| 63 | return -1; |
---|
| 64 | |
---|
| 65 | return roar_light_pwm_send(&state, vio, 8) == 0 ? count : -1; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | int driver_pwmled_ctl(struct roar_vio_calls * vio, int cmd, void * data) { |
---|
| 69 | |
---|
| 70 | if ( vio == NULL ) |
---|
| 71 | return -1; |
---|
| 72 | |
---|
| 73 | switch (cmd) { |
---|
| 74 | case ROAR_VIO_CTL_SET_SSTREAM: |
---|
| 75 | ROAR_STREAM(data)->dir = ROAR_DIR_LIGHT_OUT; |
---|
| 76 | ROAR_STREAM_SERVER(data)->codec_orgi = ROAR_CODEC_DMX512; |
---|
| 77 | break; |
---|
| 78 | default: |
---|
| 79 | return -1; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | return 0; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | //ll |
---|