📄 screen_saver.c
字号:
//
// Loop through the number of updates to the graphical screen saver to be
// done before the display is turned off.
//
for(ulCount = 0; ulCount < (2 * 60 * 30); ulCount++)
{
//
// Wait until an update has been requested.
//
while(HWREGBITW(&g_ulFlags, FLAG_UPDATE) == 0)
{
}
//
// Clear the update request flag.
//
HWREGBITW(&g_ulFlags, FLAG_UPDATE) = 0;
//
// See if the button has been pressed.
//
if(HWREGBITW(&g_ulFlags, FLAG_BUTTON_PRESS))
{
//
// Clear the button press flag.
//
HWREGBITW(&g_ulFlags, FLAG_BUTTON_PRESS) = 0;
//
// Return to the caller, ending the screen saver.
//
return;
}
//
// Shift the lines down one entry in the history buffer.
//
for(ulLoop = 1; ulLoop < 30; ulLoop++)
{
g_pucScreenLinesX1[ulLoop - 1] = g_pucScreenLinesX1[ulLoop];
g_pucScreenLinesY1[ulLoop - 1] = g_pucScreenLinesY1[ulLoop];
g_pucScreenLinesX2[ulLoop - 1] = g_pucScreenLinesX2[ulLoop];
g_pucScreenLinesY2[ulLoop - 1] = g_pucScreenLinesY2[ulLoop];
}
//
// Update the starting X coordinate of the youngest line. If the edge
// of the display has been reached, then choose a new travel speed in
// the opposite direction.
//
g_pucScreenLinesX1[29] = g_pucScreenLinesX1[28] + g_cScreenDeltaX1;
if(g_pucScreenLinesX1[29] > 127)
{
if(g_pucScreenLinesX1[29] > 191)
{
g_pucScreenLinesX1[29] = 0;
g_cScreenDeltaX1 = (RandomNumber() >> 30) + 1;
}
else
{
g_pucScreenLinesX1[29] = 127;
g_cScreenDeltaX1 = (char)-1 - (RandomNumber() >> 30);
}
}
//
// Update the starting Y coordinate of the youngest line. If the edge
// of the display has been reached, then choose a new travel speed in
// the opposite direction.
//
g_pucScreenLinesY1[29] = g_pucScreenLinesY1[28] + g_cScreenDeltaY1;
if(g_pucScreenLinesY1[29] > 95)
{
if(g_pucScreenLinesY1[29] > 191)
{
g_pucScreenLinesY1[29] = 0;
g_cScreenDeltaY1 = (RandomNumber() >> 30) + 1;
}
else
{
g_pucScreenLinesY1[29] = 95;
g_cScreenDeltaY1 = (char)-1 - (RandomNumber() >> 30);
}
}
//
// Update the ending X coordinate of the youngest line. If the edge of
// the display has been reached, then choose a new travel speed in the
// opposite direction.
//
g_pucScreenLinesX2[29] = g_pucScreenLinesX2[28] + g_cScreenDeltaX2;
if(g_pucScreenLinesX2[29] > 127)
{
if(g_pucScreenLinesX2[29] > 191)
{
g_pucScreenLinesX2[29] = 0;
g_cScreenDeltaX2 = (RandomNumber() >> 30) + 1;
}
else
{
g_pucScreenLinesX2[29] = 127;
g_cScreenDeltaX2 = (char)-1 - (RandomNumber() >> 30);
}
}
//
// Update the ending Y coordinate of the youngest line. If the edge of
// the display has been reached, then choose a new travel speed in the
// opposite direction.
//
g_pucScreenLinesY2[29] = g_pucScreenLinesY2[28] + g_cScreenDeltaY2;
if(g_pucScreenLinesY2[29] > 95)
{
if(g_pucScreenLinesY2[29] > 191)
{
g_pucScreenLinesY2[29] = 0;
g_cScreenDeltaY2 = (RandomNumber() >> 30) + 1;
}
else
{
g_pucScreenLinesY2[29] = 95;
g_cScreenDeltaY2 = (char)-1 - (RandomNumber() >> 30);
}
}
//
// Clear the local frame buffer.
//
for(ulLoop = 0; ulLoop < 6144; ulLoop += 4)
{
*((unsigned long *)(g_pucFrame + ulLoop)) = 0;
}
//
// Loop through the lines in the history buffer.
//
for(ulLoop = 0; ulLoop < 30; ulLoop++)
{
//
// Draw this line if it "exists". If both end points are at 0,0
// then the line is assumed to not exist (i.e. the line history at
// the very start). There is a tiny likelyhood that the two
// endpoints will converge on 0,0 at the same time in which case
// there will be a small anomaly (though it would be extremely
// difficult to visually discern that it occurred).
//
if(g_pucScreenLinesX1[ulLoop] || g_pucScreenLinesY1[ulLoop] ||
g_pucScreenLinesX2[ulLoop] || g_pucScreenLinesY2[ulLoop])
{
ScreenSaverLine(g_pucScreenLinesX1[ulLoop],
g_pucScreenLinesY1[ulLoop],
g_pucScreenLinesX2[ulLoop],
g_pucScreenLinesY2[ulLoop], (ulLoop / 2) + 1);
}
}
//
// Copy the local frame buffer to the display.
//
RIT128x96x4ImageDraw(g_pucFrame, 0, 0, 128, 96);
}
//
// Clear the display and turn it off.
//
RIT128x96x4Clear();
RIT128x96x4DisplayOff();
//
// Turn off the music.
//
AudioOff();
//
// Configure PWM0 to generate a 10 KHz signal for driving the user LED.
//
PWMOutputState(PWM_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, false);
PWMGenDisable(PWM_BASE, PWM_GEN_0);
PWMGenConfigure(PWM_BASE, PWM_GEN_0,
(PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC |
PWM_GEN_MODE_DBG_RUN));
PWMGenPeriodSet(PWM_BASE, PWM_GEN_0, g_ulSystemClock / 80000);
PWMPulseWidthSet(PWM_BASE, PWM_OUT_0, 2);
PWMGenEnable(PWM_BASE, PWM_GEN_0);
PWMOutputState(PWM_BASE, PWM_OUT_0_BIT, true);
//
// Configure the user LED pin for hardware control, i.e. the PWM output
// from the PWM.
//
GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0);
//
// Loop forever.
//
for(ulCount = 0; ; ulCount = (ulCount + 1) & 63)
{
//
// Wait until an update has been requested.
//
while(HWREGBITW(&g_ulFlags, FLAG_UPDATE) == 0)
{
}
//
// Clear the update request flag.
//
HWREGBITW(&g_ulFlags, FLAG_UPDATE) = 0;
//
// Turn on the user LED in sixteen gradual steps.
//
if((ulCount > 0) && (ulCount <= 16))
{
PWMPulseWidthSet(PWM_BASE, PWM_OUT_0,
((((g_ulSystemClock / 80000) - 4) *
ulCount) / 16) + 2);
}
//
// Turn off the user LED in eight gradual steps.
//
if((ulCount > 32) && (ulCount <= 48))
{
PWMPulseWidthSet(PWM_BASE, PWM_OUT_0,
((((g_ulSystemClock / 80000) - 4) *
(48 - ulCount)) / 16) + 2);
}
//
// See if the button has been pressed.
//
if(HWREGBITW(&g_ulFlags, FLAG_BUTTON_PRESS) == 1)
{
//
// Clear the button press flag.
//
HWREGBITW(&g_ulFlags, FLAG_BUTTON_PRESS) = 0;
//
// Break out of the loop.
//
break;
}
}
//
// Turn off the user LED.
//
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0);
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, 0);
//
// Re-enable the music.
//
AudioOn();
//
// Turn on the display.
//
RIT128x96x4DisplayOn();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -