コード例 #1
0
ファイル: Random.c プロジェクト: 12019/ChameleonMini
void RandomGetBuffer(void* Buffer, uint8_t ByteCount)
{
    uint8_t* BufferPtr = (uint8_t*) Buffer;

    while(ByteCount--) {
        *BufferPtr++ = RandomGetByte();
    }
}
コード例 #2
0
ファイル: Commands.c プロジェクト: MarxGonzalez/ChameleonMini
CommandStatusIdType CommandSetUid(const char* InParam)
{
  uint8_t UidBuffer[COMMAND_UID_BUFSIZE];
  uint16_t UidSize = ActiveConfiguration.UidSize;

  if (strcmp_P(InParam, PSTR(COMMAND_UID_RANDOM)) == 0) {
    /* Load with random bytes */
    for (uint8_t i=0; i<UidSize; i++) {
      UidBuffer[i] = RandomGetByte();
    }
  } else {
    /* Convert to Bytes */
    if (HexStringToBuffer(UidBuffer, sizeof(UidBuffer), InParam) != UidSize) {
      /* Malformed input. Abort */
      return COMMAND_ERR_INVALID_PARAM_ID;
    }
  }

  ApplicationSetUid(UidBuffer);

  return COMMAND_INFO_OK_ID;
}
コード例 #3
0
ファイル: Button.c プロジェクト: CedricDinont/ChameleonMini
void ButtonTick(void)
{
    static uint8_t LastButtonState = 0;
    uint8_t ThisButtonState = ~BUTTON_PORT.IN;
    uint8_t ThisButtonChange = ThisButtonState ^ LastButtonState;
    uint8_t ThisButtonPress = ThisButtonChange & ThisButtonState;
    LastButtonState = ThisButtonState;

    if ( ThisButtonPress & BUTTON_MASK ) {
        uint8_t UidBuffer[32];
        ButtonActionEnum ButtonAction = GlobalSettings.ActiveSettingPtr->ButtonAction;

        if (ButtonAction == BUTTON_ACTION_UID_RANDOM) {
            for (uint8_t i=0; i<ActiveConfiguration.UidSize; i++) {
                UidBuffer[i] = RandomGetByte();
            }

            ApplicationSetUid(UidBuffer);
        } else if (ButtonAction == BUTTON_ACTION_UID_LEFT_INCREMENT) {
            ApplicationGetUid(UidBuffer);
            bool Carry = 1;
            uint8_t i;

            for (i=0; i<ActiveConfiguration.UidSize; i++) {
                if (Carry) {
                    if (UidBuffer[i] == 0xFF) {
                        Carry = 1;
                    } else {
                        Carry = 0;
                    }

                    UidBuffer[i] = (UidBuffer[i] + 1) & 0xFF;
                }
            }

            ApplicationSetUid(UidBuffer);
        } else if (ButtonAction == BUTTON_ACTION_UID_RIGHT_INCREMENT) {
            ApplicationGetUid(UidBuffer);
            bool Carry = 1;
            uint8_t i = ActiveConfiguration.UidSize;

            while(i-- > 0) {
                if (Carry) {
                    if (UidBuffer[i] == 0xFF) {
                        Carry = 1;
                    } else {
                        Carry = 0;
                    }

                    UidBuffer[i] = (UidBuffer[i] + 1) & 0xFF;
                }
            }

            ApplicationSetUid(UidBuffer);
        } else if (ButtonAction == BUTTON_ACTION_UID_LEFT_DECREMENT) {
            ApplicationGetUid(UidBuffer);
            bool Carry = 1;
            uint8_t i;

            for (i=0; i<ActiveConfiguration.UidSize; i++) {
                if (Carry) {
                    if (UidBuffer[i] == 0x00) {
                        Carry = 1;
                    } else {
                        Carry = 0;
                    }

                    UidBuffer[i] = (UidBuffer[i] - 1) & 0xFF;
                }
            }

            ApplicationSetUid(UidBuffer);
        } else if (ButtonAction == BUTTON_ACTION_UID_RIGHT_DECREMENT) {
            ApplicationGetUid(UidBuffer);
            bool Carry = 1;
            uint8_t i = ActiveConfiguration.UidSize;

            while(i-- > 0) {
                if (Carry) {
                    if (UidBuffer[i] == 0x00) {
                        Carry = 1;
                    } else {
                        Carry = 0;
                    }

                    UidBuffer[i] = (UidBuffer[i] - 1) & 0xFF;
                }
            }

            ApplicationSetUid(UidBuffer);
        } else if (ButtonAction == BUTTON_ACTION_CYCLE_SETTINGS) {
        	SettingsCycle();
        } else if (ButtonAction == BUTTON_ACTION_STORE_MEM) {
        	MemoryStore();
        } else if (ButtonAction == BUTTON_ACTION_RECALL_MEM) {
        	MemoryRecall();
        }
    }
}