Skip to content

Commit

Permalink
poprawki milivolt to volt
Browse files Browse the repository at this point in the history
  • Loading branch information
dancharles committed Nov 12, 2012
1 parent a9904c7 commit 8b80a9f
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 83 deletions.
130 changes: 64 additions & 66 deletions Apps/LCD.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 5,26 @@
#include "DMA/adc.h"
#include "string.h"

void vLCDTask(void *pvParameters)
{
void vLCDTask(void *pvParameters) {
GLCD_Initialize();
GLCD_ClearScreen();

GLCD_GoTo(0,0); GLCD_WriteString(" --Voltage Control-- ");
GLCD_GoTo(0,7); GLCD_WriteString(" ------------------- ");
while (1) {
GLCD_ClearScreen();

int i;
for(i = 0; i < ADC_Channels; i ) {
printChannelInfo(i);
}
GLCD_GoTo(0, 0);
GLCD_WriteString(" --Voltage Control-- ");
GLCD_GoTo(0, 7);
GLCD_WriteString(" ------------------- ");

int i;
for (i = 0; i < ADC_Channels; i ) {
printChannelInfo(i);
}

while(1)
{
portTickType xLastWakeTime;
const portTickType xTimeIncrement_ms = 500;
xLastWakeTime=xTaskGetTickCount();
vTaskDelayUntil(&xLastWakeTime,xTimeIncrement_ms);
xLastWakeTime = xTaskGetTickCount();
vTaskDelayUntil(&xLastWakeTime, xTimeIncrement_ms);
}
}

Expand All @@ -33,75 34,72 @@ void printChannelInfo(int channel) {
char tempBuf2[5];

// channel number
GLCD_GoTo((channel < 6) ? 6 : 12*6, channel%6 1);
itoa(channel,tempBuf);
GLCD_GoTo((channel < 6) ? 6 : 12 * 6, channel % 6 1);
itoa(channel, tempBuf);
GLCD_WriteString(tempBuf);

// voltage
GLCD_GoTo((channel < 6) ? 3*6 : 15*6, channel%6 1);
toVolt(milivolt,tempBuf2);
GLCD_GoTo((channel < 6) ? 3 * 6 : 15 * 6, channel % 6 1);
toVolt(milivolt, tempBuf2);
GLCD_WriteString(tempBuf2);

if(ADC.overTreshold[channel] == 1) {
GLCD_GoTo((channel < 6) ? 0 : 11*6, channel%6 1);
if (ADC.overTreshold[channel] == 1) {
GLCD_GoTo((channel < 6) ? 0 : 11 * 6, channel % 6 1);
GLCD_WriteString("!");
}
}

/* reverse: reverse string s in place */
void reverse(char s[])
{
int c, i, j;
void reverse(char s[]) {
int c, i, j;

for (i = 0, j = strlen(s)-1; i<j; i , j--) {
c = s[i];
s[i] = s[j];
s[j] = c;
}
for (i = 0, j = strlen(s) - 1; i < j; i , j--) {
c = s[i];
s[i] = s[j];
s[j] = c;
}
}

/* itoa: convert n to characters in s */
void itoa(int n, char s[])
{
int i;

i = 0;
do { /* generate digits in reverse order */
s[i ] = n % 10 '0'; /* get next digit */
} while ((n /= 10) > 0); /* delete it */

s[i] = '\0';
reverse(s);
}

void toVolt(int milivolt, char s[])
{
int i;
int n = milivolt;
char tmp[12];

itoa(milivolt, tmp);
reverse(tmp);

while(strlen(tmp) < 4) {
tmp[strlen(tmp)] = '0';
tmp[strlen(tmp) 1] = '\0';
}

//TODO: robić zeby działało
void itoa(int n, char s[]) {
int i;

i = 0;
do { /* generate digits in reverse order */
if(i == 3) {
s[i ] = ',';
}
if(i >= 2) {
s[i] = tmp[i]; /* get next digit */
i ;
}
} while ((n /= 10) > 0); /* delete it */
do { /* generate digits in reverse order */
s[i ] = n % 10 '0'; /* get next digit */
} while ((n /= 10) > 0); /* delete it */

s[i] = '\0';
reverse(s);
s[i] = '\0';
reverse(s);
}

void toVolt(int milivolt, char s[]) {
int i;
char tmp[5];
itoa(milivolt, tmp);
i = strlen(tmp);
if (i >= 3) {
if (i == 5) {
s[0] = tmp[0];
s[1] = tmp[1];
s[2] = '.';
s[3] = tmp[2];
s[4] = '\0';
} else if (i == 4) {
s[0] = tmp[0];
s[1] = '.';
s[2] = tmp[1];
s[3] = '\0';
} else {
s[0] = '0';
s[1] = '.';
s[2] = tmp[0];
s[3] = '\0';
}
} else {
s[0] = '0';
s[1] = '.';
s[2] = '0';
s[3] = '\0';
}
}
32 changes: 15 additions & 17 deletions Apps/checkValues.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 3,24 @@
#include "stdio.h"
#include "DMA/adc.h"

void vCheckTask(void *pvParameters)
{
NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE;
int i;
for(i = 0; i < ADC_Channels; i ) {
if(ADC.milivolt[i] > ADC.mvMaxTreshold[i]) {
ADC.overTreshold[i] = 1;
} else if(ADC.milivolt[i] < ADC.mvMinTreshold[i]) {
ADC.overTreshold[i] = 1;
} else {
ADC.overTreshold[i] = 0;
void vCheckTask(void *pvParameters) {
while (1) {
NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE;
int i;
for (i = 0; i < ADC_Channels; i ) {
if (ADC.milivolt[i] > ADC.mvMaxTreshold[i]) {
ADC.overTreshold[i] = 1;
} else if (ADC.milivolt[i] < ADC.mvMinTreshold[i]) {
ADC.overTreshold[i] = 1;
} else {
ADC.overTreshold[i] = 0;
}
}
}
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

while(1)
{
portTickType xLastWakeTime;
const portTickType xTimeIncrement_ms = 500;
xLastWakeTime=xTaskGetTickCount();
vTaskDelayUntil(&xLastWakeTime,xTimeIncrement_ms);
xLastWakeTime = xTaskGetTickCount();
vTaskDelayUntil(&xLastWakeTime, xTimeIncrement_ms);
}
}

0 comments on commit 8b80a9f

Please sign in to comment.