コード例 #1
0
ファイル: dmx_storage_ecmd.c プロジェクト: buttonger/ethersex
int16_t parse_cmd_dmx_get_universe(char *cmd, char *output, uint16_t len)
{
	uint16_t ret=0, universe=0;
	uint8_t value=0;
	if (cmd[0]!=0) ret = sscanf_P(cmd, PSTR("%u"), &universe);
	if(ret == 1 && universe < DMX_STORAGE_UNIVERSES)
	{
		ret=0;
		static uint16_t chan = 0;
		value=get_dmx_channel(universe,chan);
		output[ret+2] = value%10 +48;
		value /= 10;
		output[ret+1] = value%10 +48;
		value /= 10;
		output[ret+0] = value%10 +48;
		ret+=3;
		if(chan < DMX_STORAGE_CHANNELS-1)
		{
			chan++;
			return ECMD_AGAIN(ret);
		}
		else
		{
			chan=0;
			return ECMD_FINAL(ret);
		}

	}
	else
		return ECMD_ERR_PARSE_ERROR;
}
コード例 #2
0
ファイル: dmx_storage.c プロジェクト: JYzor/ethersex
uint8_t
get_dmx_channel_slot(uint8_t universe, uint16_t channel, int8_t slot)
{
    if (slot < DMX_STORAGE_SLOTS && slot >= 0)
        dmx_universes[universe].slots[slot].slot_state = DMX_UNCHANGED;
    return get_dmx_channel(universe, channel);
}
コード例 #3
0
int16_t
parse_cmd_dmx_get_universe(char *cmd, char *output, uint16_t len)
{
  uint16_t ret = 0;
  uint8_t value = 0, universe = 0;
  /* trick: use bytes on cmd as "connection specific static variables" */
  if (cmd[0] != ECMD_STATE_MAGIC) /* indicator flag: real invocation:  0 */
  {
    /* read universe */
    ret = sscanf_P(cmd, PSTR("%hhu"), &universe);
    if (ret != 1 || universe >= DMX_STORAGE_UNIVERSES)
      return ECMD_ERR_PARSE_ERROR;
    cmd[0] = ECMD_STATE_MAGIC;    /* continuing call: 23 */
    cmd[1] = universe;            /* universe */
    cmd[2] = 0;                   /* reserved for chan */
    cmd[3] = 0;                   /* reserved for chan */
  }
  /* retrieve universe from *cmd */
  universe = cmd[1];
  /* retrieve chan from *cmd. chan is 16 bit. 
     cmd[1] in 16 bit is cmd[2] and cmd[3] in 8-bit */
  uint16_t chan = *((uint16_t *) (cmd) + 1);
  /* request value from dmx-storage */
  value = get_dmx_channel(universe, chan);
  /* write the value to *output with leading 0 so that the output 
     will be like this:
     255
     044
     003
     000
  */
  /* ones */
  output[2] = value % 10 + 48;
  value /= 10;
  /* tens */
  output[1] = value % 10 + 48;
  value /= 10;
  /* hundreds */
  output[0] = value % 10 + 48;
  /* Newline to be better parseable with http */
  output[3] = '\n' ;
  /* terminate string */
  output[4] = '\0';
  ret = 5;
  if (chan < DMX_STORAGE_CHANNELS - 1)
  {
    chan++;
    *((uint16_t *) (cmd) + 1) = chan;
    return ECMD_AGAIN(ret);
  }
  else
    return ECMD_FINAL(ret);
}
コード例 #4
0
ファイル: dmx_storage_ecmd.c プロジェクト: buttonger/ethersex
int16_t parse_cmd_dmx_get_channel(char *cmd, char *output, uint16_t len)
{
	uint16_t ret=0, channel=0, universe=0;
	if (cmd[0]!=0) ret = sscanf_P(cmd, PSTR("%u %u"), &universe, &channel);
	if(ret == 2)
	{
		if (channel >= DMX_STORAGE_CHANNELS)
			return ECMD_ERR_PARSE_ERROR;
		if (universe >= DMX_STORAGE_UNIVERSES)
			return ECMD_ERR_PARSE_ERROR;
		itoa(get_dmx_channel(universe,channel), output, 10);
		return ECMD_FINAL(strlen(output));
	}
	else
		return ECMD_ERR_PARSE_ERROR;
}
コード例 #5
0
ファイル: dmx-effect.c プロジェクト: Zefiro/ethersex
void dmx_effect_random_colors_show()
{
	for(uint8_t i=0;i<DMX_EFFECT_RANDOM_CHANNELS+DMX_EFFECT_RANDOM_CHANNELS*DMX_EFFECT_RANDOM_MARGIN;i++)
	{
		#if (DMX_EFFECT_RAINBOW_MARGIN > 0)
		for(uint8_t j=0;j<DMX_EFFECT_RANDOM_MARGIN;j++)
		{
			set_dmx_channel(DMX_EFFECT_RANDOM_UNIVERSE, DMX_EFFECT_RANDOM_OFFSET+i,DMX_EFFECT_RANDOM_MARGIN_FILL);
			i++;
		}
		#endif 
		uint8_t tmp_value=get_dmx_channel(DMX_EFFECT_RANDOM_UNIVERSE,DMX_EFFECT_RANDOM_OFFSET+i);
		uint8_t target_value=random_channels[(i+1)/(DMX_EFFECT_RANDOM_MARGIN+1)-1];
		if(tmp_value > target_value)
			set_dmx_channel(DMX_EFFECT_RANDOM_UNIVERSE,DMX_EFFECT_RANDOM_OFFSET+i,tmp_value-1);
		else if (tmp_value < target_value)
			set_dmx_channel(DMX_EFFECT_RANDOM_UNIVERSE,DMX_EFFECT_RANDOM_OFFSET+i,tmp_value+1);
		//else == : we do nothing, everything's set

	}
}
コード例 #6
0
ファイル: dmx-effect.c プロジェクト: strfry/ethersex
void dmx_effect_rainbow_colors(void)
{
	color_r = get_dmx_channel(DMX_EFFECT_RAINBOW_UNIVERSE,DMX_EFFECT_RAINBOW_OFFSET+3);
	color_g = get_dmx_channel(DMX_EFFECT_RAINBOW_UNIVERSE,DMX_EFFECT_RAINBOW_OFFSET+4);
	color_b = get_dmx_channel(DMX_EFFECT_RAINBOW_UNIVERSE,DMX_EFFECT_RAINBOW_OFFSET+5);

	static uint8_t rainbow_step = 0;
	static uint16_t rainbow_delay = 0;
	if (rainbow_delay++ <= (RAINBOW_DELAY / DMX_STORAGE_CHANNELS)) return;
	rainbow_delay = 0;

	int lumdist = (color_r + color_g + color_b - 127 - 256);

	if (lumdist > 0) {
//            color_r--;
        } else if (lumdist < 0) {
//            color_r++;
        }

	switch(rainbow_step) {
		case 0:
			if (color_g > 1) {
				color_g--;
				color_b++;
			} else {
				rainbow_step++;
			}
			break;
		case 1:
			if (color_r > 1) {
				color_r--;
				color_g++;
			} else {
				rainbow_step++;
			}
			break;
		case 2:
			if (color_b > 1) {
				color_b--;
				color_r++;
			} else {
				rainbow_step = 0;
			}
			break;
	}
	/*Copy colors to dmx storage*/
	for(uint16_t i=0;i<DMX_EFFECT_RAINBOW_CHANNELS+(DMX_EFFECT_RAINBOW_MARGIN*DMX_EFFECT_RAINBOW_CHANNELS);i++)
	{
	    
	
#if (DMX_EFFECT_RAINBOW_MARGIN > 0)
		for(uint8_t j=0;j<DMX_EFFECT_RAINBOW_MARGIN;j++)
		{
			set_dmx_channel(DMX_EFFECT_RAINBOW_UNIVERSE, DMX_EFFECT_RAINBOW_OFFSET+i,DMX_EFFECT_RAINBOW_MARGIN_FILL);
			i++;
		}
#endif 

		int pos = i + (i - 1 ) / 15;
			
		if(i%(DMX_EFFECT_RAINBOW_MARGIN*3+3) == DMX_EFFECT_RAINBOW_MARGIN)
			set_dmx_channel(DMX_EFFECT_RAINBOW_UNIVERSE,DMX_EFFECT_RAINBOW_OFFSET+pos,color_r);
		if(i%(DMX_EFFECT_RAINBOW_MARGIN*3+3) == 2*DMX_EFFECT_RAINBOW_MARGIN+1)
			set_dmx_channel(DMX_EFFECT_RAINBOW_UNIVERSE,DMX_EFFECT_RAINBOW_OFFSET+pos,color_g);
		if(i%(DMX_EFFECT_RAINBOW_MARGIN*3+3) == 3*DMX_EFFECT_RAINBOW_MARGIN+2)
			set_dmx_channel(DMX_EFFECT_RAINBOW_UNIVERSE,DMX_EFFECT_RAINBOW_OFFSET+pos,color_b);
		
	}
}