Changeset 1980:b43e4f60bc52 in roaraudio


Ignore:
Timestamp:
06/12/09 04:16:18 (15 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

use inst struct

File:
1 edited

Legend:

Unmodified
Added
Removed
  • roard/driver_pwmled.c

    r1978 r1980  
    2727int driver_pwmled_open_vio  (struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh) { 
    2828 struct roar_vio_defaults def; 
    29  struct roar_vio_calls    * calls = malloc(sizeof(struct roar_vio_calls)); 
     29 struct driver_pwmled * self = malloc(sizeof(struct driver_pwmled)); 
    3030 
    31  if ( calls == NULL ) 
     31 if ( self == NULL ) 
    3232  return -1; 
    3333 
     
    3636   device = "/dev/ttyS0"; 
    3737 
    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); 
     38  if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_WRONLY, 0644) == -1 ) { 
     39   free(self); 
    4340   return -1; 
    4441  } 
    4542 
    46   inst->inst = calls; 
     43  if ( roar_vio_open_dstr(&(self->vio), device, &def, 1) == -1 ) { 
     44   free(self); 
     45   return -1; 
     46  } 
     47 
     48  inst->inst = self; 
    4749 } else { 
    4850/* 
     
    5052   return -1; 
    5153*/ 
     54  free(self); 
    5255  return -1; 
    5356 } 
     
    6770 
    6871int     driver_pwmled_close (struct roar_vio_calls * vio) { 
    69  int ret = roar_vio_close(vio->inst); 
     72 int ret = roar_vio_close(&(((struct driver_pwmled*)(vio->inst))->vio)); 
    7073 
    7174 if ( vio->inst != NULL ) 
     
    7780// TODO: this function should be optimized. 
    7881ssize_t driver_pwmled_write (struct roar_vio_calls * vio,  void *buf, size_t count) { 
    79  struct roar_lpwm_state state; 
     82 struct driver_pwmled * self = vio->inst; 
    8083 
    8184 if ( vio == NULL || buf == NULL ) 
     
    8588  return -1; 
    8689 
    87  if ( roar_light_pwm_new(&state, 16) == -1 ) 
     90 if ( roar_light_pwm_new(&(self->state), 16) == -1 ) 
    8891  return -1; 
    8992 
    90  if ( roar_light_pwm_set(&state, ((unsigned char*)buf)[0] / 16) == -1 ) 
     93 if ( roar_light_pwm_set(&(self->state), ((unsigned char*)buf)[0] / 16) == -1 ) 
    9194  return -1; 
    9295 
    93  return roar_light_pwm_send(&state, vio->inst, 1) == 0 ? count : -1; 
     96 return roar_light_pwm_send(&(self->state), &(self->vio), 1) == 0 ? count : -1; 
    9497} 
    9598 
Note: See TracChangeset for help on using the changeset viewer.