static void meshscope(Window *win) { Bool configured = FALSE; while (running) { while (XPending (meshscope_dpy)) { XEvent event; XNextEvent (meshscope_dpy, &event); switch (event.type) { case ConfigureNotify: glViewport (0, 0, event.xconfigure.width, event.xconfigure.height); configured = TRUE; break; case ButtonPress: mousepress(event); break; case ButtonRelease: mouserelease(event); break; case MotionNotify: mousemove(event); break; default: printf("event %x\n", event.type); break; } } drawMesh (); animate(); dosleep (25000); } }
static void the_fftscope(void) { guchar *loc; guchar bits [256 * 129]; int i, h; running = 1; while (running) { guint val; gint j; gint k; memset(bits, 0, 256 * 128); for (i=0; i < BARS; i++) { val = 0; for (j = xranges[i]; j < xranges[i + 1]; j++) { /* k = (guint)(sqrt(fftout[j]) * fftmult); */ k = (fft_buf[j] + fft_buf[256+j]) / 256; val += k; } if(val > 127) val = 127; if (val > (guint)maxbar[ i ]) maxbar[ i ] = val; else { k = maxbar[ i ] - (4 + (8 / (128 - maxbar[ i ]))); val = k > 0 ? k : 0; maxbar[ i ] = val; } loc = bits + 256 * 128; for (h = val; h > 0; h--) { for (j = (256 / BARS) * i + 0; j < (256 / BARS) * i + ((256 / BARS) - 1); j++) { *(loc + j) = val-h; } loc -=256; } } GDK_THREADS_ENTER(); gdk_draw_indexed_image(area->window, area->style->white_gc, 0,0,256,128, GDK_RGB_DITHER_NONE, bits, 256, color_map); gdk_flush(); GDK_THREADS_LEAVE(); dosleep(SCOPE_SLEEP); } GDK_THREADS_ENTER(); fftscope_hide(); GDK_THREADS_LEAVE(); }
static void wait_for_vsync(void) { #ifdef NVIDIA_SYNC static int init = 0; static int fd = -1; static struct pollfd pollfds; if (!init) { fd = open("/dev/nvidia0", O_RDONLY); if (fd == -1) { alsaplayer_error("Error opening NVIDIA device /dev/nvidia0"); } else { pollfds.fd = fd; pollfds.events = 0xffff; pollfds.revents = 0xffff; alsaplayer_error("Using NVIDIA poll method for vsync"); } init = 1; } poll (&pollfds, 1, -1); #else dosleep(10000); #endif }
/* The actual FFTscope renderer function. */ static void the_fftscope() { guint8 *loc; guint8 bits[256 * 129]; int i, h; running = 1; while (running) { int w; guint val; memset(bits, 128, 256 * SCOPE_HEIGHT); for (i = 0; i < 256; i++) { val = (act_fft[i] + act_fft[i + 256]) / (64 * (128 / SCOPE_HEIGHT)); if (val > (SCOPE_HEIGHT-1)) { val = (SCOPE_HEIGHT-1); } loc = bits + i + 256 * (SCOPE_HEIGHT-1); for (h = val; h > 0; h--) { *loc = h; loc -= 256; } } GDK_THREADS_ENTER(); gdk_draw_indexed_image(area->window, area->style->white_gc, 0, 0, 256, SCOPE_HEIGHT, GDK_RGB_DITHER_NONE, bits, 256, color_map); gdk_flush(); GDK_THREADS_LEAVE(); dosleep(SCOPE_SLEEP); } GDK_THREADS_ENTER(); fftscope_hide(); GDK_THREADS_LEAVE(); }
int main(int argc, char *argv[]) { int sockfd; //int numbytes; //char buf[MAXDATASIZE]; struct addrinfo hints, *servinfo, *p; int rv; char s[INET6_ADDRSTRLEN]; if (argc != 3) { fprintf(stderr,"usage: client hostname port\n"); exit(1); } memset(&hints, 0, sizeof hints); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; if ((rv = getaddrinfo(argv[1], argv[2], &hints, &servinfo)) != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv)); return 1; } // loop through all the results and connect to the first we can for(p = servinfo; p != NULL; p = p->ai_next) { if ((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) { perror("client: socket"); continue; } if (connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) { close(sockfd); perror("client: connect"); continue; } break; } if (p == NULL) { fprintf(stderr, "client: failed to connect\n"); return 2; } inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr), s, sizeof s); printf("client: connecting to %s\n", s); freeaddrinfo(servinfo); // all done with this structure printf("cmd load = %d\n",doload(sockfd)); printf("cmd uptime= %d\n", douptime(sockfd)); printf("cmd invalidrc = %d\n", doinvalid(sockfd)); printf("cmd sleeptimeoutrc = %d\n", dosleep(sockfd)); printf("cmd exitrc = %d\n ", doexit(sockfd) ); close(sockfd); return 0; }
void menu_handle_joystick(uint8_t key) { uint8_t menu_line[MLINESIZE+1]; //////////////////////////////////////// // Scrolling up/down. if(key == KEY_DOWN || key == KEY_UP) { menu_setbg(menu_curitem); lcd_putchar(menu_curitem-menu_topitem+1, ' '); uint8_t insert_line = 0; if(key == KEY_DOWN) { if(menu_curitem == menu_nitems-1) menu_curitem = 0; else menu_curitem++; if(menu_curitem - menu_topitem >= BODY_LINES) { menu_topitem++; insert_line = 9; } } if(key == KEY_UP) { if(menu_curitem == 0) menu_curitem = menu_nitems-1; else menu_curitem--; if(menu_topitem > menu_curitem) { menu_topitem--; insert_line = 10; } } menu_setbg(menu_curitem); if(insert_line) { uint8_t dpybuf[17]; menu_get_line(menu_item_offset[menu_curitem], menu_line, sizeof(menu_line)); menu_getlineword(1, menu_line, dpybuf+1, sizeof(dpybuf)-1); dpybuf[0] = ' '; lcd_putline(insert_line, (char *)dpybuf); } lcd_putchar(menu_curitem-menu_topitem+1, '>'); } //////////////////////////////////////// // Exec current command if(key == KEY_RIGHT) { // Save the current position menu_lastsel[menu_stack[menu_stackidx-1]] = menu_curitem; menu_get_line(menu_item_offset[menu_curitem], menu_line, sizeof(menu_line)); uint8_t arg[MLINESIZE]; menu_getlineword(2, menu_line, arg, sizeof(arg)); if(menu_line[0] == 'S') { // submenu uint8_t sm; fromhex((char *)arg, &sm, 1); menu_push(sm); } if(menu_line[0] == 'C') { // Command lcd_invon(); callfn((char *)arg); lcd_invoff(); } if(menu_line[0] == 'm') { // Macro uint8_t idx; uint16_t off; lcd_invon(); fromhex((char *)arg, &idx, 1); off = menu_get_line(menu_offset[idx], menu_line, sizeof(menu_line)); while(off && menu_line[0]) { off = menu_get_line(off, menu_line, sizeof(menu_line)); if(off == 0 || !menu_line[0]) break; callfn((char *)menu_line); } lcd_invoff(); } } if(key == KEY_LEFT) { // pop menu stack // Save the current position menu_lastsel[menu_stack[menu_stackidx-1]] = menu_curitem; menu_pop(); } //////////////////////////////////////// // Switch display on / off if(key == KEY_ENTER) { if(lcd_on) { if(lcd_on == 0xff) { lcd_switch(1); lcd_cls(); lcd_contrast(0xfc); menu_stackidx = 0; menu_push(0); } else { dosleep(); } } else { lcd_switch(1); } bat_drawstate(); } }
void Minute_Task(void) { static uint8_t last_tick; if((uint8_t)ticks == last_tick) return; last_tick = (uint8_t)ticks; wdt_reset(); // 125Hz #ifdef XLED if ((ticks % 12) == 0) { if ( xled_pattern & _BV(xled_pos++) ) { LED_ON(); } else { LED_OFF(); } } xled_pos &= 15; #endif #ifdef HAS_FHT_TF // iterate over all TFs for(uint8_t i = 0; i < FHT_TF_NUM; i++) { // if timed out -> call fht_tf_timer to send out data if(fht_tf_timeout_Array[3 * i] == 0) { fht_tf_timer(i); } } #endif #ifdef HAS_FHT_8v if(fht8v_timeout == 0) fht8v_timer(); #endif #ifdef HAS_FHT_80b if(fht80b_timeout == 0) fht80b_timer(); #endif #ifdef HAS_RF_ROUTER if(rf_router_sendtime && --rf_router_sendtime == 0) rf_router_flush(); #endif #ifdef HAS_ONEWIRE // Check if a running conversion is done // if HMS Emulation is on, and the Minute timer has expired onewire_HsecTask (); #endif if(clock_hsec<125) return; clock_hsec = 0; // once per second from here on. #ifndef XLED if(led_mode & 2) LED_TOGGLE(); #endif if (credit_10ms < MAX_CREDIT) // 10ms/1s == 1% -> allowed talk-time without CD credit_10ms += 1; #ifdef HAS_ONEWIRE // if HMS Emulation is on, check the HMS timer onewire_SecTask (); #endif #ifdef HAS_VZ vz_sectask(); #endif #if defined(HAS_SLEEP) && defined(JOY_PIN1) if(joy_inactive < 255) joy_inactive++; if(sleep_time && joy_inactive == sleep_time) { if(USB_IsConnected) lcd_switch(0); else dosleep(); } #endif #ifdef HAS_NTP if((ntp_sec & NTP_INTERVAL_MASK) == 0) ntp_sendpacket(); #endif static uint8_t clock_sec; clock_sec++; if(clock_sec != 60) // once per minute from here on return; clock_sec = 0; #ifdef HAS_FHT_80b fht80b_minute++; if(fht80b_minute >= 60) fht80b_minute = 0; #endif #if defined(HAS_LCD) && defined(BAT_PIN) bat_drawstate(); #endif }
void playlist_looper(void *data) { #ifdef DEBUG printf("THREAD-%d=playlist thread\n", getpid()); #endif /* DEBUG */ Playlist *pl = (Playlist *)data; CorePlayer *coreplayer; if(!pl) return; while(pl->active) { if (!pl->IsPaused()) { if (!(coreplayer = (CorePlayer *)(pl->coreplayer))) return; if (!coreplayer->IsActive()) { if (pl->Length()) { if (pl->LoopingSong()) { pl->Play(pl->GetCurrent()); } else { pl->Next(); if(pl->IsOneByOne()) { pl->Stop(); } } // TODO? set a flag to skip the dosleep() } } if (pl->Crossfading() && pl->Length() && pl->coreplayer->GetSpeed() >= 0.0) { // Cross example // Calc the block to sec value int nr_blocks = coreplayer->GetBlocks(); int totaltime = coreplayer->GetCurrentTime(nr_blocks); float blocktime = (float)totaltime / (float)nr_blocks; float xstart = 300; // 3.0 seconds float xblock = xstart / blocktime; //alsaplayer_error("xblock = %.2f", xblock); if ((coreplayer->GetBlocks() - coreplayer->GetPosition()) < (int)xblock) { if (pl->player1->IsActive() && pl->player2->IsActive()) { alsaplayer_error("Stopping players in playlist_looper"); pl->player1->Stop(); pl->player2->Stop(); } if (pl->player1->IsActive()) { pl->player2->SetSpeed(pl->coreplayer->GetSpeed()); pl->coreplayer = pl->player2; } else { pl->player1->SetSpeed(pl->coreplayer->GetSpeed()); pl->coreplayer = pl->player1; } pl->Next(); // TODO? set a flag to skip the dosleep() } } } // Update the position: notifier information pl->coreplayer->PositionUpdate(); dosleep(200000); } }