예제 #1
0
파일: user.c 프로젝트: banksh/lAAAHzertag
void super_dead_mode(){
    uint16_t counter = 0;
    while(!config.health){
        handle_music();
        // Manage base station comms
        uint8_t b;
        if(CHECK_CHAR()){
            b=AVAIL_CHAR();
            if(b == 0x10) {
                control_transfer();
            }
        }
        counter++;
        delay_1_ms();
        if(counter > config.death_period){
            counter = 0;
            led_off();
            Send_Byte(config.id);
            play_song((uint16_t*)dead_song,sizeof(dead_song)/sizeof(uint16_t),10000,0);
        }
        if(counter == config.death_period-50){
            red_led_on();
        }
    }
}
예제 #2
0
int inputOneParameters(char *inputChar, bool *valueFound)
{
    int inputInt = 0;
    bool minusOrNot = false;

    *inputChar = getchar();
    /* while to get a positive/negative number */
    while( CHECK_CHAR(*inputChar) )
    {
        if('-' != *inputChar)
        {
            if(false == minusOrNot)
            {
                /* positive number */
                inputInt = 10*inputInt + (*inputChar - '0');
            }
            else
            {
                /* negative number */
                inputInt = 10*inputInt - (*inputChar - '0');
            }
            *valueFound = true;
        }
        else
        {
            minusOrNot = true;
        }

        *inputChar = getchar();
    }

    return inputInt;
}
예제 #3
0
파일: ftcsbits.c 프로젝트: hsmith/freetype
  /*
   *  This function tries to load a small bitmap within a given FTC_SNode.
   *  Note that it returns a non-zero error code _only_ in the case of
   *  out-of-memory condition.  For all other errors (e.g., corresponding
   *  to a bad font file), this function will mark the sbit as `unavailable'
   *  and return a value of 0.
   *
   *  You should also read the comment within the @ftc_snode_compare
   *  function below to see how out-of-memory is handled during a lookup.
   */
  static FT_Error
  ftc_snode_load( FTC_SNode    snode,
                  FTC_Manager  manager,
                  FT_UInt      gindex,
                  FT_ULong    *asize )
  {
    FT_Error          error;
    FTC_GNode         gnode  = FTC_GNODE( snode );
    FTC_Family        family = gnode->family;
    FT_Memory         memory = manager->memory;
    FT_Face           face;
    FTC_SBit          sbit;
    FTC_SFamilyClass  clazz;


    if ( (FT_UInt)(gindex - gnode->gindex) >= snode->count )
    {
      FT_ERROR(( "ftc_snode_load: invalid glyph index" ));
      return FT_THROW( Invalid_Argument );
    }

    sbit  = snode->sbits + ( gindex - gnode->gindex );
    clazz = (FTC_SFamilyClass)family->clazz;

    sbit->buffer = 0;

    error = clazz->family_load_glyph( family, gindex, manager, &face );
    if ( error )
      goto BadGlyph;

    {
      FT_Int        temp;
      FT_GlyphSlot  slot   = face->glyph;
      FT_Bitmap*    bitmap = &slot->bitmap;
      FT_Pos        xadvance, yadvance; /* FT_GlyphSlot->advance.{x|y} */


      if ( slot->format != FT_GLYPH_FORMAT_BITMAP )
      {
        FT_TRACE0(( "ftc_snode_load:"
                    " glyph loaded didn't return a bitmap\n" ));
        goto BadGlyph;
      }

      /* Check whether our values fit into 8-bit containers!    */
      /* If this is not the case, our bitmap is too large       */
      /* and we will leave it as `missing' with sbit.buffer = 0 */

#define CHECK_CHAR( d )  ( temp = (FT_Char)d, (FT_Int) temp == (FT_Int) d )
#define CHECK_BYTE( d )  ( temp = (FT_Byte)d, (FT_UInt)temp == (FT_UInt)d )

      /* horizontal advance in pixels */
      xadvance = ( slot->advance.x + 32 ) >> 6;
      yadvance = ( slot->advance.y + 32 ) >> 6;

      if ( !CHECK_BYTE( bitmap->rows  )     ||
           !CHECK_BYTE( bitmap->width )     ||
           !CHECK_CHAR( bitmap->pitch )     ||
           !CHECK_CHAR( slot->bitmap_left ) ||
           !CHECK_CHAR( slot->bitmap_top  ) ||
           !CHECK_CHAR( xadvance )          ||
           !CHECK_CHAR( yadvance )          )
      {
        FT_TRACE2(( "ftc_snode_load:"
                    " glyph too large for small bitmap cache\n"));
        goto BadGlyph;
      }

      sbit->width     = (FT_Byte)bitmap->width;
      sbit->height    = (FT_Byte)bitmap->rows;
      sbit->pitch     = (FT_Char)bitmap->pitch;
      sbit->left      = (FT_Char)slot->bitmap_left;
      sbit->top       = (FT_Char)slot->bitmap_top;
      sbit->xadvance  = (FT_Char)xadvance;
      sbit->yadvance  = (FT_Char)yadvance;
      sbit->format    = (FT_Byte)bitmap->pixel_mode;
      sbit->max_grays = (FT_Byte)(bitmap->num_grays - 1);

      /* copy the bitmap into a new buffer -- ignore error */
      error = ftc_sbit_copy_bitmap( sbit, bitmap, memory );

      /* now, compute size */
      if ( asize )
        *asize = (FT_ULong)FT_ABS( sbit->pitch ) * sbit->height;

    } /* glyph loading successful */

    /* ignore the errors that might have occurred --   */
    /* we mark unloaded glyphs with `sbit.buffer == 0' */
    /* and `width == 255', `height == 0'               */
    /*                                                 */
    if ( error && FT_ERR_NEQ( error, Out_Of_Memory ) )
    {
    BadGlyph:
      sbit->width  = 255;
      sbit->height = 0;
      sbit->buffer = NULL;
      error        = FT_Err_Ok;
      if ( asize )
        *asize = 0;
    }

    return error;
  }
