-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtools.c
111 lines (97 loc) · 2.29 KB
/
tools.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "tools.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <msp430x16x.h>
#include "pad.h"
void delay(int t){
int i, j;
for(i=0;i<t;++i)
for(j=0;j<i/2;++j);
}
char * chartoHex(char * c){
char text[18], result[36];
int val,i;
for(i=0;i<18;i++){
text[i]=c[i];
}
text[18]='\0';
val = (int) strtol(text, NULL, 0); // error checking omitted for brevity
sprintf(result, "%x", val);
debug_printf("%s",result);
return result;
}
void decToHex(int decimal, char * hexadecimalnum, int taille_tab){
long quotient, remainder, complethexa;
int i, j = 0;
char tab_tmp[50];
quotient = decimal;
complethexa=0;
while (quotient != 0)
{
remainder = quotient % 16;
if (remainder < 10)
hexadecimalnum[j++] = 48 + remainder;
else
hexadecimalnum[j++] = 55 + remainder;
quotient = quotient / 16;
}
j++;
debug_printf("%s\n", hexadecimalnum);
hexadecimalnum[j]='\0';
if((j-1)%4<4){
complethexa = 4-((j-1)%4);
}
for(i=j-1; i<j+(complethexa-1);i++){
hexadecimalnum[i]='0';
}
j=j+complethexa;
hexadecimalnum[j]='\0';
for(i=0; i<taille_tab; i++){
tab_tmp[i] = hexadecimalnum[i];
}
for(i=0; i<j; i++){
hexadecimalnum[i]=tab_tmp[j-(2+i)];
}
debug_printf("%s\n", hexadecimalnum);
}
int WaitPad(void){
int bs=0x1F,lbs=0x1F,pad;
//setup
//WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
//P1DIR |= 0x1F; // Set P1.0 to output direction
//P2DIR |= 0x00;
P1OUT=0x00;
pad = -1;
while(pad==-1){
bs=P2IN;
if(bs != lbs){
//si le bouton n'est pas a la position nulle
if(bs!=PAD_NULL){
//allumer toutes les leds en cliquant au centre
if(bs==PAD_CENTRE){
pad = 0;
}
//allumer la led du haut avec le bouton haut
else if(bs==PAD_HAUT){
pad = 1;
}
//allumer la led du bas
else if(bs==PAD_BAS){
pad = 2;
}
//allumer la led de gauche ...
else if(bs==PAD_GAUCHE){
pad = 3;
}
//allumer la led de droite
else if(bs==PAD_DROIT){
pad = 4;
}
}
delay(30);
}
lbs= bs;
}
return pad;
}