Example #1
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(slip_process, ev, data)
{
  PROCESS_BEGIN();

  rxbuf_init();

  while(1) {
    PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);

    slip_active = 1;

    /* Move packet from rxbuf to buffer provided by uIP. */
    uip_len = slip_poll_handler(&uip_buf[UIP_LLH_LEN],
				UIP_BUFSIZE - UIP_LLH_LEN);
#if !UIP_CONF_IPV6
    if(uip_len == 4 && strncmp((char*)&uip_buf[UIP_LLH_LEN], "?IPA", 4) == 0) {
      char buf[8];
      memcpy(&buf[0], "=IPA", 4);
      memcpy(&buf[4], &uip_hostaddr, 4);
      if(input_callback) {
	input_callback();
      }
      slip_write(buf, 8);
    } else if(uip_len > 0
       && uip_len == (((u16_t)(BUF->len[0]) << 8) + BUF->len[1])
       && uip_ipchksum() == 0xffff) {
#define IP_DF   0x40
      if(BUF->ipid[0] == 0 && BUF->ipid[1] == 0 && BUF->ipoffset[0] & IP_DF) {
	static u16_t ip_id;
	u16_t nid = ip_id++;
	BUF->ipid[0] = nid >> 8;
	BUF->ipid[1] = nid;
	nid = uip_htons(nid);
	nid = ~nid;		/* negate */
	BUF->ipchksum += nid;	/* add */
	if(BUF->ipchksum < nid) { /* 1-complement overflow? */
	  BUF->ipchksum++;
	}
      }
      tcpip_input();
    } else {
      uip_len = 0;
      SLIP_STATISTICS(slip_ip_drop++);
    }
#else /* UIP_CONF_IPV6 */
    if(uip_len > 0) {
      if(input_callback) {
        input_callback();
      }
      tcpip_input();
    }
#endif /* UIP_CONF_IPV6 */
  }