예제 #4
0
static FT_Error
ftc_sbit_node_load( FTC_SBitNode    snode,
                    FTC_Manager     manager,
                    FTC_SBitFamily  sfam,
                    FT_UInt         gindex,
                    FT_ULong       *asize )
{
    FT_Error       error;
    FTC_GlyphNode  gnode = FTC_GLYPH_NODE( snode );
    FT_Memory      memory;
    FT_Face        face;
    FT_Size        size;
    FTC_SBit       sbit;


    if ( gindex <  (FT_UInt)gnode->item_start                     ||
            gindex >= (FT_UInt)gnode->item_start + gnode->item_count )
    {
        FT_ERROR(( "ftc_sbit_node_load: invalid glyph index" ));
        return FTC_Err_Invalid_Argument;
    }

    memory = manager->library->memory;

    sbit = snode->sbits + ( gindex - gnode->item_start );

    error = FTC_Manager_Lookup_Size( manager, &sfam->type.font,
                                     &face, &size );
    if ( !error )
    {
        /* by default, indicates a `missing' glyph */
        sbit->buffer = 0;

        error = FT_Load_Glyph( face, gindex, sfam->type.flags | FT_LOAD_RENDER );
        if ( !error )
        {
            FT_Int        temp;
            FT_GlyphSlot  slot   = face->glyph;
            FT_Bitmap*    bitmap = &slot->bitmap;
            FT_Int        xadvance, yadvance;


            /* check that our values fit into 8-bit containers!       */
            /* If this is not the case, our bitmap is too large       */
            /* and we will leave it as `missing' with sbit.buffer = 0 */

#define CHECK_CHAR( d )  ( temp = (FT_Char)d, temp == d )
#define CHECK_BYTE( d )  ( temp = (FT_Byte)d, temp == d )

            /* XXX: FIXME: add support for vertical layouts maybe */

            /* horizontal advance in pixels */
            xadvance = ( slot->metrics.horiAdvance + 32 ) >> 6;
            yadvance = ( slot->metrics.vertAdvance + 32 ) >> 6;

            if ( CHECK_BYTE( bitmap->rows  )     &&
                    CHECK_BYTE( bitmap->width )     &&
                    CHECK_CHAR( bitmap->pitch )     &&
                    CHECK_CHAR( slot->bitmap_left ) &&
                    CHECK_CHAR( slot->bitmap_top  ) &&
                    CHECK_CHAR( xadvance )          &&
                    CHECK_CHAR( yadvance )          )
            {
                sbit->width     = (FT_Byte)bitmap->width;
                sbit->height    = (FT_Byte)bitmap->rows;
                sbit->pitch     = (FT_Char)bitmap->pitch;
                sbit->left      = (FT_Char)slot->bitmap_left;
                sbit->top       = (FT_Char)slot->bitmap_top;
                sbit->xadvance  = (FT_Char)xadvance;
                sbit->yadvance  = (FT_Char)yadvance;
                sbit->format    = (FT_Byte)bitmap->pixel_mode;
                sbit->max_grays = (FT_Byte)(bitmap->num_grays - 1);

#if 0 /* this doesn't work well with embedded bitmaps */

                /* grab the bitmap when possible - this is a hack! */
                if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
                {
                    slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
                    sbit->buffer           = bitmap->buffer;
                }
                else
#endif
                {
                    /* copy the bitmap into a new buffer -- ignore error */
                    error = ftc_sbit_copy_bitmap( sbit, bitmap, memory );
                }

                /* now, compute size */
                if ( asize )
                    *asize = ABS( sbit->pitch ) * sbit->height;

            }  /* glyph dimensions ok */

        } /* glyph loading successful */