Ejemplo n.º 1
0
void
stella_dmx(uint8_t* dmx_data, uint8_t len)
{
	// length
	if (len<2) return; // no real data, abort
	--len; // ignore first byte (defines fade function)
	if (STELLA_PINS < len) len = STELLA_PINS;

	for (uint8_t i=0;i<len;++i)
		stella_setValue(dmx_data[0], i, dmx_data[i+1]);
}
Ejemplo n.º 2
0
inline void checkRunningTicks(void) {
    if (runningticksWithoutChange>200) {
        state = SensorNotWorkingState;
        currentposition = -1;
        setMotor(0, DirectionDown);
        stella_setValue(STELLA_SET_IMMEDIATELY, 0, 255);
        stella_process();
        return;
    }

}
Ejemplo n.º 3
0
void
udpstella_net_main(void)
{
    if (!uip_newdata ())
	return;

    uip_slen = 0;
    uint16_t len = uip_len;
    uint8_t buffer[uip_len];
    memcpy(buffer, uip_appdata, uip_len);

    struct udpstella_packet* packet = (struct udpstella_packet*)buffer;
    uint8_t* answer = uip_appdata;

    while (len>=sizeof(struct udpstella_packet)) {
	    if (packet->type == STELLA_GETALL) {
		answer[0] = 's';
		answer[1] = 't';
		answer[2] = 'e';
		answer[3] = 'l';
		answer[4] = 'l';
		answer[5] = 'a';
		answer[6] = (uint8_t)STELLA_CHANNELS;
		for (uint8_t c=0;c<STELLA_CHANNELS;++c) {
			answer[7+c] = stella_brightness[c];
		}
		uip_slen += STELLA_CHANNELS+6;
		answer += STELLA_CHANNELS+6;
	    } else {
			stella_setValue(packet->type, packet->channel, packet->value);
	    }
     	packet++;
     	len-=sizeof(struct udpstella_packet);
     }

    if (uip_slen == 0) return;
	/* Sent data out */

	uip_udp_conn_t echo_conn;
	uip_ipaddr_copy(echo_conn.ripaddr, BUF->srcipaddr);
	echo_conn.rport = BUF->srcport;
	echo_conn.lport = HTONS(UDP_STELLA_PORT);

	uip_udp_conn = &echo_conn;
	uip_process(UIP_UDP_SEND_CONN);
	router_output();

	uip_slen = 0;

}
Ejemplo n.º 4
0
int16_t parse_cmd_stella_channel (char *cmd, char *output, uint16_t len)
{
	char f=0;
	uint8_t ch=0;
	uint8_t value=0;
	int8_t ret = 0;
	if (cmd[0]!=0) ret = sscanf_P(cmd, PSTR("%u %u %c"), &ch, &value, &f);
	
	if (f=='s') f = 0; // set
	else if (f=='f') f = 1; // fade
	else if (f=='y') f = 2; // fade variant 2

	// return all channel values
	if (ret == 0)
	{
		ret = 0;
		for (ch = 0; ch<STELLA_PINS*4; ch+=4,++ret)
		{
			value = stella_getValue(ret);
			output[ch+2] = value%10 +48;
			value /= 10;
			output[ch+1] = value%10 +48;
			value /= 10;
			output[ch+0] = value%10 +48;
			output[ch+3] = '\n';
		}
		if (ch>0) --ch;
		return ch;
	}
	// return one channel value
	else if (ret == 1)
	{
		if (ch>=STELLA_PINS) return ECMD_ERR_PARSE_ERROR;

		return ECMD_FINAL(snprintf_P(output, len, PSTR("%u"), stella_getValue(ch)));
	}
	// else set channel to value
	else if (ret >= 2)
	{
		if (ch>=STELLA_PINS) return ECMD_ERR_PARSE_ERROR;
		stella_setValue(f, ch, value);

		return ECMD_FINAL_OK;
	}
	else
		return ECMD_ERR_PARSE_ERROR;
}
Ejemplo n.º 5
0
void
stella_process(void)
{
#ifdef DMX_STORAGE_SUPPORT
  if (get_dmx_slot_state(STELLA_UNIVERSE, stella_dmx_conn_id) ==
      DMX_NEWVALUES)
  {
    uint8_t mode =
      get_dmx_channel_slot(STELLA_UNIVERSE, STELLA_UNIVERSE_OFFSET,
                           stella_dmx_conn_id);
    for (uint8_t i = 0; i < STELLA_CHANNELS; i++)
    {
      stella_setValue(mode, i,
                      get_dmx_channel_slot(STELLA_UNIVERSE,
                                           STELLA_UNIVERSE_OFFSET + i + 1,
                                           stella_dmx_conn_id));
    }
  }
#endif
  /* the main loop is too fast, slow down */
  if (stella_fade_counter == 0)
  {
    uint8_t i;
    /* Fade channels. stella_fade_counter is 0 currently. Set to 1
     * if fading changed a channel brigthness value */
    for (i = 0; i < STELLA_CHANNELS; ++i)
    {
      if (stella_brightness[i] == stella_fade[i])
        continue;

      stella_fade_funcs[stella_fade_func].p(i);

      stella_fade_counter = 1;
    }

    if (stella_fade_counter)
      stella_sync = UPDATE_VALUES;

    /* reset counter */
    stella_fade_counter = stella_fade_step;
  }

  /* sort if new values are available */
  if (stella_sync == UPDATE_VALUES)
    stella_sort();
}
Ejemplo n.º 6
0
/* Process recurring actions for moodlight */
void
moodlight_process (void)
{
	/* Only do something if any of the channels is selected
	 * to be 'moodlighted' and the moodlight counter reached
	 * the threshold value. */
	if (moodlight_mask && moodlight_counter == moodlight_threshold)
	{
		for (uint8_t i = 0; i < STELLA_CHANNELS; ++i)
		{
			if (moodlight_mask & _BV(i))
				stella_setValue(1, i, LO8(rand()));
		}

		moodlight_counter = 0;
	}
	else
		moodlight_counter ++;
}
Ejemplo n.º 7
0
int main(void)
{
    // Alles TriState
    DDRA = 0;
    DDRB = 0;
    DDRC = 0;
    DDRD = 0;
    PORTA = 0;
    PORTB = 0;
    PORTC = 0;
    PORTD = 0;

    // save power
    MCUCR |= _BV(JTD);
    PRR |= _BV(PRTWI) | _BV(PRSPI) | _BV(PRADC);
    //ADCSRA &= ~_BV(ADEN);
    //ACSR |=_BV(ACD);

    // Power Led
    DDRA|=_BV(7);
    PIN_SET(A,7);

    sei();

    // Init: Subsysteme
    uart_init(UART_BAUD_SELECT(BAUD,F_CPU));
    stella_init();
//     curtain_init();
    //sensors_init();

    // Init: Variablen
    enum stateEnum {
        StateCommands,
        StateCurtainValue,
        StateLedChannel,
        StateLedValue
    } laststate, state = StateCommands;

    uint8_t slowdown_counter = 0;
    uint8_t slowdown_counter2 = 0;
    uint8_t panic_counter = 0;
	uint8_t panic_counter_led = 0;
	uint8_t panic_counter_brightness = 0;
    uint8_t stella_channel = 0;
    enum stella_set_function stella_fading = STELLA_SET_IMMEDIATELY;

	uint8_t packetPosition = 0;
	unsigned char lastChar, haslastChar = 0;
    slowdown_counter = 0;
    slowdown_counter2 = 0;
    stella_setValue(STELLA_SET_IMMEDIATELY, 0, 0);
    stella_process();

	 wdt_enable(WDTO_250MS);
	#define PANIC_THRESHOLD 150
    // Hauptprogramm
    while (1) {
		wdt_reset();
        stella_process();
        curtain_process();
        //sensors_process();

        //panic counter
        if (++slowdown_counter == 0) {

            if (++slowdown_counter2==0) {
                if (panic_counter < PANIC_THRESHOLD)
                    ++panic_counter;
            }
            
			if (panic_counter == PANIC_THRESHOLD) {
				panic_counter = PANIC_THRESHOLD+1;
				panic_counter_led = 0;
				panic_counter_brightness = 0;
				packetPosition = 0;
				storeValues();
				PIN_SET(A,6);
			}
			if (panic_counter == PANIC_THRESHOLD+1) {
				if (panic_counter_brightness==255) {
					panic_counter=PANIC_THRESHOLD+2;
					continue;
				}
				stella_setValue(STELLA_SET_FADE, panic_counter_led, ++panic_counter_brightness);
			}
			if (panic_counter == PANIC_THRESHOLD+2) {
				if (panic_counter_brightness==0) {
					panic_counter=PANIC_THRESHOLD+1;
					if (++panic_counter_led >= STELLA_CHANNELS)
						panic_counter_led = 0;
					continue;
				}
				stella_setValue(STELLA_SET_FADE, panic_counter_led, --panic_counter_brightness);
			}
        }

		uint16_t r = uart_getc();
		uint8_t info = r >> 8;
		if (r == UART_NO_DATA)
			continue;
		else if (info!=0) {
			PIN_SET(A,6);
			PIN_SET(A,7);
			packetPosition = 0;
			continue;
		}
		
		const unsigned char temp = haslastChar ? lastChar : 0;
		haslastChar = 1;
		lastChar = r & 0xff;
		if (lastChar == 0xff && temp == 0xff) { // two proceeding 255-values start a valid packet
			packetPosition = 1;
			state = StateCommands;
			continue;
		}

		if (!packetPosition)
			continue;
        
		// reset panic counter
		if (panic_counter) {
			if (panic_counter>=110) {
				restoreValues();
				PIN_CLEAR(A,6);
			}
			panic_counter = 0;
		}
		
		laststate = state;
		switch (state) {
		case StateCommands:
			switch (lastChar) {
			case 0xef: // get values
				sendInit();
				sendStella();
				//sendSensor();
				sendMotor();
				break;
			case 0xdf: // prepare for a curtain value
				state = StateCurtainValue;
				break;
			case 0xcf: // prepare for a led channel and value (fade:immediately)
				state = StateLedChannel;
				stella_fading = STELLA_SET_IMMEDIATELY;
				break;
			case 0xbf: // prepare for a led channel and value (fade:fade)
				state = StateLedChannel;
				stella_fading = STELLA_SET_FADE;
				break;
			case 0xaf: // prepare for a led channel and value (fade:fade flashy)
				state = StateLedChannel;
				stella_fading = STELLA_SET_FLASHY;
				break;
			case 0x9f: // prepare for a led channel and value (fade:fade immediately+relative)
				state = StateLedChannel;
				stella_fading = STELLA_SET_IMMEDIATELY_RELATIVE;
				break;
			case 0x00: // reset panic counter and acknowdlegde
				sendAck();
				break;
			}
			break;
		case StateCurtainValue:
			state = StateCommands;
			curtain_setPosition(lastChar);
			break;
		case StateLedChannel:
			state = StateLedValue;
			stella_channel = lastChar;
			break;
		case StateLedValue:
			state = StateCommands;
			stella_setValue(stella_fading, stella_channel, lastChar);
			break;
		}
		// the state has not changed -> a full packet has been received -> prepare for the next one
		if (laststate==state) {
			packetPosition=0;
		}
    }
    return 0;
}
Ejemplo n.º 8
0
inline void restoreValues(void) {
	for (uint8_t i=0;i<STELLA_CHANNELS;++i) {
		stella_setValue(STELLA_SET_FADE, i, storedValues[i]);
	}
}
Ejemplo n.º 9
0
inline void storeValues(void) {
	for (uint8_t i=0;i<STELLA_CHANNELS;++i) {
		storedValues[i] = stella_getValue(i);
		stella_setValue(STELLA_SET_FADE, i, 0);
	}
}