📄 pioag_pin.c
字号:
#include "pioag_private.h"
#include "ag_types.h"
#include <panic.h>
#include <pio.h>
#include <ps.h>
#include <stdlib.h>
#include <string.h>
/*
pioAgLedFlashTimer
Timer function that flashes the LEDs and increments the PIN Code count.
*/
static Delay pioAgLedFlashTimer(TimerHandle h)
{
uint16 pioValue = 0;
uint16 pioMask = LED1 | LED2;
/* keep the compiler happy */
h = h;
/* Get the current PIO values and mask the stuff we're not interested in */
pioValue = PioGet() & pioMask;
if (pioValue)
{
/* Reset LED's */
PioSet(LED1 | LED2, 0);
}
else
{
/*
Increment count, note that this will contain a number that is
one bigger than required since it counts the number of times
this function is called which will include the zero indication.
*/
PioAgState.pinCode[PioAgState.pinLengthBytes]++;
/* Reset count to zero if it is too big */
if (PioAgState.pinCode[PioAgState.pinLengthBytes] > 10)
PioAgState.pinCode[PioAgState.pinLengthBytes] = 1;
/* Set LED's */
if (PioAgState.pinCode[PioAgState.pinLengthBytes] == 1)
{
/* Set zero indicator */
PioSet(LED1, LED1);
}
else
{
/* Set non-zero indicator */
PioSet(LED2, LED2);
}
}
return D_mSEC(500);
}
/*
pioAgGetPinCode
Gets pin code from user, this is done by a cunning sequence of
flashing LED's and button presses. PIO2 flashes to indicate a zero,
then PIO3 flashes to indicate 1.2.3. etc. When the LED's have flashed
the appropriate number of times press PIO6 to move on to the next pin
enter. When the PIN has been entered press PIO7 to move on to the next step.
*/
void pioAgGetPinCode(void)
{
/* Start LED Flash Timer */
if (PioAgState.timerHandle == NULL_TIMER)
{
/* This is called repeatedly so only alloc array if there is no pin stored */
if (PioAgState.pinLengthBytes == 0)
{
/* Allocate the array we're going to store the PIN in and init it to zero */
PioAgState.pinCode = (uint8 *)PanicNull(malloc(MAX_PIN_LENGTH));
memset(PioAgState.pinCode, 0, MAX_PIN_LENGTH);
}
PioAgState.timerHandle = TimerAdd(D_mSEC(1000), pioAgLedFlashTimer);
}
}
/*
pioAgPinEntryComplete
Pin entry stage has finished either because the user has pressed a
button to indicate this or because the full MAX_PIN_LENGTH values
have been entered
*/
void pioAgPinEntryComplete(void)
{
/* PIN entry is complete send message to start inquiry */
uint16 tmp_len = PioAgState.pinLengthBytes;
/* Cancel the timer and clear the LED's */
TimerCancel(PioAgState.timerHandle);
PioAgState.timerHandle = NULL_TIMER;
/* Reset the Leds */
PioSet(LED1 | LED2, 0);
/* Store the PIN code and its length. */
(void) PsStore(PIO_AG_PS_PIN_CODE, PioAgState.pinCode, PioAgState.pinLengthBytes);
(void) PsStore(PIO_AG_PS_PIN_LENGTH, &(tmp_len), 1);
PioAgState.pinEntered = 1;
/*
PIN stored so free the pin code array. If we need the PIN we have to
read it out of persistent store. This saves us a few words since the
PIN is usually only entered once (or a small number of times).
*/
PioAgState.pinLengthBytes = 0;
free(PioAgState.pinCode);
PioAgState.pinCode = 0;
/* Start Inquiry */
pioAgInquiryReq();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -