-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab4.cpp
107 lines (91 loc) · 2.07 KB
/
lab4.cpp
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
/*
* lab4.cpp
*
* Created on: Mar 13, 2019
* Author: Nathan Klapstein
*/
#include <predef.h>
#include <stdio.h>
#include <ctype.h>
#include <startnet.h>
#include <autoupdate.h>
#include <smarttrap.h>
#include <taskmon.h>
#include <NetworkDebug.h>
#include "Keypad.h"
#include "error_wrapper.h"
#include "Stepper.h"
#include "Stepper.h"
extern "C" {
void UserMain(void * pd);
}
const char * AppName="Nathan Klapstein, Thomas Lorincz";
Stepper myStepper;
Keypad myKeypad;
volatile int mode = 0;
/**
* Interrupt service request handler.
*
* Updates the mode by one. Acceptable modes range from 0 to 3.
*/
void EdgePortISR1(void) {
// Insert your ISR code here for exercise 3
mode = (mode + 1) % 4;
}
#define OFF_1 0
#define ON_CW_FULL 1
#define OFF_2 2
#define ON_CCW_HALF 3
/**
* Update the given stepper motor to reflect the state noted by the
* {@code mode} variable.
*/
void UpdateStepperState(Stepper *stepper){
switch(mode){
case OFF_1:
break;
case ON_CW_FULL:
stepper->SetMode(STEPPER_MODE_FULL_STEP);
stepper->SetDirection(CLOCKWISE);
break;
case OFF_2:
break;
case ON_CCW_HALF:
stepper->SetMode(STEPPER_MODE_HALF_STEP);
stepper->SetDirection(COUNTER_CLOCKWISE);
break;
default:
break;
}
}
/**
* Main execution
*/
void UserMain(void * pd) {
InitializeStack();
OSChangePrio(MAIN_PRIO);
EnableAutoUpdate();
StartHTTP();
EnableTaskMonitor();
#ifndef _DEBUG
EnableSmartTraps();
#endif
#ifdef _DEBUG
InitializeNetworkGDB_and_Wait();
#endif
// new keypad interrupt service request
myKeypad.Init(KEYPAD_INT_MODE, &EdgePortISR1);
myStepper.Init(STEPPER_MODE_FULL_STEP);
iprintf("Application started: Lab 4\n");
while (1) {
// exercise 3
printf("%d mode\n", mode); // TODO: debug
UpdateStepperState(&myStepper);
// OSTimeDly(TICKS_PER_SECOND / 20);
// only step the stepper motor on modes 1 (ON_CW_FULL) and 3 (ON_CCW_HALF)
if (mode == 1 || mode == 3) {
myStepper.Step(myStepper.GetDirection(), 2);
}
// OSTimeDly(10); // wait one tick
}
}