Stoper/hello_widget.c

159 lines
5.3 KiB
C
Raw Permalink Normal View History

2022-06-06 11:02:40 +02:00
#include <stdbool.h>
#include <stdint.h>
#include <utils/ustdlib.h>
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "grlib/grlib.h"
#include "grlib/widget.h"
#include "grlib/canvas.h"
#include "grlib/pushbutton.h"
#include "drivers/frame.h"
#include "drivers/kentec320x240x16_ssd2119.h"
#include "drivers/pinout.h"
#include "drivers/touch.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/interrupt.h"
#include "driverlib/timer.h"
extern tCanvasWidget g_sBackground;
extern tPushButtonWidget g_sPushBtn;
extern tPushButtonWidget g_sPushReset;
tContext g_sContext;
uint32_t g_ui32Flags;
const char Counter[6] = "Stoper";
char flagStart = 0;
unsigned int msec = 0;
unsigned int sec = 0;
unsigned int min = 0;
unsigned int hrs = 0;
char charTime[] = "00:00:00.0 ";
void stoperTick(void)
{
msec++;
if (msec == 10){
msec = 0;
sec++;
}
else if (sec == 60){
sec = 0;
min++;
}
else if (min == 60){
min = 0;
hrs++;
}
}
void Timer0IntHandler(void)
{
ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); // Clear the timer interrupt.
if(flagStart == 1){
stoperTick(); // zliczanie ms
}
}
void OnButtonPress(tWidget *psWidget); // The canvas widget acting as the background to the display.
void OnButtonReset(tWidget *psWidget);
Canvas(g_sBackground, WIDGET_ROOT, 0, &g_sPushBtn,
&g_sKentec320x240x16_SSD2119, 10, 25, 300, (240 - 25 -10),
CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0);
RectangularButton(g_sPushBtn, &g_sBackground, 0, &g_sPushReset, // The button used to hide or display the "Hello World" message.
&g_sKentec320x240x16_SSD2119, 40, 140, 80, 40,
(PB_STYLE_OUTLINE | PB_STYLE_TEXT_OPAQUE | PB_STYLE_TEXT |
PB_STYLE_FILL | PB_STYLE_RELEASE_NOTIFY),
ClrDarkBlue, ClrBlue, ClrWhite, ClrWhite,
g_psFontCmss22b, "START", 0, 0, 0, 0, OnButtonPress);
RectangularButton(g_sPushReset, &g_sPushBtn, 0, 0,
&g_sKentec320x240x16_SSD2119, 180, 140, 80, 40,
(PB_STYLE_OUTLINE | PB_STYLE_TEXT_OPAQUE | PB_STYLE_TEXT |
PB_STYLE_FILL | PB_STYLE_RELEASE_NOTIFY),
ClrDarkRed, ClrRed, ClrWhite, ClrWhite,
g_psFontCmss22b, "RESET", 0, 0, 0, 0, OnButtonReset);
bool g_bHelloVisible = false;
2022-06-07 09:02:53 +02:00
2022-06-06 11:02:40 +02:00
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif
void OnButtonPress(tWidget *psWidget) // funkcja obslugujaca przycisk start
{
g_bHelloVisible = !g_bHelloVisible;
if(g_bHelloVisible)
{
WidgetRemove((tWidget *)&g_sPushReset);
flagStart = 1;
PushButtonTextSet(&g_sPushBtn, "STOP");
WidgetPaint(WIDGET_ROOT);
}
else
{
WidgetAdd((tWidget *)&g_sPushBtn, (tWidget *)&g_sPushReset);
flagStart = 0;
PushButtonTextSet(&g_sPushBtn, "START");
WidgetPaint((tWidget *)&g_sPushBtn);
}
}
void OnButtonReset(tWidget *psWidget) // funkcja obslugujaca przycisk reset
{
flagStart = 0;
msec = 0;
sec = 0;
min = 0;
hrs = 0;
}
int main(void)
{
// Run from the PLL at 120 MHz.
uint32_t ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480), 120000000);
// Konfiguracja wyswietlacza
PinoutSet(); // Configure the device pins.
Kentec320x240x16_SSD2119Init(ui32SysClock); // Initialize the display driver.
GrContextInit(&g_sContext, &g_sKentec320x240x16_SSD2119); // Initialize the graphics context.
FrameDraw(&g_sContext, "StOpErEk"); // Draw the application frame.
TouchScreenInit(ui32SysClock); // Initialize the touch screen driver.
TouchScreenCallbackSet(WidgetPointerMessage); // Set the touch screen event handler.
WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sBackground); // Add the compile-time defined widgets to the widget tree.
WidgetPaint(WIDGET_ROOT); // Paint the widget tree to make sure they all appear on the display.
// Konfiguracja timera
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
ROM_IntMasterEnable(); // Enable processor interrupts.
ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); // Configure the two 32-bit periodic timers.
ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ui32SysClock/10);
ROM_IntEnable(INT_TIMER0A); // Setup the interrupts for the timer timeouts.
ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
ROM_TimerEnable(TIMER0_BASE, TIMER_A); // Enable the timers
while(1)
{
usprintf(charTime,"%02u:%02u:%02u.%01u ",hrs,min,sec,msec); // Convert unsigned ints to one char
GrStringDraw(&g_sContext, charTime, -1, 140, 55, 1); // Draw a stopwatch result
WidgetMessageQueueProcess(); // Process any messages from or for the widgets.
}
}