/** * @ingroup main * */ static void events_init() { int i; const uint32_t mircos_now = hardware_micros(); for (i = 0; i < (sizeof(events) / sizeof(events[0])); i++) { events_elapsed_time[i] += mircos_now; } }
/** * @ingroup main * */ inline static void events_check() { int i; const uint32_t micros_now = hardware_micros(); for (i = 0; i < (sizeof(events) / sizeof(events[0])); i++) { if (micros_now - events_elapsed_time[i] > events[i].period) { events[i].f(); events_elapsed_time[i] += events[i].period; hardware_watchdog_feed(); } } }
/** * * Receive DMX on Change (label = 8 \ref RECEIVE_DMX_ON_CHANGE) * * This message requests the Widget send a DMX packet to the PC only when the DMX values change * on the input port. * * By default the widget will always send, if you want to send on change it must be enabled by sending * this message. * * This message also reinitializes the DMX receive processing, so that if change of state reception is * selected, the initial received DMX data is cleared to all zeros. * */ static void widget_receive_dmx_on_change(void) { monitor_line(MONITOR_LINE_INFO, "RECEIVE_DMX_ON_CHANGE"); monitor_line(MONITOR_LINE_STATUS, NULL); dmx_set_port_direction(DMX_PORT_DIRECTION_INP, false); receive_dmx_on_change = widget_data[0]; dmx_clear_data(); dmx_set_port_direction(DMX_PORT_DIRECTION_INP, true); widget_received_dmx_packet_start = hardware_micros(); }
/** * * This function is called from the poll table in \ref main.c * */ void widget_rdm_timeout(void) { if (widget_mode == MODE_RDM_SNIFFER) { return; } if (widget_send_rdm_packet_start == 0) { return; } if (hardware_micros() - widget_send_rdm_packet_start > 1000000) {// 1 second rdm_time_out_message(); // Send message to host Label=12 RDM_TIMEOUT widget_send_rdm_packet_start = 0; } }
/** * * Send RDM Discovery Request (Label=11 \ref SEND_RDM_DISCOVERY_REQUEST) * * This message requests the Widget to send an RDM Discovery Request packet out of the Widget * DMX port, and then receive an RDM Discovery Response. */ static void widget_send_rdm_discovery_request(uint16_t data_length) { monitor_line(MONITOR_LINE_INFO, "SEND_RDM_DISCOVERY_REQUEST"); monitor_line(MONITOR_LINE_STATUS, NULL); dmx_set_port_direction(DMX_PORT_DIRECTION_OUTP, false); rdm_send_data(widget_data, data_length); udelay(RDM_RESPONDER_DATA_DIRECTION_DELAY); dmx_set_port_direction(DMX_PORT_DIRECTION_INP, true); widget_rdm_discovery_running = true; widget_send_rdm_packet_start = hardware_micros(); monitor_rdm_data(MONITOR_LINE_RDM_DATA, data_length, widget_data, true); }
/** * * Get Widget Serial Number Reply (Label = 10 \ref GET_WIDGET_PARAMS_REPLY) * */ static void widget_get_sn_reply(void) { struct _rdm_device_info_data rdm_device_info_sn; monitor_line(MONITOR_LINE_INFO, "GET_WIDGET_PARAMS_REPLY"); monitor_line(MONITOR_LINE_STATUS, NULL); rdm_device_info_get_sn(&rdm_device_info_sn); dmx_set_port_direction(DMX_PORT_DIRECTION_INP, false); widget_usb_send_message(GET_WIDGET_SN_REPLY, rdm_device_info_sn.data, rdm_device_info_sn.length); dmx_set_port_direction(DMX_PORT_DIRECTION_INP, true); widget_received_dmx_packet_start = hardware_micros(); }
/** * * Set Widget Parameters Request (Label=4 \ref SET_WIDGET_PARAMS) * This message sets the Widget configuration. The Widget configuration is preserved when the Widget loses power. * */ static void widget_set_params() { struct _widget_params widget_params; monitor_line(MONITOR_LINE_INFO, "SET_WIDGET_PARAMS"); monitor_line(MONITOR_LINE_STATUS, NULL); dmx_set_port_direction(DMX_PORT_DIRECTION_INP, false); widget_params.break_time = widget_data[2]; widget_params.mab_time = widget_data[3]; widget_params.refresh_rate = widget_data[4]; widget_params_set(&widget_params); dmx_set_port_direction(DMX_PORT_DIRECTION_INP, true); widget_received_dmx_packet_start = hardware_micros(); }
/** * * https://wiki.openlighting.org/index.php/USB_Protocol_Extensions#Device_Name.2C_Label_.3D_78.2C_no_data * * Get Widget Name Reply (Label = 78 \ref GET_WIDGET_NAME_LABEL) */ static void widget_get_name_reply(void) { struct _rdm_device_info_data rdm_device_info_label; struct _widget_params_data widget_params_type_id; monitor_line(MONITOR_LINE_INFO, "GET_WIDGET_NAME_LABEL"); monitor_line(MONITOR_LINE_STATUS, NULL); rdm_device_info_get_label(0, &rdm_device_info_label); widget_params_get_type_id(&widget_params_type_id); dmx_set_port_direction(DMX_PORT_DIRECTION_INP, false); widget_usb_send_header(GET_WIDGET_NAME_LABEL, widget_params_type_id.length + rdm_device_info_label.length); widget_usb_send_data(widget_params_type_id.data, widget_params_type_id.length); widget_usb_send_data(rdm_device_info_label.data, rdm_device_info_label.length); widget_usb_send_footer(); dmx_set_port_direction(DMX_PORT_DIRECTION_INP, true); widget_received_dmx_packet_start = hardware_micros(); }
/** * * https://wiki.openlighting.org/index.php/USB_Protocol_Extensions#Device_Manufacturer.2C_Label_.3D_77.2C_no_data * * Get Widget Manufacturer Reply (Label = 77 \ref MANUFACTURER_LABEL) */ static void widget_get_manufacturer_reply(void) { struct _rdm_device_info_data rdm_device_info_manufacturer_name; struct _rdm_device_info_data rdm_device_info_manufacturer_id; monitor_line(MONITOR_LINE_INFO, "MANUFACTURER_LABEL"); monitor_line(MONITOR_LINE_STATUS, NULL); rdm_device_info_get_manufacturer_name(&rdm_device_info_manufacturer_name); rdm_device_info_get_manufacturer_id(&rdm_device_info_manufacturer_id); dmx_set_port_direction(DMX_PORT_DIRECTION_INP, false); widget_usb_send_header(MANUFACTURER_LABEL, rdm_device_info_manufacturer_id.length + rdm_device_info_manufacturer_name.length); widget_usb_send_data(rdm_device_info_manufacturer_id.data, rdm_device_info_manufacturer_id.length); widget_usb_send_data(rdm_device_info_manufacturer_name.data, rdm_device_info_manufacturer_name.length); widget_usb_send_footer(); dmx_set_port_direction(DMX_PORT_DIRECTION_INP, true); widget_received_dmx_packet_start = hardware_micros(); }
/** * * This function is called from the poll table in \ref main.c * * Received DMX Packet (Label=5 \ref RECEIVED_DMX_PACKET) * * The Widget sends this message to the PC unsolicited, whenever the Widget receives a DMX or RDM packet from the DMX port, * and the Receive DMX on Change mode (\ref receive_dmx_on_change) is 'Send always' (\ref SEND_ALWAYS). */ void widget_received_dmx_packet(void) { if (widget_mode == MODE_RDM_SNIFFER) { return; } if (widget_rdm_discovery_running || (DMX_PORT_DIRECTION_INP != dmx_get_port_direction()) || (SEND_ON_DATA_CHANGE_ONLY == receive_dmx_on_change)) { return; } const uint8_t *dmx_data = dmx_get_available(); if (dmx_data == NULL) { return; } const uint32_t micros_now = hardware_micros(); if (micros_now - widget_received_dmx_packet_start < widget_received_dmx_packet_period) { return; } widget_received_dmx_packet_start = micros_now; widget_received_dmx_packet_count++; const struct _dmx_data *dmx_statistics = (struct _dmx_data *)dmx_data; const uint16_t length = (uint16_t)(dmx_statistics->statistics.slots_in_packet + 1); monitor_line(MONITOR_LINE_LABEL, "poll:RECEIVED_DMX_PACKET"); monitor_line(MONITOR_LINE_INFO, "Send DMX data to HOST, %d", length); monitor_line(MONITOR_LINE_STATUS, NULL); widget_usb_send_header(RECEIVED_DMX_PACKET, length + 1); usb_send_byte(0); // DMX Receive status widget_usb_send_data(dmx_data, length); widget_usb_send_footer(); }