Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Lab3 by
Revision 11:3cc46e37f97f, committed 2016-12-02
- Comitter:
- Dorsh
- Date:
- Fri Dec 02 18:15:45 2016 +0000
- Parent:
- 10:337f8b757d8d
- Commit message:
- ye
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Nov 28 17:47:24 2016 +0000
+++ b/main.cpp Fri Dec 02 18:15:45 2016 +0000
@@ -21,13 +21,12 @@
* read messages, the keypad subsystem is complete
*/
-void createMessage(char* msg); //Creates message based off Keytable[Index] press
+char createMessage(); //Creates message based off Keytable[Index] press
void send(char* msg); //Takes the created message and sends to the CAN Bus
//DigitalOut myled(LED1);
CAN can2(p30,p29);
CAN can1(p9,p10);
-const int msgLength = 8; //Length of message sent to CAN Bus
char Keytable[] = { '1', '2', '3', // r0
'4', '5', '6', // r1
'7', '8', '9', // r2
@@ -51,13 +50,13 @@
keypad.attach(&cbAfterInput);
keypad.start(); // energize the keypad via c0-c3
- char msg[msgLength];//initialize to something 8 characters
+ char msg = 'z';
CANMessage recievedMessage;
while (1) {
__wfi(); //waits for input
printf("Interrupted\r\n");
wait(0.5);
- send(msg);
+ send(&msg);
printf("Index:%d => Key:%c\r\n", Index, Keytable[Index]);
if(can2.read(recievedMessage)) {
printf("Message received: %s\n", recievedMessage.data);
@@ -67,15 +66,15 @@
void send(char *str) {
- createMessage(str);
- printf("send(%s)\n",str);
- if(can1.write(CANMessage(1337, str, msgLength))) {
+ *str = createMessage();
+ printf("send(%c)\n",str[0]);
+ if(can1.write(CANMessage(1337, str, 1))) {
printf("wrote successfully\n");
}
}
//Returns a specific message to be sent to the CAN Bus
-void createMessage(char msg[]) {
+char createMessage() {
char key = Keytable[Index];
static int subsys = 0; //0 = DAC, 1 = DigiPot, 2 = ADC
@@ -87,9 +86,6 @@
if(key == '#') {
subsys = (subsys + 1) % (numOfSubsys); //cycles from 0,1,2,0,1,2,etc
printf("Now working with Subsystem %s\n", sysName[subsys]);
- memset(msg, '\0', sizeof(msg));
- strcpy(msg,"switch");
- printf("this is the solution\n");
}
//Handles all message creation
@@ -99,23 +95,37 @@
else {
switch(subsys) {
case 0:
- if(key == '*')
- strcpy(msg, "D_");
+ if(key == '2')
+ return 'a';
else if(key == '1')
- strcpy(msg, "D_");
+ return 'b';
+ else if(key == '3')
+ return 'c';
+ else if(key == '4')
+ return 'd';
+ else if(key == '5')
+ return 'e';
+ else if(key == '6')
+ return 'f';
break;
case 1:
- if(key == '*')
- strcpy(msg, "DACswitc");
- else if(key == '1')
- strcpy(msg, "DACswitc");
+ if(key == '1')
+ return '1';
+ else if(key == '2')
+ return '2';
+ else if(key == '3')
+ return '3';
+ else if(key == '4')
+ return '4';
+ else if(key == '5')
+ return '5';
break;
case 2:
if(key == '*')
- strcpy(msg, "A_switch");
+ return 'A';
break;
default:
- strcpy(msg, "null"); //no message
+ return '0';
break;
}
