int main(void) { SetupHardware(); // LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); GlobalInterruptEnable(); // uint8_t BUT_current = PIND & (1 << PD1);; // текущее значение кнопки // uint8_t BUT_previous = BUT_current; // предыдущее значение кнопки //uint8_t BUT_message=0; // 0 - ничего не отправлять, 1 - отправить vel 0, 2 - отправить vel 127 //uint8_t LED_current = 0; // текущее значение светодиода int ADC_current[16]; // текущие значения АЦП int ADC_previous[16]; // предыдущие значения АЦП uint8_t ADC_deviation = 20; // порог фиксации изменения АЦП, давить шум for (uint8_t i=0; i<16; i++) { ADC_current[i] = raw_ADC(); ADC_previous[i] = ADC_current[i];} // инициализация for (;;) { // дроп входящих MIDI_EventPacket_t ReceivedMIDIEvent; while (MIDI_Device_ReceiveEventPacket(&Keyboard_MIDI_Interface, &ReceivedMIDIEvent)); // опрос 16 входов мультиплексора for (int MUX_pos = 0; MUX_pos < 3; MUX_pos++ ){ MUX_address(MUX_pos); // установить адрес // _delay_ms(1); // MUX_enable(); // _delay_ms(1); ADC_current[MUX_pos] = raw_ADC(); // АЦП // MUX_disable(); if ( abs(ADC_current[MUX_pos] - ADC_previous[MUX_pos]) >= ADC_deviation ) // если изменения больше порога, отправить сообщение CC { cc_send(MUX_pos, ADC_current[MUX_pos] / 8); ADC_previous[MUX_pos] = ADC_current[MUX_pos]; } _delay_ms(10); MIDI_Device_USBTask(&Keyboard_MIDI_Interface); USB_USBTask(); } // MIDI_Device_USBTask(&Keyboard_MIDI_Interface); // USB_USBTask(); } }
static bool_t CC_CALL _send_header(cc_event_t *e, cckit_http_t *h) { cc_url_t *u = NULL; int32_t head_len = 0; tchar_t buff_head[10240] = {0}; #ifdef CC_UNICODE char_t send_head[10240] = {0}; #else char_t* send_head = NULL; #endif bool_t ret = TRUE; u = h->address; if(h->cb.cb_before_send) { head_len = cc_countof(buff_head); if (h->cb.cb_before_send(u, buff_head, &head_len, h->cb.args) == FALSE) { head_len = 0; } } if (head_len <= 0) { head_len = _sntprintf(buff_head, cc_countof(buff_head), default_http_template, u->path, u->host, _user_agent[rand()%cc_countof(_user_agent)]); } #ifdef CC_UNICODE head_len = cc_utf16_to_utf8((uint16_t*)buff_head, (uint16_t*)(buff_head + head_len), (uint8_t*)(send_head), (uint8_t*)(send_head + cc_countof(send_head)), FALSE); #else send_head = (char_t*)buff_head; #endif #ifdef CC_OPENSSL_HTTPS if (u->scheme == CC_SCHEME_HTTPS && h->ssl) { if (_sendSSL(h->ssl, (byte_t*)send_head, head_len) != head_len) { h->cb.cb_error(h->cb.args, CCKIT_HTTP_SOCKET_SEND_FAILED); ret = FALSE; } } else #endif if (cc_send(e->io_handle, (byte_t*)send_head, head_len) < 0) { h->cb.cb_error(h->cb.args, CCKIT_HTTP_SOCKET_SEND_FAILED); ret = FALSE; } return ret; }