Flu_Combo_Box :: Flu_Combo_Box( int X, int Y, int W, int H, const char* l )
  : Fl_Group( X, Y, W, H, l ), input( X, Y, W, H )
{
  box( FL_DOWN_BOX );
  align( FL_ALIGN_LEFT );
  pop_height( 100 );

  _cbox = NULL;
  _valbox = FL_UP_BOX;

  input_callback( NULL );
  input.box( FL_FLAT_BOX );
  input.callback( input_cb, this );
  input.when( FL_WHEN_ENTER_KEY_ALWAYS );
  input.color( FL_WHITE, selection_color());
  input.textfont( FL_HELVETICA );
  input.textsize(  FL_NORMAL_SIZE );
  input.textcolor( FL_FOREGROUND_COLOR );

  input.resize( X+Fl::box_dx(box()), Y+Fl::box_dy(box()), 
		W-18-Fl::box_dw(box()), H-Fl::box_dh(box()) );

  editable( true );

  end();
}
Example #3
0
void GUI::TextBox::HandleEvent(const SDL_Event &event) {
	if(event.type == SDL_KEYDOWN) {
		if(event.key.keysym.sym == SDLK_BACKSPACE) {
			if(insert_offset > 0) {
				text.erase(--insert_offset, 1);
			}
		}else if(event.key.keysym.sym == SDLK_RETURN) {
			if(enter_callback) {
				enter_callback(*this, event);
			}
		}else if(event.key.keysym.sym == SDLK_LEFT) {
			if(insert_offset > 0) {
				insert_offset--;
			}
		}else if(event.key.keysym.sym == SDLK_RIGHT) {
			if(insert_offset < text.length()) {
				insert_offset++;
			}
		}else if(event.key.keysym.sym == SDLK_HOME) {
			insert_offset = 0;
		}else if(event.key.keysym.sym == SDLK_END) {
			insert_offset = text.length();
		}else if(event.key.keysym.sym == SDLK_DELETE) {
			if(insert_offset < text.length()) {
				text.erase(insert_offset, 1);
			}
		}else if(isprint(event.key.keysym.sym)) {
			if(input_callback) {
				if(input_callback(*this, event)) {
					text.insert(insert_offset++, 1, event.key.keysym.sym);
				}else{
					std::cerr << "Illegal character" << std::endl;
				}
			}else{
				text.insert(insert_offset++, 1, event.key.keysym.sym);
			}
		}
	}else if(event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_LEFT) {
		TTF_Font *font = FontStuff::LoadFont("fonts/DejaVuSansMono.ttf", 14);
		int fw = FontStuff::TextWidth(font, "A");

		if(event.button.y > y && event.button.y < y+h-1) {
			for(insert_offset = 0; event.button.x > x + 2 + fw * (insert_offset+1) && insert_offset < text.length();) {
				insert_offset++;
			}
		}
	}
}
Example #4
0
File: command.c Project: V07D/mc
static cb_ret_t
command_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{
    switch (msg)
    {
    case MSG_FOCUS:
        /* Never accept focus, otherwise panels will be unselected */
        return MSG_NOT_HANDLED;

    case MSG_KEY:
        /* Special case: we handle the enter key */
        if (parm == '\n')
            return enter (INPUT (w));
        /* fall through */

    default:
        return input_callback (w, sender, msg, parm, data);
    }
}
Example #5
0
static cb_ret_t
command_callback (Widget * w, widget_msg_t msg, int parm)
{
    WInput *cmd = (WInput *) w;

    switch (msg)
    {
    case WIDGET_FOCUS:
        /* Never accept focus, otherwise panels will be unselected */
        return MSG_NOT_HANDLED;

    case WIDGET_KEY:
        /* Special case: we handle the enter key */
        if (parm == '\n')
        {
            return enter (cmd);
        }
        /* fall through */

    default:
        return input_callback (w, msg, parm);
    }
}
static int
input_callback(IDL_input_reason reason, union IDL_input_data *cb_data,
               gpointer user_data)
{
    input_callback_state *callback_state = user_data;
    input_data *data = callback_state->input_stack;
    input_data *new_data = NULL;
    unsigned int len, copy;
    int rv;
    char *start;

    switch(reason) {
      case IDL_INPUT_REASON_INIT:
        if (data == NULL || data->next == NULL) {
            /*
             * This is the first file being processed.  As it's the target
             * file, we only look for it in the first entry in the include
             * path, which we assume to be the current directory.
             */

            /* XXXmccabe proper assumption?  Do we handle files in other
               directories? */

            IncludePathEntry first_entry;

            first_entry.directory = callback_state->include_path->directory;
            first_entry.next = NULL;

            new_data = new_input_data(cb_data->init.filename,
                                               &first_entry);
        } else {
            new_data = new_input_data(cb_data->init.filename,
                                               callback_state->include_path);
        }

        if (!new_data)
            return -1;

        IDL_file_set(new_data->filename, (int)new_data->lineno);
        callback_state->input_stack = new_data;
        return 0;

      case IDL_INPUT_REASON_FILL:
        start = NULL;
        len = 0;

        while (data->point >= data->max) {
            if (!data->next)
                return 0;

            /* Current file is done; revert to including file */
            callback_state->input_stack = data->next;
            free(data->filename);
            free(data->buf);
            free(data);
            data = callback_state->input_stack;

            IDL_file_set(data->filename, (int)data->lineno);
            IDL_inhibit_pop();
        }
        
        /*
         * Now we scan for sequences which require special attention:
         *   \n#include                   begins an include statement
         *   \n%{                         begins a raw-source block
         *   /\*                          begins a comment
         * 
         * We used to be fancier here, so make sure that we sent the most
         * data possible at any given time.  To that end, we skipped over
         * \n%{ raw \n%} blocks and then _continued_ the search for special
         * sequences like \n#include or /\* comments .
         * 
         * It was really ugly, though -- liberal use of goto!  lots of implicit
         * state!  what fun! -- so now we just do this:
         *
         * if (special at start) {
         *     process that special -
         *         - raw: send it to libIDL, and don't look inside for specials
         *         - comments: adjust point and start over
         *         - includes: push new input_data struct for included file, and
         *           start over
         * } else {
         *     scan for next special
         *     send data up to that special to libIDL
         * }
         *
         * If len is set to zero, it is a sentinel value indicating we a comment
         * or include was found, and parsing should start over.
         *
         * XXX const string foo = "/\*" will just screw us horribly.
         * Hm but.  We could treat strings as we treat raw blocks, eh?
         */

        /*
         * Order is important, so that you can have /\* comments and
         * #includes within raw sections, and so that you can comment out
         * #includes.
         */
        rv = NextIsRaw(data, &start, (int *)&len);
        if (rv == -1) return -1;
        if (!rv) {
            /*
             * When NextIsComment succeeds, it returns a 0 len (requesting a
             * restart) and adjusts data->point to pick up after the comment.
             */
            rv = NextIsComment(data, &start, (int *)&len);
            if (rv == -1) return -1;
            if (!rv) {
                /*
                 * NextIsInclude might push a new input_data struct; if so, it
                 * will return a 0 len, letting the callback pick up the new
                 * file the next time around.
                 */
                rv = NextIsInclude(callback_state, &start, (int *)&len);
                if (rv == -1) return -1;
                if (!rv)
                    FindSpecial(data, &start, (int *)&len);
            }
        }

        if (len == 0) {
            /*
             * len == 0 is a sentinel value that means we found a comment or
             * include.  If we found a comment, point has been adjusted to
             * point past the comment.  If we found an include, a new input_data
             * has been pushed.  In both cases, calling the input_callback again
             * will pick up the new state.
             */
            return input_callback(reason, cb_data, user_data);
        }

        copy = MIN(len, (unsigned int) cb_data->fill.max_size);
        memcpy(cb_data->fill.buffer, start, copy);
        data->point = start + copy;

        if (tracefile)
            fwrite(cb_data->fill.buffer, copy, 1, tracefile);

        return copy;

      case IDL_INPUT_REASON_ABORT:
      case IDL_INPUT_REASON_FINISH:
        while (data != NULL) {
            input_data *next;

            next = data->next;
            free(data->filename);
            free(data->buf);
            free(data);
            data = next;
        }
        return 0;

      default:
        g_error("unknown input reason %d!", reason);
        return -1;
    }
}
Example #7
0
/*---------------------------------------------------------------------------*/
static void
cs_isr(uint8_t port, uint8_t pin)
{
  int d, i;

  /* check if ISR comes from CS pin */
  if((port != SPI_CS_PORT) && (pin != SPI_CS_PIN)) {
    return;
  }
  
  /* CS goes HIGH, End of Transmission */
  if(GPIO_READ_PIN(SPI_CS_PORT_BASE, SPI_CS_PIN_MASK)) {
    /* check if something left in RX FIFO after transaction, and put all remain data into RX ringbuffer */
    while(REG(SSI0_BASE + SSI_SR) & SSI_SR_RNE) {
      d = REG(SSI0_BASE + SSI_DR);
      ringbuf_put(&spi_rx_buf, d);
      PRINTF("ERR: Something left in FIFO!\r\n");
    }
    /* pass received  data to upper level driver via callback */
    d = ringbuf_get(&spi_rx_buf);
    while(d != -1) {
      if(input_callback) {
        input_callback((unsigned char)d);
      }
      d = ringbuf_get(&spi_rx_buf);
    }
    /* mark that there is no start of frame phase */
    /* TODO: is it necessary? */
    start_of_frame = 0;
    /* check if TX FIFO is not empty */
    if(!(REG(SSI0_BASE + SSI_SR) & SSI_SR_TNF)) {
      /* if TX FIFO is not empty, reset SSI to flush TX FIFO
         it is possible that previous transaction has been failed, so complete frame
         has not been transmitted. Eg. NBR has been turned off during transmission
      */
      PRINTF("ERR: TX FIFO not empty after transaction!\r\n");
      ssi_reset_request = 3;
    }
    if(ssi_reset_request) {
      /* if reset request is active, perform SSI reset */
      PRINTF("WARN: SSI reset request %u\r\n", ssi_reset_request);
      ssi_reconfigure(1);
      ssi_reset_request = 0;
    }
  } else {
    /* CS goes LOW, Start of Transmission */
    start_of_frame = 1;
    /* fill TX FIFO with data only if we were connected */
    if(connected) {
      /* get number of elements in ringbuffer */
      d = ringbuf_elements(&spi_tx_buf);
      /* send that number to master with characteristic upper nibble */
      d = 0x50 | (d > 7 ? 7 : d);
      REG(SSI0_BASE + SSI_DR) = d;
      for(i = 0; i < 7; i++) {
        if(!(REG(SSI0_BASE + SSI_SR) & SSI_SR_TNF)) {
          /* Error, we shouldn't overflow TX FIFO */
          PRINTF("ERR: TX FIFO overflow!\r\n");
          break;
        }
        d = ringbuf_get(&spi_tx_buf);
        if(d == -1) {
          REG(SSI0_BASE + SSI_DR) = 0xff;
        } else {
          REG(SSI0_BASE + SSI_DR) = d;
        }
      }
      /* If the CS interrupt was triggered due to slave requesting SPI transfer,
       * we clear the INT pin, as the transfer has now been completed.
       */
      if(ringbuf_elements(&spi_tx_buf) == 0) {
        GPIO_CLR_PIN(SPI_INT_PORT_BASE, SPI_INT_PIN_MASK);
      }
    } else {
      /* mark we are connected */
      connected = 1;
    }
  }
}
Example #8
0
static PRESULT find_btn_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	VACTION unact;    
	UINT8 i,bID;
	UINT32 str_len;
	char ch,str_temp[2];

	bID = OSD_GetObjID(pObj);
	switch(event)
	{
		case EVN_UNKNOWN_ACTION:
		unact = (VACTION)(param1>>16);
		ret = PROC_LOOP;
		str_len = ComUniStrLen(input_name_str);
	    
		if(unact == VACT_DEL || (unact == VACT_ENTER && key_chars[bID - 1] == 0x7F) )   /* DEL */
		{
			if(str_len>0)
			{
				input_name_str[str_len-1] = 0;
				OSD_DrawObject((POBJECT_HEAD)&find_input, C_UPDATE_ALL);
				if(!edit_keyboard_flag)
				{
					input_callback((UINT8*)input_name_str);                
				}
			}
		}
		else if(unact == VACT_OK || (unact == VACT_ENTER && key_chars[bID - 1] == 0xFF) ) /* OK */
		{
			check_ok = TRUE;
			ret = PROC_LEAVE;
			if(name_valid_func != NULL)
			{
				if(name_valid_func(input_name_str) == 0)
				{
					ret = PROC_LEAVE;				
				}
				else
				{
					ret = PROC_LOOP;
				}
			}
		}
		else if(unact == VACT_ENTER)
		{
			ch = key_chars[bID - 1];
			if(str_len < MAX_INPUT_STR_LEN)
			{
				SetUniStrCharAt(input_name_str,ch,str_len);
				input_name_str[str_len + 1] = 0;
				OSD_DrawObject((POBJECT_HEAD)&find_input, C_UPDATE_ALL);
				if(!edit_keyboard_flag)
				{
				        input_callback((UINT8*)input_name_str);
				}
			}
		}
		else if(unact == VACT_CAPS)
		{
			str_temp[1] = '\0';
			for(i = 0;i < CHRACTER_CNT;i++)
			{
				if((key_chars[i] >= 'a') && (key_chars[i] <= 'z'))
				{
					key_chars[i] = key_chars[i] - ('a' - 'A');
				}
				else if((key_chars[i] >= 'A') && (key_chars[i] <= 'Z'))
				{
					key_chars[i] = key_chars[i] + ('a' - 'A');
				}
				str_temp[0] = key_chars[i];
				OSD_SetTextFieldContent(&find_txt_chars[i], STRING_ANSI,(UINT32)str_temp);
			}
			OSD_TrackObject((POBJECT_HEAD)&g_win_find, C_DRAW_SIGN_EVN_FLG | C_UPDATE_ALL);
			//draw_caps_colbtn_ext(COLBTN_L,  COLBTN_T, 1,IM_EPG_COLORBUTTON_YELLOW);
			//draw_del_colbtn_ext(COLBTN_L + 120, COLBTN_T, 1,IM_EPG_COLORBUTTON_RED);
			//draw_ok_colbtn_ext(COLBTN_L + 240,COLBTN_T, 1,IM_EPG_COLORBUTTON_BLUE);

    		draw_caps_colbtn_ext(COLBTN_L,  COLBTN_T, 1,IM_EPG_COLORBUTTON_YELLOW);
    		draw_del_colbtn_ext(COLBTN_L + 120,           COLBTN_T, 1,IM_EPG_COLORBUTTON_RED);
    		draw_ok_colbtn_ext(COLBTN_L + 240,       COLBTN_T, 1,IM_EPG_COLORBUTTON_BLUE);
        }
		break;
	}
	return ret;
}