void draw_led_element (char* cp) {

_E_LED_t*	p;
uint8_t		m;
uint8_t		s;

	p = (_E_LED_t*) cp;

	XRAM_SELECT_BLOCK(XRAM_PAGE_PAGE);

	/* binary or radio button function? */
	if (p->parameter & LED_PARAMETER_RADIO) {
		s = p->repeat_radio_value == eib_get_object_8_value (p->eib_object_listen);
	}
	else {
		m = 1 << (p->parameter & LED_PARAMETER_BITPOS);
		s = eib_get_object_8_value (p->eib_object_listen) & m;
	}
	XRAM_SELECT_BLOCK(XRAM_PAGE_PAGE);
	if (s) {
		XRAM_SELECT_BLOCK(XRAM_PAGE_PAGE);
		if (p->parameter & LED_PARAMETER_WARNING) {
			draw_picture (p->picture_warning_index, p->x_pos, p->y_pos);
			set_backlight_on ();
			XRAM_SELECT_BLOCK(XRAM_PAGE_PAGE);
			sound_play_clip (p->sound_index_warning, p->repeat_radio_value);
		}
		else {
			draw_picture (p->picture_on_index, p->x_pos, p->y_pos);
		}
	}
	else {
		draw_picture (p->picture_off_index, p->x_pos, p->y_pos);
	}
}
Example #2
0
void check_led_object (char* cp, uint8_t tflags) {

_O_LED_t*	p;
uint8_t			eib_value;

	p = (_O_LED_t*) cp;

	// get new value
	eib_value = eib_get_object_8_value (p->eib_object_listen);
	XRAM_SELECT_BLOCK(XRAM_LISTEN_ELEMENTS_PAGE);

	// get led output value for led state
uint8_t lc; // led config
uint8_t ls; // led state
uint8_t lf; // led frequency
	if (eib_value)
		lc = (p->parameter >> 2) & 0x03;
	else 
uint8_t check_led_warning_state (char* cp, uint8_t warning_toggle) {

_E_LED_t*	p;

		p = (_E_LED_t*) cp;

		/* warning function? */
		if (p->parameter & LED_PARAMETER_WARNING) {
			if (eib_get_object_8_value (p->eib_object_listen)) {
				XRAM_SELECT_BLOCK(XRAM_PAGE_PAGE);
				if (warning_toggle)
					draw_picture (p->picture_warning_index, p->x_pos, p->y_pos);
				else
					draw_picture (p->picture_on_index, p->x_pos, p->y_pos);
				return 1;
			}
		}
		return 0;
}
// copies data from Flash to xram. Can NOT handle sector overflows!
// stores data starting from 1st XRAM Bank address
void copy_Flash_to_XRAM (uint8_t flash_sector, uint16_t flash_offset, uint8_t xram_block, uint16_t xram_offset, uint16_t byte_count) {

uint16_t 	fdata;
volatile uint8_t*	p;


	if (!byte_count)
		return;

	p = (uint8_t*)(xram_offset+XRAM_BASE_ADDRESS);
	// set xram page
	XRAM_SELECT_BLOCK (xram_block);

	// check, if starting on odd byte address
	if (flash_offset & 0x01) {
		fdata = read_flash (flash_sector, (flash_offset >> 1) & 0x7fff);
		*p++ = (fdata >> 8) & 0xff;
		byte_count--;
	}
uint8_t touch_led_element (char *cp, t_touch_event *evt, uint8_t *touch_state) {

_E_LED_t*	p;
uint16_t	width, height;
uint8_t 	hit;
uint8_t		eib_value;

	p = (_E_LED_t*) cp;
	// check, if this element is sensitive to touch events
	if (!(p->parameter & LED_PARAMETER_SEND))
		return 1;

	get_picture_size (p->picture_on_index, &width, &height);
	hit = (p->x_pos < evt->lx) && (p->y_pos < evt->ly) && (p->x_pos + width > evt->lx) && (p->y_pos + height > evt->ly);

	// are we already touched?
	if (*touch_state) {
		// yes, this element is still touched
		if (evt->state == RELEASED) {

			// user released the touch screen
			sound_play_clip (p->sound_index_up, 0);
			XRAM_SELECT_BLOCK(XRAM_PAGE_PAGE);

			return 1;
		}
		else {
			// moved finger. Check, if element is still hit or not and adjust bitmap accordingly
			if (hit && (*touch_state == 1)) {
				*touch_state = 2;
			}
			if (!hit && (*touch_state == 2)) {
				*touch_state = 1;
			}
			return 0;
		}
	}
	else {
		// no, element is not yet touched
		if (!hit)
			return 1;
		// we are touched first time, if event is TOUCHED
		if (evt->state == TOUCHED) {
			*touch_state = 2;
			sound_play_clip (p->sound_index_down, 0);
			XRAM_SELECT_BLOCK(XRAM_PAGE_PAGE);
		}
		else return 1;
		// now we are touched first time

		/* execute activity depending on the LED function type */
		if (p->parameter & LED_PARAMETER_WARNING) {
			/* Warning element can switch off only */
			eib_value = 0x00;
			XRAM_SELECT_BLOCK(XRAM_PAGE_PAGE);
			eib_G_DATA_request(get_group_address (p->eib_object_send), &eib_value, 0);
		}
		else if (p->parameter & LED_PARAMETER_RADIO) {
			/* Radio button element always sends its own ID */
			eib_value = p->repeat_radio_value;
			XRAM_SELECT_BLOCK(XRAM_PAGE_PAGE);
			eib_G_DATA_request(get_group_address (p->eib_object_send), &eib_value, 1);
		}
		else {
			/* Indicator LED always toggles its object value */
			eib_value = eib_get_object_8_value (p->eib_object_listen);
			if (eib_value)
				eib_value = 0x00;
			else
				eib_value = 0x01;
			XRAM_SELECT_BLOCK(XRAM_PAGE_PAGE);
			eib_G_DATA_request(get_group_address (p->eib_object_send), &eib_value, 0);
		}

		return 0;
	}
}
void ir_button_pressed (char *cp, uint8_t evt) {

_IR_BUTTON_t*	p;
uint8_t		eib_object;
uint8_t		eib_value[2];
int			new_value;
float		fval;

	p = (_IR_BUTTON_t*) cp;
	
	// check, if address and command match
	if ((p->rc5_address != rc5_a) || (p->rc5_command != rc5_c))
		return;

	if (evt == RC5_RELEASED_LONG) {

		// check, if we have to execute an activity
		switch (p->eib_function) {

			case EIB_BUTTON_FUNCTION_BRIGHTER:
			case EIB_BUTTON_FUNCTION_DARKER:
				// dimm stop
				eib_value[0] = 0x00;
				eib_G_DATA_request(get_group_address (p->eib_object0), eib_value, 0);
			break;
			case EIB_BUTTON_FUNCTION_ON_BRIGHTER:
			case EIB_BUTTON_FUNCTION_OFF_DARKER:
				// dimm stop
				eib_value[0] = 0x00;
				eib_G_DATA_request(get_group_address (p->eib_object1), eib_value, 0);
			break;
		}
	}
	else if (evt == RC5_RELEASED_SHORT) {
		// button has been touched for short time and is released now

		switch (p->eib_function) {

			case EIB_BUTTON_FUNCTION_BRIGHTER:
			case EIB_BUTTON_FUNCTION_DARKER:
				// dimm stop
				eib_value[0] = 0x00;
				eib_G_DATA_request(get_group_address (p->eib_object0), eib_value, 0);
			break;
			case EIB_BUTTON_FUNCTION_ON_BRIGHTER:
				// switch on
				eib_value[0] = 0x01;
				eib_G_DATA_request(get_group_address (p->eib_object0), eib_value, 0);
			break;
			case EIB_BUTTON_FUNCTION_OFF_DARKER:
				// switch off
				eib_value[0] = 0x00;
				eib_G_DATA_request(get_group_address (p->eib_object0), eib_value, 0);
			break;
		}
	}
	else if (evt == RC5_PRESSED_LONG) {

		switch (p->eib_function) {
			case EIB_BUTTON_FUNCTION_ON_BRIGHTER:
				// dimm up
				eib_value[0] = 0x09;
				eib_G_DATA_request(get_group_address (p->eib_object1), eib_value, 0);
			break;
			case EIB_BUTTON_FUNCTION_OFF_DARKER:
				// dimm down
				eib_value[0] = 0x01;
				eib_G_DATA_request(get_group_address (p->eib_object1), eib_value, 0);
			break;
			case EIB_BUTTON_FUNCTION_UP_STEPUP:
				// go up
				eib_value[0] = 0x00;
				eib_G_DATA_request(get_group_address (p->eib_object0), eib_value, 0);
			break;
			case EIB_BUTTON_FUNCTION_DOWN_STEPDOWN:
				// go down
				eib_value[0] = 0x01;
				eib_G_DATA_request(get_group_address (p->eib_object0), eib_value, 0);
			break;
		}
	}
	else if (evt == RC5_PRESSED_AUTO) {

		switch (p->eib_function) {
			case EIB_BUTTON_FUNCTION_STEPUP:
				// go up
				eib_value[0] = 0x00;
				eib_G_DATA_request(get_group_address (p->eib_object0), eib_value, 0);
			break;
			case EIB_BUTTON_FUNCTION_STEPDOWN:
				// go down
				eib_value[0] = 0x01;
				eib_G_DATA_request(get_group_address (p->eib_object0), eib_value, 0);
			break;
			case EIB_BUTTON_FUNCTION_DELTA_EIS6:
				// add delta value to 8bit object and send it
				eib_object = p->eib_object0;
				eib_value[0] = eib_get_object_8_value (p->eib_object0);
				XRAM_SELECT_BLOCK(XRAM_CYCLIC_ELEMENTS_PAGE);
				new_value = eib_value[0] + (int8_t) p->value[0];
/*				if (new_value < p->min) { 
					new_value = p->min;
				}
				if (new_value > p->max) { 
					new_value = p->max;
				} */
				if (new_value < 0) { 
					new_value = 0;
				}
				if (new_value > 255) { 
					new_value = 255;
				}
				eib_value[0] = new_value & 0xff;
				eib_G_DATA_request(get_group_address(eib_object), eib_value, 1);
			break;
			case EIB_BUTTON_FUNCTION_DELTA_EIS5:
				// add delta value to 16bit EIS5 object and send it
				eib_object = p->eib_object0;
				fval = eib_get_object_EIS5_value (eib_object);
				XRAM_SELECT_BLOCK(XRAM_CYCLIC_ELEMENTS_PAGE);
				fval += (float) ((int8_t) p->value[0])/10;
				// check, if the new value is inside of the bounds
/*				if (10*fval < p->min) { 
					fval = p->min;
					fval /= 10;
				}
				if (10*fval > p->max) { 
					fval = p->max;
					fval /= 10;
				} */
				if (fval < -100.0) { 
					fval = -100.0;
				}
				if (fval > 100.0) { 
					fval = 100.0;
				}
				// send new value as EIS5
				eib_set_object_EIS5_value(get_group_address(eib_object), fval);
			break;
		}
	}
	else if (evt == RC5_PRESSED_NEW) {
		switch (p->eib_function) {
			case EIB_BUTTON_FUNCTION_TOGGLE:
				eib_object = p->eib_object0;
				eib_value[0] = eib_get_object_8_value (p->eib_object1);
				if (eib_value[0])
					eib_value[0] = 0x00;
				else
					eib_value[0] = 0x01;
				eib_G_DATA_request(get_group_address (eib_object), eib_value, 0);
			break;
			case EIB_BUTTON_FUNCTION_ON:
				// switch on
				eib_value[0] = 0x01;
				eib_G_DATA_request(get_group_address (p->eib_object0), eib_value, 0);
			break;
			case EIB_BUTTON_FUNCTION_OFF:
				// switch off
				eib_value[0] = 0x00;
				eib_G_DATA_request(get_group_address (p->eib_object0), eib_value, 0);
			break;
			case EIB_BUTTON_FUNCTION_BRIGHTER:
				// dimm up
				eib_value[0] = 0x09;
				eib_G_DATA_request(get_group_address (p->eib_object0), eib_value, 0);
			break;
			case EIB_BUTTON_FUNCTION_DARKER:
				// dimm down
				eib_value[0] = 0x01;
				eib_G_DATA_request(get_group_address (p->eib_object0), eib_value, 0);
			break;
			case EIB_BUTTON_FUNCTION_UP:
			case EIB_BUTTON_FUNCTION_STEPUP:
				// go up
				eib_value[0] = 0x00;
				eib_G_DATA_request(get_group_address (p->eib_object0), eib_value, 0);
			break;
			case EIB_BUTTON_FUNCTION_DOWN:
			case EIB_BUTTON_FUNCTION_STEPDOWN:
				// go down
				eib_value[0] = 0x01;
				eib_G_DATA_request(get_group_address (p->eib_object0), eib_value, 0);
			break;
			case EIB_BUTTON_FUNCTION_UP_STEPUP:
				// go up
				eib_value[0] = 0x00;
				eib_G_DATA_request(get_group_address (p->eib_object1), eib_value, 0);
			break;
			case EIB_BUTTON_FUNCTION_DOWN_STEPDOWN:
				// go down
				eib_value[0] = 0x01;
				eib_G_DATA_request(get_group_address (p->eib_object1), eib_value, 0);
			break;
			case EIB_BUTTON_FUNCTION_8BIT_VALUE:
				eib_object = p->eib_object0;
				eib_value[0] = p->value[0];
				eib_G_DATA_request(get_group_address (eib_object), eib_value, 1);
			break;
			case EIB_BUTTON_FUNCTION_16BIT_VALUE:
				eib_object = p->eib_object0;
				eib_value[0] = p->value[1];
				eib_value[1] = p->value[0];
				eib_G_DATA_request(get_group_address (eib_object), eib_value, 2);
			break;
			case EIB_BUTTON_FUNCTION_DELTA_EIS6:
				// add delta value to 8bit object and send it
				eib_object = p->eib_object0;
				eib_value[0] = eib_get_object_8_value (p->eib_object0);
				XRAM_SELECT_BLOCK(XRAM_CYCLIC_ELEMENTS_PAGE);
				new_value = eib_value[0] + (int8_t) p->value[0];
/*				if (new_value < p->min) { 
					new_value = p->min;
				}
				if (new_value > p->max) { 
					new_value = p->max;
				} */
				if (new_value < 0) { 
					new_value = 0;
				}
				if (new_value > 255) { 
					new_value = 255;
				}
				eib_value[0] = new_value & 0xff;
				eib_G_DATA_request(get_group_address(eib_object), eib_value, 1);
			break;
			case EIB_BUTTON_FUNCTION_DELTA_EIS5:
				// add delta value to 16bit EIS5 object and send it
				eib_object = p->eib_object0;
				fval = eib_get_object_EIS5_value (eib_object);
				XRAM_SELECT_BLOCK(XRAM_CYCLIC_ELEMENTS_PAGE);
				fval += (float) ((int8_t) p->value[0])/10;
				// check, if the new value is inside of the bounds
/*				if (10*fval < p->min) { 
					fval = p->min;
					fval /= 10;
				}
				if (10*fval > p->max) { 
					fval = p->max;
					fval /= 10;
				} */
				if (fval < -100.0) { 
					fval = -100.0;
				}
				if (fval > 100.0) { 
					fval = 100.0;
				}
				// send new value as EIS5
				eib_set_object_EIS5_value(get_group_address(eib_object), fval);
			break;
		}
	}
}