/** * plugin setter - this will be called if core wants to set stuff * @note you don't need to implement a setter for every LedPluginParam */ NftResult _set_handler(void *privdata, LedPluginParam o, LedPluginParamData * data) { struct priv *p = privdata; /** decide about type of data (s. hardware.h) */ switch (o) { case LED_HW_ID: { strncpy(p->id, data->id, sizeof(p->id)); return NFT_SUCCESS; } case LED_HW_LEDCOUNT: { /* resize buffer */ /* if(!(p->txBuffer = realloc(p->txBuffer, * data->ledcount))) { NFT_LOG_PERROR("realloc"); * return NFT_FAILURE; } */ /* save ledcount */ p->ledcount = data->ledcount; return NFT_SUCCESS; } case LED_HW_GAIN: { NFT_TODO(); return NFT_SUCCESS; } /* handle dynamic custom properties - we can read out * data->custom.value.[s|i|f] and * data->custom.valuesize */ case LED_HW_CUSTOM_PROP: { if(strcmp(data->custom.name, "spi_speed") == 0) { /* set new value */ p->spiSpeed = (uint32_t) data->custom.value.i; NFT_LOG(L_DEBUG, "Setting \"spi_speed\" of \"%s\" to %u", p->id, p->spiSpeed); return NFT_SUCCESS; } else if(strcmp(data->custom.name, "spi_delay") == 0) { /* set new value */ p->spiDelay = (uint16_t) data->custom.value.i; NFT_LOG(L_DEBUG, "Setting \"spi_delay\" of \"%s\" to %hu", p->id, p->spiDelay); return NFT_SUCCESS; } else { NFT_LOG(L_ERROR, "Unhandled custom property \"%s\"", data->custom.name); return NFT_FAILURE; } } default: { return NFT_SUCCESS; } } return NFT_FAILURE; }
/** * plugin setter - this will be called if core wants to set stuff * @note you don't need to implement a setter for every LedPluginParam */ NftResult _set_handler(void *privdata, LedPluginParam o, LedPluginParamData * data) { struct priv *p = privdata; /** decide about type of data (s. hardware.h) */ switch (o) { case LED_HW_ID: { strncpy(p->id, data->id, sizeof(p->id)); return NFT_SUCCESS; } case LED_HW_LEDCOUNT: { /* validate range */ if(data->ledcount > 512) { NFT_LOG(L_ERROR, "This hardware can't control less than 0 or more than 512 LEDs"); return NFT_SUCCESS; } /* ledcount must be a multiple of 8 */ // if(data->ledcount % 8 != 0) { p->ledcount = // (data->ledcount/8+1)*8; NFT_LOG(L_WARNING, "Ledcount // // // // // // (%d) is no multiple of 8, using %d.", // data->ledcount, p->ledcount); } else { p->ledcount = data->ledcount; // } /* set chipcount at arduino */ char chipcount = (char) (p->ledcount % 64 == 0 ? p->ledcount / 64 : p->ledcount / 8 + 1); NFT_LOG(L_DEBUG, "Setting chipcount to %d", chipcount); return ad_setChipcount(p, chipcount); } case LED_HW_GAIN: { NFT_TODO(); return NFT_SUCCESS; } /* handle dynamic custom properties - we can read out * data->custom.value.[s|i|f] and * data->custom.valuesize */ case LED_HW_CUSTOM_PROP: { if(strcmp(data->custom.name, "threshold") == 0) { /* validate */ if(data->custom.value.i < 0 || data->custom.value.i > 255) { NFT_LOG(L_ERROR, "threshold may only be 0-255. Not changing it."); return NFT_FAILURE; } /* set new value */ p->threshold = (unsigned char) data->custom.value.i; NFT_LOG(L_DEBUG, "Setting \"threshold\" of \"%s\" to %d", p->id, p->threshold); return NFT_SUCCESS; } else if(strcmp(data->custom.name, "scan_limit") == 0) { /* validate */ if(data->custom.value.i < 0 || data->custom.value.i >= 8) { NFT_LOG(L_ERROR, "Scan limit %d outside range (0-7)", data->custom.value.i); return NFT_FAILURE; } /* set new value */ p->scan_limit = (unsigned char) data->custom.value.i; NFT_LOG(L_DEBUG, "Setting \"scan_limit\" of \"%s\" to %d", p->id, p->threshold); ad_setScanLimit(p, p->scan_limit); return NFT_SUCCESS; } else { NFT_LOG(L_ERROR, "Unhandled custom property \"%s\"", data->custom.name); return NFT_FAILURE; } } default: { return NFT_SUCCESS; } } return NFT_FAILURE; }