tasks/task_led.c
// TODO: send back error if type is not actuator configuration.
send back error if type is not actuator configuration.
send back error if type is not actuator configuration .
ruuvi_endpoint_status_t led_handler(ruuvi_standard_message_t* const message)
{
  if(NULL == message)                        { return ENDPOINT_HANDLER_NULL; }
  if(LED != message->destination_endpoint)   { return ENDPOINT_INVALID; }
  if(ACTUATOR_CONFIGRATION != message->type) { return ENDPOINT_INVALID; }
  ruuvi_actuator_configuration_t* config = (void*)message->payload;
  bool success = true;
  uint8_t leds[] = LEDS_LIST;
  if(LEDS_NUMBER > config->channel)
  {
      if(config->duty_cycle) { platform_gpio_write(leds[config->channel], LEDS_ACTIVE_STATE); }
      else                   { platform_gpio_write(leds[config->channel], !LEDS_ACTIVE_STATE); }
  }
  else
  {
      config->channel = ENDPOINT_INVALID;
      success = false;
  }
  uint8_t source = message->source_endpoint;
  message->source_endpoint = message->destination_endpoint;
  message->destination_endpoint = source;
  message->type = ACKNOWLEDGEMENT;
  if (success) { memset(message->payload, 0 , sizeof(message->payload)); }
  return ENDPOINT_SUCCESS;
}
ruuvi_endpoint_status_t led_handler ( ruuvi_standard_message_t * const message ) { if ( NULL == message ) { return ENDPOINT_HANDLER_NULL ; } if ( LED != message -> destination_endpoint ) { return ENDPOINT_INVALID ; } if ( ACTUATOR_CONFIGRATION != message -> type ) { return ENDPOINT_INVALID ; } ruuvi_actuator_configuration_t * config = ( void * ) message -> payload ; bool success = true ; uint8_t leds [ ] = LEDS_LIST ; if ( LEDS_NUMBER > config -> channel ) { if ( config -> duty_cycle ) { platform_gpio_write ( leds [ config -> channel ] , LEDS_ACTIVE_STATE ) ; } else { platform_gpio_write ( leds [ config -> channel ] , ! LEDS_ACTIVE_STATE ) ; } } else { config -> channel = ENDPOINT_INVALID ; success = false ; } uint8_t source = message -> source_endpoint ; message -> source_endpoint = message -> destination_endpoint ; message -> destination_endpoint = source ; message -> type = ACKNOWLEDGEMENT ; if ( success ) { memset ( message -> payload , 0 , sizeof ( message -> payload ) ) ; } return ENDPOINT_SUCCESS ; }
TODO: send back error if type is not actuator configuration.
TODO : send back error if type is not actuator configuration .
// Signal error by writing invalid to channel // If message was understood, switch destination and source, set type as acknowledgement // and set payload to success