Exemplo n.º 1
0
// Gekuerzte Main-Funktion
int main(void) {
	while (1) { 	// In Endlosschleife wechseln
		wdt_reset();	// Watchdog zuruecksetzen
		if (get_key_press(1 << KEY1))	// 1 - Zurueck
			menu_exit(&menu_context);
		if( get_key_press(1 << KEY2))	// 2 - Hoch
			menu_prev_entry(&menu_context);
		if (get_key_press(1 << KEY3))	// 3 - Runter
			menu_next_entry(&menu_context);
		if (get_key_press(1 << KEY4))	// 4 - Ok
			menu_select(&menu_context);
	}
}
Exemplo n.º 2
0
enum user_commands get_command(void)
{
  long key0 = get_key_press( 1<<KEY0 );
	long key1 = get_key_rpt( 1<<KEY1 ) || get_key_press( 1<<KEY1 );
  int ir_cmd = ir_get_cmd();
	
	if ((key0 && state == PLAYING) || ir_cmd == 0x36) {
    return CMD_STOP;
	} else if (key0 || ir_cmd == 0x35) {
    return CMD_START;
	} else if (key1 || ir_cmd == 0x34) {
    return CMD_NEXT;
	}
	
  return -1;
}
Exemplo n.º 3
0
uint8_t menu_edit_month(uint8_t m) {
  for (;;) {
    lcd_locate(3, 0);
    menu_print_month(m);
    lcd_locate(3, 0);
    set_busy_led(true);
    lcd_cursor(true);
    for (;;) {
      if (get_key_autorepeat(KEY_PREV)) {
        if (m == 0) m = 11;
        else --m;
        break;
      }
      if (get_key_autorepeat(KEY_NEXT)) {
        if (m == 11) m = 0;
        else ++m;
        break;
      }
      if (get_key_press(KEY_SEL)) {
        set_busy_led(false);
        lcd_cursor(false);
        return m;
      }
    }
  }
}
Exemplo n.º 4
0
uint8_t menu_edit_value(uint8_t v, uint8_t min, uint8_t max) {
  uint8_t x = lcd_x;
  uint8_t y = lcd_y;

  lcd_locate(x, y);
  lcd_cursor(true);
  set_busy_led(true);
  for (;;) {
    lcd_printf("%02d", v);
    lcd_locate(x, y);
    for (;;) {
      if (get_key_autorepeat(KEY_PREV)) {
        if (v <= min) v = max;
        else --v;
        break;
      }
      if (get_key_autorepeat(KEY_NEXT)) {
        if (v >= max) v = min;
        else ++v;
        break;
      }
      if (get_key_press(KEY_SEL)) {
        lcd_cursor(false);
        set_busy_led(false);
        return v;
      }
    }
  }
}
Exemplo n.º 5
0
Arquivo: main.c Projeto: bhase/garage
int main(void)
{
	uint8_t retval;
	while (1) {
		init();
		for (retval = 0; retval < 50; retval++) {
			/* wait x ms until inputs are debounced */
			wait_for_timer_tick();
		}
		if (direction == ASK) {
			if (position() == OPEN) direction = DOWN;
			else direction = UP;
		}
		if (!get_key_press(START_BT)) {
			goto unintended_wakeup;
		}
		led1(GREEN);
		start_moving(direction);
		retval = 1;
		while (run_enable && retval) {
			wait_for_timer_tick();
			retval = pwm_ramp_up();
			if (get_key_press(START_BT)) {
				disable();
			}
		}
		while (run_enable) {
			wait_for_timer_tick();
			if (get_key_press(START_BT)) {
				disable();
			}
		}
		retval = 1;
		while (retval) {
			wait_for_timer_tick();
			retval = pwm_ramp_down();
		}
		stop_moving();
unintended_wakeup:
		led1(OFF);
		deinit();
		sleep();
	}
	/* never reached */
	return 0;
}
Exemplo n.º 6
0
int main(void)
{
 
  initIO();		//Setup LED and Button pins
  timer0_overflow();	//Setup the button debounce timer
  initTimer1_modes();	//Setup the delay timer

  state = sweep;	//Set default state
  initState(state);	//Setup initial state

  while(1) 
  {
    //If interrupt set the timer flag act on that
    if (timer) {
      switch (state)
      {
        case sweep:
          if (direction) tracker <<= 1;
          else tracker >>= 1;

          if ((tracker == 0x01) | (tracker == 0x80)) direction ^= 1;

          ledPort = tracker;
          break;

        case xor:
          toggle_led();
          break;

        case flash:
          toggle_led();
          break;

        case sleep:
          //Arriving here means we just woke up from sleep
          state = sweep; //Reset state machine
          initState(state);
          break;
      }
      timer = 0;
    }

    if( get_key_press( 1<<KEY0 )) {
      timer1_stop();	//Halt the delay timer
      timer = 0;	//Clear delay timer flag
      
      //Increment the state machine
      if (++state > sleep) state = sweep;

      initState(state);
    }
  }
}
Exemplo n.º 7
0
void play_back()
{
  int x,y;
  unsigned int h,w,bw,d;

  Window root;
  XEvent ev;
  int i=0;
  XGetGeometry(display,draw_win,&root,&x,&y,&w,&h,&bw,&d);
  if(mov_ind==0)return;
  if(h<movie[i].h||w<movie[i].w){
    too_small();
    return;
  }
  
  XCopyArea(display,movie[i].xi,draw_win,gc_graph,0,0,w,h,0,0);
  XFlush(display);
  while(1){
    XNextEvent(display,&ev);
    switch(ev.type)
      {
      case ButtonPress:
	i++;
	if(i>=mov_ind)i=0;
	if(show_frame(i,h,w))return;
	break;
      case KeyPress:
	switch(get_key_press(&ev)){
	  case ESC:
	    return;
	  case RIGHT:
	    i++;
	    if(i>=mov_ind)i=0;
	    if(show_frame(i,h,w))return;
	    break;
	  case  LEFT:
	    i--;
	    if(i<0)i=mov_ind-1;
	    if(show_frame(i,h,w))return;
	    break;
	  case  HOME:
	    i=0;
	    if(show_frame(i,h,w))return;
	    break;
	  case END:
	    i=mov_ind-1;
	    if(show_frame(i,h,w))return;
	    break;
	  }
	  
      }
  }
}
Exemplo n.º 8
0
void
putc(uint8_t c)
{
	int key_press = get_key_press();
	int32_t curr_terminal;

	/* If putc is called by system call */
	if(key_press == 0){
		asm volatile ("cli"); // Protect with cli
		curr_terminal = get_current_terminal();	
	}
	/* If putc is called by keyboard interrupt */
	else{
Exemplo n.º 9
0
Arquivo: main.c Projeto: bhase/garage
void sleep(void)
{
	set_sleep_mode(SLEEP_MODE_PWR_DOWN);
	cli();
	/* check conditions */
	if (!get_key_press(START_BT)) {
		sleep_enable();
		sei();
		sleep_cpu();
		sleep_disable();
	}
	sei();
}
Exemplo n.º 10
0
bool handle_buttons(void) {
  if (!menu_system_enabled) return false;
  uint8_t buttons = get_key_press(KEY_ANY);
  if (!buttons) return false;
  if (buttons & KEY_PREV) {
    // If there's an error, PREV clears the disk status
    // If not, enter menu system just as any other key
    if (current_error != ERROR_OK) {
      set_error(ERROR_OK);
      return false;
    }
  }
  return menu();
}
Exemplo n.º 11
0
//*****************************************************************************
// 
uint8_t get_key_short (uint8_t key_mask)
{
	uint8_t ret;
	uint8_t sreg = SREG;
	
	// disable all interrupts
	cli();
	
  ret = get_key_press (~key_state & key_mask);
	
	SREG = sreg;	// restore status register
	
  return ret;
}
Exemplo n.º 12
0
Arquivo: menu.c Projeto: tommie/xppaut
void x11_menu_event(X11Menu *m, const XEvent *ev) {
  int key;

  switch (ev->type) {
  case Expose:
  case MapNotify:
    x11_menu_draw(m);
    break;

  case KeyPress:
    key = get_key_press(ev);
    if (key == '\r')
      key = m->descr.def_key;
    if (key)
      m->select_func(m->cookie, key);
    break;

  case ButtonRelease:
    for (int i = 0; i < m->entry_wins.len; i++) {
      if (ev->xbutton.window == m->entry_wins.elems[i]) {
        m->select_func(m->cookie, m->descr.entries[i].key);
        break;
      }
    }

    break;

  case EnterNotify:
    for (int i = 0; i < m->entry_wins.len; i++) {
      if (ev->xcrossing.window == m->entry_wins.elems[i]) {
        XSetWindowBorderWidth(display, m->entry_wins.elems[i], 1);
        if (TipsFlag)
          x11_status_bar_set_text(m->sb, m->descr.entries[i].hint);
        break;
      }
    }
    break;

  case LeaveNotify:
    for (int i = 0; i < m->entry_wins.len; i++) {
      if (ev->xcrossing.window == m->entry_wins.elems[i]) {
        XSetWindowBorderWidth(display, m->entry_wins.elems[i], 0);
        break;
      }
    }
    break;
  }
}
Exemplo n.º 13
0
bool Input::get_qualifier_press(KeyboardQualifier qualifier) const
{
    bool result = true;
    if( value(qualifier & KeyboardQualifier::SHIFT) )
        result &= (get_key_press(KeyboardCode::LSHIFT) || get_key_press(KeyboardCode::RSHIFT));
    if( value(qualifier & KeyboardQualifier::CTRL) )
        result &= (get_key_press(KeyboardCode::LCTRL) || get_key_press(KeyboardCode::RCTRL));
    if( value(qualifier & KeyboardQualifier::ALT) )
        result &= (get_key_press(KeyboardCode::LALT) || get_key_press(KeyboardCode::RALT));
    return result;
}
Exemplo n.º 14
0
void menu_adjust_brightness(void) {
  uint8_t i;
  uint8_t min = 0;
  uint8_t max = 255;
  uint8_t res;
  uint8_t step;

  lcd_clear();
  lcd_puts_P(PSTR("Adjust brightness"));
  lcd_locate(0, 1);

  lcd_cursor(false);
  set_busy_led(true);
  for (;;) {
    lcd_locate(0, 1);
    lcd_putc('[');
    for (i = 0; i < 18; i++) {
      lcd_putc(i >= (lcd_brightness / 14) ? ' ' : 0xFF);
    }
    lcd_putc(']');
    res = lcd_set_brightness(lcd_brightness);
    if (res) break;
    for (;;) {
      step = 10;
      if (lcd_brightness < 20 || lcd_brightness > 235) step = 1;
      if (get_key_autorepeat(KEY_PREV)) {
        if (lcd_brightness <= min) lcd_brightness = max;
        else lcd_brightness -= step;
        break;
      }
      if (get_key_autorepeat(KEY_NEXT)) {
        if (lcd_brightness >= max) lcd_brightness = min;
        else lcd_brightness += step;
        break;
      }
      if (get_key_press(KEY_SEL)) {
        lcd_cursor(false);
        set_busy_led(false);
        menu_ask_store_settings();
        return;
      }
    }
  }
  pwm_error();
}
Exemplo n.º 15
0
int8_t menu_vertical(uint8_t min, uint8_t max) {
  uint8_t pos = min;

  lcd_cursor(true);
  for (;;) {
    lcd_locate(0, pos);
    if (get_key_autorepeat(KEY_PREV)) {
      if (pos > min) --pos;
      else pos = max;
    }
    if (get_key_autorepeat(KEY_NEXT)) {
      if (pos < max) ++pos;
      else pos = min;
    }
    if (get_key_press(KEY_SEL)) break;
  }
  lcd_cursor(false);
  return pos;
}
Exemplo n.º 16
0
void menu_adjust_contrast(void) {
  uint8_t i;
  uint8_t min = 0;
  uint8_t max = LCD_COLS - 2;
  uint8_t res;

  lcd_clear();
  lcd_puts_P(PSTR("Adjust LCD contrast"));
  lcd_locate(0, 1);

  lcd_cursor(false);
  set_busy_led(true);
  for (;;) {
    lcd_locate(0, 1);
    lcd_putc('[');
    for (i = 0; i < LCD_COLS - 2; i++) {
      lcd_putc(i >= lcd_contrast ? ' ' : 0xFF);
    }
    lcd_putc(']');
    res = lcd_set_contrast(lcd_contrast);
    if (res) break;
    for (;;) {
      if (get_key_autorepeat(KEY_PREV)) {
        if (lcd_contrast <= min) lcd_contrast = max;
        else --lcd_contrast;
        break;
      }
      if (get_key_autorepeat(KEY_NEXT)) {
        if (lcd_contrast >= max) lcd_contrast = min;
        else ++lcd_contrast;
        break;
      }
      if (get_key_press(KEY_SEL)) {
        lcd_cursor(false);
        set_busy_led(false);
        menu_ask_store_settings();
        return;
      }
    }
  }
  pwm_error();
}
Exemplo n.º 17
0
/*
 * get increment/decrement keys.
 * This may be extended for rotary encoders in future version.
 */
int8_t get_key_increment(void)
{
	#ifdef ENCODER
	#warning encoder gets key increment
	int8_t keys = encoderRead();
	// limit
	if (keys > 0)
		return 1;
	if (keys < 0)
		return -1;
	#else
	uint8_t keys = get_key_press((1 << KEY_MINUS) | (1 << KEY_PLUS));
	if(keys & (1 << KEY_PLUS))
		return 1;
	if(keys & (1 << KEY_MINUS))
		return -1;
	#endif
	
	return 0;
}
Exemplo n.º 18
0
play_back()
{
int x,y;
 unsigned int h,w,bw,d;
 char ch;
 Window root;
 XEvent ev;
 int i=0;
 XGetGeometry(display,draw_win,&root,&x,&y,&w,&h,&bw,&d);
 if(mov_ind==0)return;
 if(h<movie[i].h||w<movie[i].w){
	too_small();
	return;
	}

 XCopyArea(display,movie[i].xi,draw_win,gc_graph,0,0,w,h,0,0);
 XFlush(display);
 while(1){
          XNextEvent(display,&ev);
          switch(ev.type){
			  case ButtonPress:
				 i++;
			         if(i>=mov_ind)i=0;
				  if(h<movie[i].h||w<movie[i].w){
					too_small();
						return;
					}
			  XCopyArea(display,movie[i].xi,draw_win,gc_graph,0,0,w,h,0,0);
			  XFlush(display);
			 break;
			case KeyPress:
			      if(get_key_press(&ev)==27)return;
			   
		         break;
                        }

		}
  }	         
Exemplo n.º 19
0
//*****************************************************************************
// 
uint8_t get_key_long2 (uint8_t key_mask)
{
  return get_key_press (get_key_rpt (key_press^key_mask));
}
Exemplo n.º 20
0
static uint8_t Menu_canRun(void *_self, uint32_t now) {
	Menu_keyPress = get_key_press(1<<KEY0);
	Menu_rotEnc = encode_read();
	return Menu_keyPress || Menu_rotEnc || Menu_updateRequest;
}
Exemplo n.º 21
0
/*--------------------------------------------------------------------------
  FUNC: 8/1/11 - Used to read debounced button held for REPEAT_START amount
	of time.
  PARAMS: A keymask corresponding to the pin for the button you with to poll
  RETURNS: A keymask where any high bits represent a long button press
--------------------------------------------------------------------------*/
unsigned char get_key_long( unsigned char key_mask ) 
{ 
  return get_key_press( get_key_rpt( key_mask )); 
}
Exemplo n.º 22
0
/*--------------------------------------------------------------------------
  FUNC: 8/1/11 - Used to read debounced button released after a short press
  PARAMS: A keymask corresponding to the pin for the button you with to poll
  RETURNS: A keymask where any high bits represent a quick press and release
--------------------------------------------------------------------------*/
unsigned char get_key_short( unsigned char key_mask ) 
{ 
  __disable_irq ();         // read key state and key press atomic ! 
  return get_key_press( ~key_state & key_mask ); 
} 
Exemplo n.º 23
0
uint8_t get_key_short( uint8_t key_mask ) {
  cli();                                          // read key state and key press atomic !
  return get_key_press( ~key_state & key_mask );
}
Exemplo n.º 24
0
int main(void)
{
	RCC_ClocksTypeDef RCC_Clocks;
	RCC_GetClocksFreq(&RCC_Clocks);
	/* SysTick event each 1ms */
	SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);

	DELAY_Init();
	USB_Init(0);
	
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
	
	GPIO_InitTypeDef GPIO_InitStructure;
	GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_OUT;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_13;       
	GPIO_Init(GPIOB, &GPIO_InitStructure);  
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_12;       
	GPIO_Init(GPIOB, &GPIO_InitStructure);  
	
	//buttons
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
	GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_IN;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_4;       
	GPIO_Init(GPIOC, &GPIO_InitStructure);  
	
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_6;       
	GPIO_Init(GPIOC, &GPIO_InitStructure);  
	buttonsInitialized=1;
	
	int loopcount = 0;
	while(1)
	{
		midi_package_t rpack;

		int recv = USB_MIDI_PackageReceive(&rpack);

		if(recv != -1)
		{
			if(rpack.velocity > 50)
			{
				GPIOB->ODR           |=       1<<13;
			}
			else
			{
				GPIOB->ODR           &=       ~(1<<13);
			}
		}

		loopcount++;
		if((loopcount == 50)||(loopcount == 150))
		{
			if(USB_MIDI_CheckAvailable(0))
			{
				GPIOB->ODR           &=       ~(1<<12);
			}
		}
		if((loopcount == 100)||(loopcount == 200))
		{
			if(USB_MIDI_CheckAvailable(0))
			{
				GPIOB->ODR           |=       1<<12;
			}

			if(loopcount==200)
				loopcount = 0;
  		
		}
		
		if(get_key_press(KEY_A))
		{
		
			midi_package_t package;

			package.type     = CC;
			package.event    = CC;
			package.note     = 7;
			package.velocity = 100;

	
			USB_MIDI_PackageSend_NonBlocking(package);
		}

		if(get_key_press(KEY_B))
		{
		
			midi_package_t package;

			package.type     = CC;
			package.event    = CC;
			package.note     = 7;
			package.velocity = 50;

	
			USB_MIDI_PackageSend_NonBlocking(package);
		}
			
		DELAY_Wait_uS(1000);
	}


}
Exemplo n.º 25
0
int two_choice(char *choice1, char *choice2, char *string, char *key, int x,
               int y, Window w, char *title) {
  Window base, c1, c2, wm;
  XEvent ev;
  int not_done = 1;
  int value = 0;
  int l1 = strlen(choice1) * DCURX;
  int l2 = strlen(choice2) * DCURX;
  int lm = strlen(string) * DCURX;
  int tot = lm, xm, x1, x2;

  if (lm < (l1 + l2 + 4 * DCURX))
    tot = (l1 + l2 + 4 * DCURX);
  tot = tot + 6 * DCURX;
  xm = (tot - lm) / 2;
  x1 = (tot - l1 - l2 - 4 * DCURX) / 2;
  x2 = x1 + l1 + 4 * DCURX;
  base = make_plain_window(w, x, y, tot, 5 * DCURY, 4);

  make_icon((char *)alert_bits, alert_width, alert_height, base);

  c1 = make_window(base, x1, 3 * DCURY, l1 + DCURX, DCURY + 4, 1);
  c2 = make_window(base, x2, 3 * DCURY, l2 + DCURX, DCURY + 4, 1);
  XSelectInput(display, c1, BUT_MASK);
  XSelectInput(display, c2, BUT_MASK);

  wm = make_window(base, xm, DCURY / 2, lm + 2, DCURY, 0);

  ping();
  if (w == RootWindow(display, screen)) {
    if (title == NULL) {
      set_window_title(base, "!!!!");
    } else {
      set_window_title(base, title);
    }
  }

  while (not_done) {
    XNextEvent(display, &ev);
    switch (ev.type) {
    case Expose:
    case MapNotify:
      do_expose(ev);
      expose_choice(choice1, choice2, string, c1, c2, wm, ev.xexpose.window);
      break;

    case ButtonPress:
      if (ev.xbutton.window == c1) {
        value = (int)key[0];
        not_done = 0;
      }
      if (ev.xbutton.window == c2) {
        value = (int)key[1];
        not_done = 0;
      }
      break;
    case KeyPress:
      value = get_key_press(&ev);
      not_done = 0;
      break;
    case EnterNotify:
      if (ev.xcrossing.window == c1 || ev.xcrossing.window == c2)
        XSetWindowBorderWidth(display, ev.xcrossing.window, 2);
      XFlush(display);
      break;
    case LeaveNotify:
      if (ev.xcrossing.window == c1 || ev.xcrossing.window == c2)
        XSetWindowBorderWidth(display, ev.xcrossing.window, 1);
      XFlush(display);
      break;
    }
  }
  waitasec(2 * ClickTime);
  XFlush(display);
  XSelectInput(display, c1, EV_MASK);
  XSelectInput(display, c2, EV_MASK);
  XFlush(display);
  XDestroySubwindows(display, base);
  XDestroyWindow(display, base);
  return (value);
}
Exemplo n.º 26
0
static int s_box_event_loop(STRING_BOX *sb, int *pos, int *col,
                            SCROLLBOX *scrb) {
  XEvent ev;
  int status = -1, inew;
  int nn = sb->n;
  int done = 0, i, j;
  int item;
  char ch;
  int ihot = sb->hot;
  Window wt;
  Window w = sb->win[ihot]; /* active window   */
  char *s;
  s = sb->value[ihot];

  XNextEvent(display, &ev);
  switch (ev.type) {
  case ConfigureNotify:
  case Expose:
  case MapNotify:
    do_expose(ev); /*  menus and graphs etc  */
    expose_sbox(*sb, ev.xany.window, *pos, *col);
    if (scrb->exist)
      expose_scroll_box(ev.xany.window, *scrb);
    break;
  case MotionNotify:
    if (scrb->exist)
      scroll_box_motion(ev, scrb);
    break;
  case ButtonPress:
    if (scrb->exist) {
      item = select_scroll_item(ev.xbutton.window, *scrb);
      if (item >= 0) {
        set_sbox_item(sb, item);
        new_editable(sb, sb->hot, pos, col, &done, &w);
        destroy_scroll_box(scrb);
      }
    }
    if (ev.xbutton.window == sb->ok) {
      destroy_scroll_box(scrb);
      status = DONE_ALL;
      break;
    }
    if (ev.xbutton.window == sb->cancel) {
      status = FORGET_ALL;
      break;
      destroy_scroll_box(scrb);
    }
    for (i = 0; i < nn; i++) {
      if (ev.xbutton.window == sb->win[i]) {
        XSetInputFocus(display, sb->win[i], RevertToParent, CurrentTime);
        if (i != sb->hot) {
          destroy_scroll_box(scrb);
          new_editable(sb, i, pos, col, &done, &w);
        } else { /* i==sb->hot */
          if (ev.xbutton.x < DCURX) {
            j = sb->hot;
            if (sb->hh[j] >= 0) {
              scroll_popup(sb, scrb);
            }
          }
        }

        break;
      }
    }
    break;

  case EnterNotify:
    wt = ev.xcrossing.window;
    if (scrb->exist)
      crossing_scroll_box(wt, 1, *scrb);
    if (wt == sb->ok || wt == sb->cancel)
      XSetWindowBorderWidth(display, wt, 2);
    break;

  case LeaveNotify:
    wt = ev.xcrossing.window;
    if (scrb->exist)
      crossing_scroll_box(wt, 0, *scrb);
    if (wt == sb->ok || wt == sb->cancel)
      XSetWindowBorderWidth(display, wt, 1);
    break;

  case KeyPress:
    ch = get_key_press(&ev);
    edit_window(w, pos, s, col, &done, ch);
    if (done != 0) {
      if (done == DONE_ALL) {
        status = DONE_ALL;
        break;
      }
      inew = (sb->hot + 1) % nn;
      new_editable(sb, inew, pos, col, &done, &w);
    }
    break;
  }
  return (status);
}
Exemplo n.º 27
0
void menu_browse_files(void) {
  buffer_t *buf;
  buffer_t *buf_tbl;
  buffer_t *buf_cur;
  buffer_t *first_buf;
  path_t path;
  cbmdirent_t dent;
  uint16_t entries;
  uint8_t entry_num;
  bool fat_filesystem;
  uint8_t i;
  uint8_t my;
  uint16_t mp;
  bool action;
  uint16_t stack_mp[MAX_LASTPOS];
  uint8_t stack_my[MAX_LASTPOS];
  uint8_t pos_stack;
  uint8_t save_active_buffers;

  pos_stack = 0;
  memset(stack_mp, 0, sizeof(stack_mp));
  memset(stack_my, 0, sizeof(stack_my));
  save_active_buffers = active_buffers;

start:
  lcd_clear();
  lcd_puts_P(PSTR("Reading..."));

  buf = buf_tbl = buf_cur = first_buf = NULL;
  entries = entry_num = mp = 0;
  fat_filesystem = false;

  // Allocate one buffer, used to read a single directory entry
  if ((buf = alloc_system_buffer()) == NULL) return;

  // Allocate buffers with continuous data segments
  // Stores pointers to directory entries for qsort
  if ((buf_tbl = alloc_linked_buffers(CONFIG_DIR_BUFFERS)) == NULL) return;

  // Buffers to store the actual diretory entries.
  // Whilst the directory grows, new buffers get allocated and linked
  if ((buf_cur = alloc_system_buffer()) == NULL) return;
  first_buf = buf_cur;

  // Allocating buffers affects the LEDs
  set_busy_led(false); set_dirty_led(true);

  path.part = current_part;
  path.dir  = partition[path.part].current_dir;
  uart_trace(&path.dir, 0, sizeof(dir_t));
  uart_putcrlf();
  uart_flush();
  if (opendir(&buf->pvt.dir.dh, &path)) return;

  for (;;) {
    if (next_match(&buf->pvt.dir.dh,
                    buf->pvt.dir.matchstr,
                    buf->pvt.dir.match_start,
                    buf->pvt.dir.match_end,
                    buf->pvt.dir.filetype,
                    &dent) == 0)
    {
      uint8_t e_flags = 0;
      if (dent.opstype == OPSTYPE_FAT) {
        fat_filesystem = true;
        if (check_imageext(dent.pvt.fat.realname) != IMG_UNKNOWN)
          e_flags |= E_IMAGE;
      }
      // Current block full?
      if (entry_num == ENTRIES_PER_BLOCK) {
        entry_num = 0;
        buffer_t *old_buf = buf_cur;
        if ((buf_cur = alloc_system_buffer()) == NULL) {
          printf("alloc buf_cur failed, %d entries", entries);
          goto cleanup;
        }
        set_busy_led(false); set_dirty_led(true);
        buf_cur->pvt.buffer.next = NULL;
        old_buf->pvt.buffer.next = buf_cur;
      }

      // Store entry
      ep[entries] = (entry_t *) (buf_cur->data + entry_num * sizeof(entry_t));
      ustrncpy(ep[entries]->filename, dent.name, 16);
      ep[entries]->filesize = dent.blocksize;
      if ((dent.typeflags & EXT_TYPE_MASK) == TYPE_DIR)
        e_flags |= E_DIR;
      ep[entries]->flags = e_flags;
      entries++;
      entry_num++;
    } else {
      // No more directory entries to read
      break;
    }
  }
  printf("%d entries\r\n", entries);

  if (fat_filesystem)
    qsort(ep, entries, sizeof(entry_t*), compare);

  for (uint16_t i = 0; i < entries; i++) {
    printf("%3u: ", i);
    if (ep[i]->flags & E_DIR)
      uart_puts_P(PSTR(" DIR "));
    else if (ep[i]->flags & E_IMAGE)
      uart_puts_P(PSTR(" IMG "));
    else
      printf("%4u ", ep[i]->filesize);
    uint8_t filename[16 + 1];
    ustrncpy(filename, ep[i]->filename, 16);
    filename[16] = '\0';
    pet2asc(filename);
    printf("%s\r\n", filename);
    uart_flush();
  }
  uart_putcrlf();

#define DIRNAV_OFFSET   2
#define NAV_ABORT       0
#define NAV_PARENT      1

  mp = stack_mp[pos_stack];
  my = stack_my[pos_stack];
  printf("mp set to %d\r\n", mp);
  if (mp < (LCD_LINES - 1))
    my = mp;
  else
    my = 0;
  action = false;

  for (i=0; i < MAX_LASTPOS; i++) {
    if (pos_stack == i) uart_putc('>');
    printf("%d ", stack_mp[i]);
  }
  uart_putcrlf();

  for (;;) {
    lcd_clear();
    for (i = 0; i < LCD_LINES; i++) {
      lcd_locate(0, i);
      int8_t y = mp - my + i;
      if (y < 0) return; // should not happen!
      if (y < DIRNAV_OFFSET) {
        rom_menu_browse(y);
      } else {
        y -= DIRNAV_OFFSET;
        if (y >= entries) {
          lcd_puts_P(PSTR("-- End of dir --"));
          break;
        } else {
          lcd_print_dir_entry(y);
        }
      }
    }

    lcd_cursor(true);
    for (;;) {
      lcd_locate(0, my);
      //printf("mp: %u   my: %u\r\n", mp, my);
      //while (!get_key_state(KEY_ANY));
      if (get_key_autorepeat(KEY_PREV)) {
        if (mp > 0) {
          --mp;
          if (my > 0) --my;
          else {
            my = LCD_LINES - 1;
            if (mp < LCD_LINES) {
              while ((mp - my) >= DIRNAV_OFFSET) {
                --my;
                // TODO: is this really necessary?
                uart_puts_P(PSTR("my fixed\r\n"));
              }
            }
            break;
          }
        } else {
          my = LCD_LINES - 2;
          mp = entries + DIRNAV_OFFSET - 1;
          break;
        }
      }
      if (get_key_autorepeat(KEY_NEXT)) {
        if (mp < (entries -1 + DIRNAV_OFFSET)) {
          ++mp;
          if (my < (LCD_LINES - 1))  ++my;
          else {
            my = 0;
            break;
          }
        } else {
          mp = 0;
          my = 0;
          break;
        }
      }
      if (get_key_press(KEY_SEL)) {
        action = true;
        break;
      }
    }
    lcd_cursor(false);
    if (!action) continue;
    if (mp == NAV_ABORT) goto cleanup;
    if (mp == NAV_PARENT) {
      uart_puts_P(PSTR("CD_\r\n"));
      ustrcpy_P(command_buffer, PSTR("CD_"));
      command_length = 3;
      parse_doscommand();
      clear_command_buffer();
      stack_mp[pos_stack] = 0;
      stack_my[pos_stack] = 0;
      if (pos_stack > 0) --pos_stack;
      printf("pos_stack set to %d\r\n", pos_stack);
      if (current_error != ERROR_OK) goto cleanup;
      goto reread;
    }
    if (ep[mp - DIRNAV_OFFSET]->flags & E_DIR ||
        ep[mp - DIRNAV_OFFSET]->flags & E_IMAGE)
    {
      clear_command_buffer();
      ustrcpy_P(command_buffer, PSTR("CD:"));
      ustrncpy(command_buffer + 3, ep[mp - DIRNAV_OFFSET]->filename, 16);
      command_length = ustrlen(command_buffer);
      parse_doscommand();
      clear_command_buffer();
      if (current_error != ERROR_OK) goto cleanup;
      if (pos_stack < MAX_LASTPOS) {
        stack_mp[pos_stack]   = mp;
        stack_my[pos_stack++] = my;
        printf("pos_stack set to %d\r\n", pos_stack);
      }
      goto reread;
    }
  }

reread:
  free_buffer(buf);

  buffer_t *p = buf_tbl;
  do {
    p->allocated = 0;
    p = p->pvt.buffer.next;
  } while (p != NULL);

  p = first_buf;
  if (p != NULL) do {
    p->allocated = 0;
    p = p->pvt.buffer.next;
  } while (p != NULL);

  set_busy_led(false); set_dirty_led(true);
  active_buffers = save_active_buffers;
  if (mp == NAV_ABORT) return;
  goto start;

cleanup:
  mp = NAV_ABORT;
  goto reread;
}
Exemplo n.º 28
0
bool menu(void) {
  uint8_t mp = 0;
  uint8_t my = 0;
  uint8_t i;
  uint8_t old_bus;
  bool action;

  old_bus = active_bus;
  bus_sleep(true);

  menu_select_status(); // disable splash screen if still active
  set_error(ERROR_OK);
  for (;;) {
    set_busy_led(false); set_dirty_led(true);
    lcd_clear();
    for (i = 0; i < LCD_LINES; i++) {
      lcd_locate(0, i);
      rom_menu_main(mp - my + i);
    }

    lcd_cursor(true);
    for (;;) {
      action = false;
      lcd_locate(0, my);
      //printf("mp: %u   my: %u\r\n", mp, my);
      //while (!get_key_state(KEY_ANY));
      if (get_key_autorepeat(KEY_PREV)) {
        if (mp > 0) {
          // Move up
          --mp;
          if (my > 0) {
            --my;               // Move within same page
          } else {
            mp = LCD_LINES - 1;
            my = LCD_LINES - 1; // page up
            break;
          }
        } else {
          // flip down to last menu entry
          my = MAIN_MENU_LAST_ENTRY % LCD_LINES;
          mp = MAIN_MENU_LAST_ENTRY;
          break;
        }
      }
      if (get_key_autorepeat(KEY_NEXT)) {
        if (mp < MAIN_MENU_LAST_ENTRY) {
          ++mp;
          if (my < (LCD_LINES - 1)) {
            ++my;               // Move within same page
          } else {
            my = 0;             // page down
            break;
          }
        } else {
          // flip up to first menu entry
          mp = 0;
          my = 0;
          break;
        }
      }
      if (get_key_press(KEY_SEL)) {
        action = true;
        break;
      }
    }
    lcd_cursor(false);
    if (!action) continue;
    lcd_clear();
    if      (mp == 1) menu_browse_files();
    else if (mp == 2) menu_device_number();
    else if (mp == 3) menu_set_clock();
    else if (mp == 4) menu_select_bus();
    else if (mp == 5) menu_adjust_contrast();
    else if (mp == 6) menu_adjust_brightness();
    else  break;
    if (current_error != ERROR_OK) break;
  }

  bus_sleep(false);
  lcd_draw_screen(SCRN_STATUS);
  update_leds();
  return old_bus != active_bus;
}
Exemplo n.º 29
0
Arquivo: main.c Projeto: sebseb7/lun1k
int main(void)
{
	RCC_ClocksTypeDef RCC_Clocks;


	RCC_GetClocksFreq(&RCC_Clocks);
	/* SysTick end of count event each 0.1ms */
	SysTick_Config(RCC_Clocks.HCLK_Frequency / 10000);

	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
	
	
	//prepare init structure
	GPIO_InitTypeDef GPIO_InitStructure;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
	GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_OUT;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
/*
 *      10   11   12
 *
 * E    C7   C5   B12
 * DC   A7   A7   A7
 * RW   C9   C9   C9
 * RST  A6   A6   A6
 * D0   C4   B15  B15
 * D1   C5   B0   B0
 * D2   B0   B1   B1
 * D3   B1   B2   B2
 * D4   B15  B14  B14
 * D5   B14  B13  B13
 * D6   B13  B12  C5
 * D7   B12  C6   C6
 *
 * v11 : E,D0..D7 swapped
 * v12 : E and D6 swapped
 *
 */

	
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_6;
	GPIO_Init(GPIOA, &GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_7;
	GPIO_Init(GPIOA, &GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_0;
	GPIO_Init(GPIOB, &GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_1;
	GPIO_Init(GPIOB, &GPIO_InitStructure);
#if LUN1K_VERSION >= 11
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_2;
	GPIO_Init(GPIOB, &GPIO_InitStructure);
#endif
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_12;
	GPIO_Init(GPIOB, &GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_13;
	GPIO_Init(GPIOB, &GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_14;
	GPIO_Init(GPIOB, &GPIO_InitStructure);
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_15;
	GPIO_Init(GPIOB, &GPIO_InitStructure);
#if LUN1K_VERSION == 10
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_4;
	GPIO_Init(GPIOC, &GPIO_InitStructure);
#endif
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_5;
	GPIO_Init(GPIOC, &GPIO_InitStructure);
#if LUN1K_VERSION >= 11
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_6;
	GPIO_Init(GPIOC, &GPIO_InitStructure);
#endif
#if LUN1K_VERSION == 10
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_7;
	GPIO_Init(GPIOC, &GPIO_InitStructure);
#endif
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_9;
	GPIO_Init(GPIOC, &GPIO_InitStructure);

	//leds
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_2;       
	GPIO_Init(GPIOD, &GPIO_InitStructure);  
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_1;       
	GPIO_Init(GPIOC, &GPIO_InitStructure);  
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_3;       
	GPIO_Init(GPIOC, &GPIO_InitStructure);  
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_3;       
	GPIO_Init(GPIOB, &GPIO_InitStructure);  

	//regen
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_1;       
	GPIO_Init(GPIOA, &GPIO_InitStructure);  


	//ESC Button
	GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_IN;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_8;       
	GPIO_Init(GPIOB, &GPIO_InitStructure);  
	
	//stick button
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_13;       
	GPIO_Init(GPIOC, &GPIO_InitStructure);  
	//A
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_4;       
	GPIO_Init(GPIOB, &GPIO_InitStructure);  
	//B
	GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_0;       
	GPIO_Init(GPIOA, &GPIO_InitStructure);  
	buttonsInitialized=1;
		


	//set RW to 0
	GPIO_ResetBits(GPIOC,GPIO_Pin_9);	

	// 12V power
	GPIOA->ODR           |=       1<<1;


	RNG_Enable();
	srand(RNG_Get());
	RNG_Disable();

	adc_a3_init();

	lcdInit();
	
	n35p112_init();

	
	int current_animation = 0;
	animations[current_animation].init_fp();
	int tick_count = 0;
	

	int loopcount = 0;

	uint8_t count  = 0;
		
	int16_t bat_voltage = adc_a3_get();

	float voltagesample = bat_voltage;

	while(1)
	{
		loopcount++;
		if((loopcount == 55)||(loopcount == 57))
		{
			GPIOC->ODR           |=       1<<1;
			GPIOD->ODR           |=       1<<2;
			GPIOB->ODR           |=       1<<3;
			GPIOC->ODR           |=       1<<3;
		}
		if((loopcount == 56)||(loopcount == 58))
		{
			GPIOC->ODR           &=       ~(1<<1);
			GPIOD->ODR           &=       ~(1<<2);
			GPIOB->ODR           &=       ~(1<<3);
			GPIOC->ODR           &=       ~(1<<3);
			if(loopcount==58)
				loopcount = 0;
		}
		
		uint32_t start_tick = tick;

		get_n35p112(&joy_x,&joy_y);

		animations[current_animation].tick_fp();
/*		int16_t bat_voltage = adc_a3_get();

		fill_8x6(20,20, 5,0,0,0);
		fill_8x6(20,30, 5,0,0,0);
		draw_number_8x6(20,20, bat_voltage, 5, ' ' ,255,255,255);

		voltagesample = voltagesample * 0.98f;
		voltagesample += bat_voltage * 0.02f;


		float tmp2 = voltagesample / (4096.0f / 3.3f);

		float tmp3 = tmp2 * 2.14f;

		draw_number_8x6(20,30, tmp3*1000, 5, ' ' ,255,255,255);

		setLedXY(bat_voltage-2364, count,255,0,0);*/

		lcdFlush();

		uint32_t duration = tick - start_tick;

		//draw_number_8x6(20,20, animations[current_animation].timing - duration, 6, ' ' ,255,255,255);


		if(animations[current_animation].timing > 0)
			Delay100us(animations[current_animation].timing - duration);
	

//		draw_number_8x6(20,30, joy_y, 3, ' ' ,255,255,255);

//		draw_filledCircle(joy_y>>1,joy_x>>1,8,0,0,0);
//		draw_filledCircle(joy_y>>1,joy_x>>1,5,255,255,255);


		count++;
		if(count > 128)
			count=0;

		tick_count++;


		if(get_key_press(KEY_ESC))
		{
			animations[current_animation].deinit_fp();

			current_animation++;
			if(current_animation == animationcount)
			{
				current_animation = 0;
			}
			tick_count=0;
	
			lcdFillRGB(0,0,0);

			animations[current_animation].init_fp();

			//usb_printf("diff: %i , %i (%i) (%i %i %i %i %i %i %i)\n",diff,int_status,i2c_errors,i2c_e[0],i2c_e[1],i2c_e[2],i2c_e[3],i2c_e[4],i2c_e[5],i2c_e[6]);

		}
	}

}
Exemplo n.º 30
0
int main(void) {
  /* Early system initialisation */
  early_board_init();
  system_init_early();
  leds_init();

  set_busy_led(1);
  set_dirty_led(0);

  /* Due to an erratum in the LPC17xx chips anything that may change */
  /* peripheral clock scalers must come before system_init_late()    */
  uart_init();
#ifndef SPI_LATE_INIT
  spi_init(SPI_SPEED_SLOW);
#endif
  timer_init();
  i2c_init();

  /* Second part of system initialisation, switches to full speed on ARM */
  system_init_late();
  enable_interrupts();

  /* Prompt software name and version string */
  uart_puts_P(PSTR("\r\nNODISKEMU " VERSION "\r\n"));

  /* Internal-only initialisation, called here because it's faster */
  buffers_init();
  buttons_init();

  /* Anything that does something which needs the system clock */
  /* should be placed after system_init_late() */
  rtc_init();    // accesses I2C
  disk_init();   // accesses card
  read_configuration(); // restores configuration, may change device address

  filesystem_init(0);
  // FIXME: change_init();

#ifdef CONFIG_REMOTE_DISPLAY
  /* at this point all buffers should be free, */
  /* so just use the data area of the first to build the string */
  uint8_t *strbuf = buffers[0].data;
  ustrcpy_P(strbuf, versionstr);
  ustrcpy_P(strbuf+ustrlen(strbuf), longverstr);
  if (display_init(ustrlen(strbuf), strbuf)) {
    display_address(device_address);
    display_current_part(0);
  }
#endif

  set_busy_led(0);

#if defined(HAVE_SD)
  /* card switch diagnostic aid - hold down PREV button to use */
  if (menu_system_enabled && get_key_press(KEY_PREV))
    board_diagnose();
#endif

  if (menu_system_enabled)
    lcd_splashscreen();

  bus_interface_init();
  bus_init();
  read_configuration();
  late_board_init();

  for (;;) {
    if (menu_system_enabled)
      lcd_refresh();
    else {
      lcd_clear();
      lcd_printf("#%d", device_address);
    }
    /* Unit number may depend on hardware and stored settings */
    /* so present it here at last */
    printf("#%02d\r\n", device_address);
    bus_mainloop();
    bus_interface_init();
    bus_init();    // needs delay, inits device address with HW settings
  }
}