Ok, that was not my problem.
When I use activate the SampleThread thread the Set button fails to work but the Clear button continues to work.
Without activating the SampleThread both buttons work fine, I have tried increasing the process stack size to 0x2000 and it will still not work properly.
I am a but stumped here..
Code: Select all
#include "ch.h"
#include "hal.h"
#include "gfx.h"
#include "stubs.c"
#include "syscalls.c"
static GButtonObject gClear;
static GButtonObject gSet;
static GListener gl;
GHandle GW1, GW2;
#define ADC_GRP1_NUM_CHANNELS 1
#define ADC_GRP1_BUF_DEPTH 1
static adcsample_t BatterySamples[ADC_GRP1_NUM_CHANNELS * ADC_GRP1_BUF_DEPTH];
static const ADCConversionGroup adcgrpcfg1 = {
TRUE,
ADC_GRP1_NUM_CHANNELS,
NULL,
NULL,
0, /* CR1 */
ADC_CR2_SWSTART, /* CR2 */
ADC_SMPR1_SMP_AN11(ADC_SAMPLE_112),
0, /* SMPR2 */
ADC_SQR1_NUM_CH(ADC_GRP1_NUM_CHANNELS),
0,
ADC_SQR3_SQ1_N(ADC_CHANNEL_IN11)
};
char BatteryLevel[5];//Buffer for battery test
float Pulse = 0;
char PulseBuffer[10000];
static msg_t SampleThread(void *arg) {
//Set Pad Mode's
palSetPadMode(GPIOC,15,PAL_MODE_OUTPUT_PUSHPULL);
adcStart(&ADCD1, NULL);
adcStartConversion(&ADCD1, &adcgrpcfg1, BatterySamples, ADC_GRP1_BUF_DEPTH);
gwinDrawString(GW1, 1, 1, "DaweTec Titan200");
gwinDrawString(GW1,1,15,"V 1.5");
while (TRUE) {
float BatteryVoltage = (((((adcsample_t)BatterySamples[0]*2.51)/4096)/2.51)*100);
gwinSetColor(GW1, White);
gwinFillArea(GW1,0, 50, 150, 10);
gwinSetColor(GW1, Black);
sprintf(BatteryLevel, "Battery Level: %.f %%", BatteryVoltage);
gwinDrawString(GW1,1, 50, BatteryLevel);
sprintf(PulseBuffer, "Frequency: %.f Hz", Pulse);
gwinSetColor(GW1, White);
gwinFillArea(GW1,0, 61, 150, 10);
gwinSetColor(GW1, Black);
gwinDrawString(GW1,1, 61,PulseBuffer);
palSetPad(GPIOC,15);
chThdSleepMilliseconds(500);
palClearPad(GPIOC,15);
chThdSleepMilliseconds(500);
Pulse ++;
}
return 0;
}
int main(void) {
GSourceHandle gs, gsClear, gsSet;
GEvent *pe;
GEventMouse *pem;
GEventGWinButton *peb;
coord_t swidth, sheight;
GHandle ghc, ghClear, ghSet;
font_t font;
/* initialize the hardware and the OS */
halInit();
chSysInit();
//reset lcd
palClearPad(GPIOB,1);
chThdSleepMilliseconds(50);
palSetPad(GPIOB,1);
/* initialize the LCD */
gdispInit();
gdispClear(Black);
/* Get the display dimensions */
swidth = gdispGetWidth();
sheight = gdispGetHeight();
ghClear = ghSet = 0;
/* choose our font */
font = gdispOpenFont("Larger Double");
/* Initialize the mouse */
geventListenerInit(&gl);
gs = ginputGetMouse(0);
gdispClear(Black);
font = gdispOpenFont("Larger");
GW1 = gwinCreateWindow(NULL, 20, 10, 150, 460);
GW2 = gwinCreateWindow(NULL, 200, 100, 400, 370);
gwinSetColor(GW1, Black);
gwinSetBgColor(GW1, White);
gwinSetColor(GW2, White);
gwinSetBgColor(GW2, Blue);
gwinSetFont(GW1,font);
gwinClear(GW1);
gwinClear(GW2);
/* create the "clear" button */
ghClear = gwinCreateButton(&gClear, 670, 50, 100, 50, font, GBTN_NORMAL);
gwinSetButtonText(ghClear, "Clear", FALSE);
gsClear = gwinGetButtonSource(ghClear);
geventAttachSource(&gl, gsClear, 0);
gwinAttachButtonMouse(ghClear, 0);
/* create the "set" button */
ghSet = gwinCreateButton(&gSet, 670, 105, 100, 50, font, GBTN_NORMAL);
gwinSetButtonText(ghSet, "Set", FALSE);
gsSet = gwinGetButtonSource(ghSet);
geventAttachSource(&gl, gsSet, 0);
gwinAttachButtonMouse(ghSet, 0);
/* draw the buttons */
gwinButtonDraw(ghClear);
gwinButtonDraw(ghSet);
Thread *tp = chThdCreateFromHeap(NULL, THD_WA_SIZE(650), NORMALPRIO+1,
SampleThread, NULL);
if (tp == NULL)
while(TRUE) {
pe = geventEventWait(&gl, TIME_INFINITE);
/* button pressed... */
if (pe->type == GEVENT_GWIN_BUTTON) {
peb = (GEventGWinButton *)pe;
if (peb->button == ghSet)
palSetPad(GPIOD, 12);
else if (peb->button == ghClear)
palClearPad(GPIOD, 12);
}
}
return 0;
}