void tuner_set_forced_mono(gboolean value) { if(value) tuner_write(tuner.thread, "B1"); else tuner_write(tuner.thread, "B0"); }
void tuner_set_mode(gint mode) { gchar buffer[3]; g_snprintf(buffer, sizeof(buffer), "M%d", mode); tuner_write(tuner.thread, buffer); }
void tuner_set_sampling_interval(gint interval, gboolean mode) { gchar buffer[10]; g_snprintf(buffer, sizeof(buffer), "I%d,%d", interval, mode); tuner_write(tuner.thread, buffer); }
void connection_toggle() { if(tuner.thread) { connect_button(TRUE); if(!conf.disconnect_confirm || ui_dialog_confirm_disconnect()) { /* The tuner is connected, shutdown it */ tuner_write(tuner.thread, "X"); /* Lock the connection button until the thread ends */ gtk_widget_set_sensitive(ui.b_connect, FALSE); g_usleep(100000); tuner_thread_cancel(tuner.thread); } return; } /* Drop current rotator state */ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ui.b_cw), FALSE); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ui.b_ccw), FALSE); /* Display connection dialog */ connection_dialog(FALSE); }
void tuner_set_rotator(gpointer user_data) { gboolean cw = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ui.b_cw)); gboolean ccw = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ui.b_ccw)); gchar buffer[3]; gint state = GPOINTER_TO_INT(user_data); if(!cw && !ccw) { state = 0; } else if(state == 1) { if(ccw) { g_signal_handlers_block_by_func(G_OBJECT(ui.b_ccw), GINT_TO_POINTER(tuner_set_rotator), GINT_TO_POINTER(2)); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ui.b_ccw), FALSE); g_signal_handlers_unblock_by_func(G_OBJECT(ui.b_ccw), GINT_TO_POINTER(tuner_set_rotator), GINT_TO_POINTER(2)); } } else if(state == 2) { if(cw) { g_signal_handlers_block_by_func(G_OBJECT(ui.b_cw), GINT_TO_POINTER(tuner_set_rotator), GINT_TO_POINTER(1)); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ui.b_cw), FALSE); g_signal_handlers_unblock_by_func(G_OBJECT(ui.b_cw), GINT_TO_POINTER(tuner_set_rotator), GINT_TO_POINTER(1)); } } g_snprintf(buffer, sizeof(buffer), "C%d", state); tuner_write(tuner.thread, buffer); tuner.last_set_rotator = g_get_real_time() / 1000; }
void tuner_set_squelch() { gchar buffer[5]; g_snprintf(buffer, sizeof(buffer), "Q%ld", lround(gtk_scale_button_get_value(GTK_SCALE_BUTTON(ui.squelch)))); tuner_write(tuner.thread, buffer); tuner.last_set_squelch = g_get_real_time() / 1000; }
void tuner_set_alignment() { gchar buffer[5]; g_snprintf(buffer, sizeof(buffer), "V%ld", lround(gtk_adjustment_get_value(GTK_ADJUSTMENT(ui.adj_align)))); tuner_write(tuner.thread, buffer); tuner.last_set_daa = g_get_real_time() / 1000; }
void tuner_set_volume() { gchar buffer[5]; conf.volume = lround(gtk_scale_button_get_value(GTK_SCALE_BUTTON(ui.volume))); g_snprintf(buffer, sizeof(buffer), "Y%d", conf.volume); tuner_write(tuner.thread, buffer); tuner.last_set_volume = g_get_real_time() / 1000; }
void tuner_set_deemphasis() { gchar buffer[3]; conf.deemphasis = gtk_combo_box_get_active(GTK_COMBO_BOX(ui.c_deemph)); g_snprintf(buffer, sizeof(buffer), "D%d", conf.deemphasis); tuner_write(tuner.thread, buffer); tuner.last_set_deemph = g_get_real_time() / 1000; }
void tuner_set_bandwidth() { gchar buffer[4]; g_snprintf(buffer, sizeof(buffer), "F%d", tuner_filter_from_index(gtk_combo_box_get_active(GTK_COMBO_BOX(ui.c_bw)))); tuner_write(tuner.thread, buffer); tuner.last_set_filter = g_get_real_time() / 1000; }
void tuner_set_antenna() { gchar buffer[3]; gint antenna = gtk_combo_box_get_active(GTK_COMBO_BOX(ui.c_ant)); g_snprintf(buffer, sizeof(buffer), "Z%d", (antenna >=0 ? antenna : 0)); tuner_write(tuner.thread, buffer); tuner.last_set_ant = g_get_real_time() / 1000; }
void tuner_set_agc() { gchar buffer[3]; conf.agc = gtk_combo_box_get_active(GTK_COMBO_BOX(ui.c_agc)); g_snprintf(buffer, sizeof(buffer), "A%d", conf.agc); tuner_write(tuner.thread, buffer); tuner.last_set_agc = g_get_real_time() / 1000; }
void tuner_set_gain() { gchar buffer[4]; conf.rfgain = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ui.x_rf)); conf.ifgain = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ui.x_if)); g_snprintf(buffer, sizeof(buffer), "G%02d", conf.rfgain * 10 + conf.ifgain); tuner_write(tuner.thread, buffer); tuner.last_set_gain = g_get_real_time() / 1000; }
void tuner_set_frequency(gint freq) { static gint freq_waiting = -1; static gint64 last_request = 0; gint64 now = g_get_real_time(); gchar buffer[8]; gint real_freq = freq + conf.freq_offset; if((now-last_request) < 1000000 && real_freq == freq_waiting && real_freq != tuner.freq) return; ui_antenna_switch(freq); g_snprintf(buffer, sizeof(buffer), "T%d", real_freq); tuner_write(tuner.thread, buffer); freq_waiting = real_freq; last_request = now; }
void app_tuner_updown_tasks() { static uint8_t cmd_power_up[] = {0x01, 0x00, 0xB5}; static uint8_t cmd_power_down[] = {0x11}; static uint8_t cmd_tune[] = {0x20,0x01,0x24,0x9A,0x00}; //0x01 = inaccurate but fast tunning alowed to 93.7 static uint8_t cmd_int_update[] = {0x14}; static uint8_t cmd_int_clear[] = {0x22, 0x01}; static uint8_t cmd_dosr[] = {0x12, 0x00, 0x01, 0x04, 0xBB, 0x80}; //sample rate static uint8_t cmd_refclk_presc[]= {0x12, 0x00, 0x02, 0x02, 0x10, 0x2F}; //1538461,538461538 / 47 -> 32733,2Hz bit 12 = 1 (colck from dclk) 0x102f static uint8_t cmd_refclk_freq[]= {0x12, 0x00, 0x02, 0x01, 0x7F, 0xDD}; //32733 0x7fdd static uint8_t * cmd_list[] = { NULL, cmd_power_up, cmd_refclk_freq, cmd_refclk_presc, cmd_tune, cmd_int_update, cmd_int_clear, cmd_dosr, NULL }; static size_t cmd_sizes[] = { 0, sizeof(cmd_power_up), sizeof(cmd_refclk_freq) ,sizeof(cmd_refclk_presc), sizeof(cmd_tune), sizeof(cmd_int_update), sizeof(cmd_int_clear), sizeof(cmd_dosr), 0, }; static enum { ST_DOWN = 0, ST_PWRUP, ST_RCLK_FREQ, ST_RCLK_PRESC, ST_TUNE, ST_TUNE_INT_UPDATE, ST_TUNE_INT_CLR, ST_DOSR, ST_UP, } state[] = {ST_DOWN, ST_DOWN}; static enum { CST_DONE, CST_CHCK_REPLY, CST_READING } com_st[2] = {CST_DONE, CST_DONE}; static Tuner_read_reply reply[2]; static int tid = 1; //ID of currently porcessed tunner { Tuner_com_state tun_s = tuner_com_state(); static bool bus = false; if(tun_s == TUNER_COM_BUSY) { if(!bus) U1TXREG = 'B'; bus = true; } else { if(bus) U1TXREG = 'b'; bus = false; } if( tun_s == TUNER_COM_BUSY) return; tid = (tid+1)&1; Nop(); switch(com_st[tid]) { case CST_DONE: break; case CST_CHCK_REPLY: tuner_read(tid, &reply[tid], 1); com_st[tid] = CST_READING; return; case CST_READING: if(reply[tid].STATUS.bits.CTS) com_st[tid] = CST_DONE; else { com_st[tid] = CST_CHCK_REPLY; } return; } switch(state[tid]) { case ST_UP: if(appData.suspended) { tuner_hold_in_rst(1); tuner_audio_run(tid, 0); state[tid] = ST_DOWN; } break; case ST_DOWN: if(!appData.suspended) { tuner_audio_run(tid, 1); tuner_hold_in_rst(0); state[tid]++; } break; case ST_TUNE_INT_CLR: if(!reply[tid].STATUS.bits.STCINT) { state[tid] = ST_TUNE_INT_UPDATE; break; } //do not put break here or another state default: if(cmd_list[state[tid]]==NULL) debughalt(); tuner_write(tid, cmd_list[state[tid]], cmd_sizes[state[tid]]); com_st[tid] = CST_CHCK_REPLY; state[tid]++; break; } } }
void tuner_set_stereo_test() { tuner_write(tuner.thread, "N"); tuner.last_set_pilot = g_get_real_time() / 1000; }
void APP_Task_configured_state( void ) { //Tries to send sound frame if available { int i=0; static int last = 0; static int16_t* last_data = NULL; int cnt; for(;i<AUDIO_HANDLES;i++) { if(audio_handle[i] == HANDLE_INVALID) { int16_t* data = tuner_audio_get(0); if(data != last_data) { USB_DEVICE_EndpointWrite( appData.usbDevHandle, &audio_handle[i], AUDIO_EP, data, PACKET_SIZE, USB_DEVICE_TRANSFER_FLAGS_DATA_COMPLETE ); last_data = data; } } else cnt++; } if(cnt!=last) { U1TXREG = '0'+(char)cnt; last = cnt; } } //Allows receive a data for I2C tunel from host if(!appData.reading) { static USB_DEVICE_TRANSFER_HANDLE h; //we do not need handle volatile USB_DEVICE_RESULT r = USB_DEVICE_EndpointRead(appData.usbDevHandle, &h, TUNNEL_EP_OUT, appData.tunnel_read_data, sizeof(appData.tunnel_read_data)); if(r!=USB_DEVICE_RESULT_OK) Nop(); appData.reading = 1; U1TXREG = 'i'; } //Ping request was received if(appData.pingRequest) { volatile USB_DEVICE_RESULT r = USB_DEVICE_EndpointWrite( appData.usbDevHandle, &appData.tunnel_write_handle, TUNNEL_EP_IN, &appData.tunnel_read_data, appData.tunnel_read_count, USB_DEVICE_TRANSFER_FLAGS_DATA_COMPLETE); if(r!=USB_DEVICE_RESULT_OK) Nop(); U1TXREG = 'w'; appData.pingRequest = 0; appData.reading = 0; } //A request for tuner was received if(appData.tuner_request) { int tuner_id = (appData.tunnel_read_data[0]&TUNNEL_TUNER_SELECT_MASK) ? 1 : 0 ; uint8_t * data = appData.tunnel_read_data; appData.tunnel_write_data[0] = 0; //reset status byte if(appData.tunnel_read_data[0] & TUNNEL_RW_SELECT_MASK) { //R //Second byte of read request is count of bytes to read tuner_read(tuner_id, appData.tunnel_write_data+1, appData.tunnel_read_data[1]); } else { //W size_t count = appData.tunnel_read_count-1; if(count > sizeof(appData.tunnel_write_data)) count = sizeof(appData.tunnel_write_data); tuner_write(tuner_id, data+1, count); } appData.reading = 0; appData.tuner_request = 0; appData.tuner_wait_for_reply = 1; } //We started communication with tuner and now we have to periodicallz check it's state if(appData.tuner_wait_for_reply) { Tuner_com_state st = tuner_com_state(); if(st != TUNER_COM_BUSY) { //Com is done if(st==TUNER_COM_IDLE || st==TUNER_COM_DEV_BUSY) { size_t size_to_send = 1; if(appData.tunnel_read_data[0] & TUNNEL_RW_SELECT_MASK) size_to_send = tuner_rwed_bytes()+1; //was reading last USB_DEVICE_EndpointWrite( appData.usbDevHandle, &appData.tunnel_write_handle, TUNNEL_EP_IN, &appData.tunnel_write_data, size_to_send, USB_DEVICE_TRANSFER_FLAGS_DATA_COMPLETE); } else { //error appData.tunnel_write_data[0] = (uint8_t)st; USB_DEVICE_EndpointWrite( appData.usbDevHandle, &appData.tunnel_write_handle, TUNNEL_EP_IN, &appData.tunnel_write_data, 1, USB_DEVICE_TRANSFER_FLAGS_DATA_COMPLETE); } appData.tuner_wait_for_reply = 0; } } }