200943373hongyun

Dependencies:   N5110 mbed

Committer:
hongyunAHN
Date:
Thu May 04 11:46:46 2017 +0000
Revision:
0:e70cf0da7c72
200943373

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hongyunAHN 0:e70cf0da7c72 1 #ifndef BACKGROUND_H
hongyunAHN 0:e70cf0da7c72 2 #define BACKGROUND_H
hongyunAHN 0:e70cf0da7c72 3
hongyunAHN 0:e70cf0da7c72 4 #include <bitset>
hongyunAHN 0:e70cf0da7c72 5
hongyunAHN 0:e70cf0da7c72 6
hongyunAHN 0:e70cf0da7c72 7 namespace mbed
hongyunAHN 0:e70cf0da7c72 8 {
hongyunAHN 0:e70cf0da7c72 9 class AnalogIn;
hongyunAHN 0:e70cf0da7c72 10 class InterruptIn;
hongyunAHN 0:e70cf0da7c72 11 class PwmOut;
hongyunAHN 0:e70cf0da7c72 12 class Timeout;
hongyunAHN 0:e70cf0da7c72 13 }
hongyunAHN 0:e70cf0da7c72 14 #define TOL 0.1f
hongyunAHN 0:e70cf0da7c72 15 #define RAD2DEG 57.2957795131f
hongyunAHN 0:e70cf0da7c72 16 enum Direction {
hongyunAHN 0:e70cf0da7c72 17 CENTRE,
hongyunAHN 0:e70cf0da7c72 18 N,
hongyunAHN 0:e70cf0da7c72 19 NE,
hongyunAHN 0:e70cf0da7c72 20 E,
hongyunAHN 0:e70cf0da7c72 21 SE,
hongyunAHN 0:e70cf0da7c72 22 S,
hongyunAHN 0:e70cf0da7c72 23 SW,
hongyunAHN 0:e70cf0da7c72 24 W,
hongyunAHN 0:e70cf0da7c72 25 NW
hongyunAHN 0:e70cf0da7c72 26 };
hongyunAHN 0:e70cf0da7c72 27
hongyunAHN 0:e70cf0da7c72 28
hongyunAHN 0:e70cf0da7c72 29 struct Vector2D {
hongyunAHN 0:e70cf0da7c72 30 float x;
hongyunAHN 0:e70cf0da7c72 31 float y;
hongyunAHN 0:e70cf0da7c72 32 };
hongyunAHN 0:e70cf0da7c72 33
hongyunAHN 0:e70cf0da7c72 34
hongyunAHN 0:e70cf0da7c72 35 struct Polar {
hongyunAHN 0:e70cf0da7c72 36 float mag;
hongyunAHN 0:e70cf0da7c72 37 float angle;
hongyunAHN 0:e70cf0da7c72 38 };
hongyunAHN 0:e70cf0da7c72 39
hongyunAHN 0:e70cf0da7c72 40
hongyunAHN 0:e70cf0da7c72 41 class Background
hongyunAHN 0:e70cf0da7c72 42 {
hongyunAHN 0:e70cf0da7c72 43 public:
hongyunAHN 0:e70cf0da7c72 44
hongyunAHN 0:e70cf0da7c72 45 enum BackgroundEvent {
hongyunAHN 0:e70cf0da7c72 46 A_PRESSED,
hongyunAHN 0:e70cf0da7c72 47 B_PRESSED,
hongyunAHN 0:e70cf0da7c72 48 X_PRESSED,
hongyunAHN 0:e70cf0da7c72 49 Y_PRESSED,
hongyunAHN 0:e70cf0da7c72 50 L_PRESSED,
hongyunAHN 0:e70cf0da7c72 51 R_PRESSED,
hongyunAHN 0:e70cf0da7c72 52 BACK_PRESSED,
hongyunAHN 0:e70cf0da7c72 53 START_PRESSED,
hongyunAHN 0:e70cf0da7c72 54 JOY_PRESSED,
hongyunAHN 0:e70cf0da7c72 55 N_EVENTS
hongyunAHN 0:e70cf0da7c72 56 };
hongyunAHN 0:e70cf0da7c72 57 private:
hongyunAHN 0:e70cf0da7c72 58 mbed::PwmOut *_led1;
hongyunAHN 0:e70cf0da7c72 59 mbed::PwmOut *_led2;
hongyunAHN 0:e70cf0da7c72 60 mbed::PwmOut *_led3;
hongyunAHN 0:e70cf0da7c72 61 mbed::PwmOut *_led4;
hongyunAHN 0:e70cf0da7c72 62 mbed::PwmOut *_led5;
hongyunAHN 0:e70cf0da7c72 63 mbed::PwmOut *_led6;
hongyunAHN 0:e70cf0da7c72 64
hongyunAHN 0:e70cf0da7c72 65 mbed::InterruptIn *_button_A;
hongyunAHN 0:e70cf0da7c72 66 mbed::InterruptIn *_button_B;
hongyunAHN 0:e70cf0da7c72 67 mbed::InterruptIn *_button_X;
hongyunAHN 0:e70cf0da7c72 68 mbed::InterruptIn *_button_Y;
hongyunAHN 0:e70cf0da7c72 69 mbed::InterruptIn *_button_L;
hongyunAHN 0:e70cf0da7c72 70 mbed::InterruptIn *_button_R;
hongyunAHN 0:e70cf0da7c72 71 mbed::InterruptIn *_button_back;
hongyunAHN 0:e70cf0da7c72 72 mbed::InterruptIn *_button_start;
hongyunAHN 0:e70cf0da7c72 73 mbed::InterruptIn *_button_joystick;
hongyunAHN 0:e70cf0da7c72 74
hongyunAHN 0:e70cf0da7c72 75 mbed::AnalogIn *_vert;
hongyunAHN 0:e70cf0da7c72 76 mbed::AnalogIn *_horiz;
hongyunAHN 0:e70cf0da7c72 77
hongyunAHN 0:e70cf0da7c72 78 mbed::PwmOut *_buzzer;
hongyunAHN 0:e70cf0da7c72 79 mbed::AnalogIn *_pot;
hongyunAHN 0:e70cf0da7c72 80
hongyunAHN 0:e70cf0da7c72 81 mbed::Timeout *_timeout;
hongyunAHN 0:e70cf0da7c72 82
hongyunAHN 0:e70cf0da7c72 83 std::bitset<N_EVENTS> _event_state;
hongyunAHN 0:e70cf0da7c72 84
hongyunAHN 0:e70cf0da7c72 85
hongyunAHN 0:e70cf0da7c72 86 float _x0;
hongyunAHN 0:e70cf0da7c72 87 float _y0;
hongyunAHN 0:e70cf0da7c72 88
hongyunAHN 0:e70cf0da7c72 89 public:
hongyunAHN 0:e70cf0da7c72 90
hongyunAHN 0:e70cf0da7c72 91
hongyunAHN 0:e70cf0da7c72 92 Background();
hongyunAHN 0:e70cf0da7c72 93
hongyunAHN 0:e70cf0da7c72 94
hongyunAHN 0:e70cf0da7c72 95 ~Background();
hongyunAHN 0:e70cf0da7c72 96
hongyunAHN 0:e70cf0da7c72 97
hongyunAHN 0:e70cf0da7c72 98 void init();
hongyunAHN 0:e70cf0da7c72 99
hongyunAHN 0:e70cf0da7c72 100
hongyunAHN 0:e70cf0da7c72 101 void leds_on();
hongyunAHN 0:e70cf0da7c72 102
hongyunAHN 0:e70cf0da7c72 103
hongyunAHN 0:e70cf0da7c72 104 void leds_off();
hongyunAHN 0:e70cf0da7c72 105
hongyunAHN 0:e70cf0da7c72 106
hongyunAHN 0:e70cf0da7c72 107 void leds(float val) const;
hongyunAHN 0:e70cf0da7c72 108
hongyunAHN 0:e70cf0da7c72 109
hongyunAHN 0:e70cf0da7c72 110 void led(int n,float val) const;
hongyunAHN 0:e70cf0da7c72 111
hongyunAHN 0:e70cf0da7c72 112
hongyunAHN 0:e70cf0da7c72 113 float read_pot() const;
hongyunAHN 0:e70cf0da7c72 114
hongyunAHN 0:e70cf0da7c72 115
hongyunAHN 0:e70cf0da7c72 116 void tone(float frequency, float duration);
hongyunAHN 0:e70cf0da7c72 117
hongyunAHN 0:e70cf0da7c72 118
hongyunAHN 0:e70cf0da7c72 119 bool check_event(BackgroundEvent const id);
hongyunAHN 0:e70cf0da7c72 120
hongyunAHN 0:e70cf0da7c72 121
hongyunAHN 0:e70cf0da7c72 122 float get_mag();
hongyunAHN 0:e70cf0da7c72 123
hongyunAHN 0:e70cf0da7c72 124
hongyunAHN 0:e70cf0da7c72 125 float get_angle();
hongyunAHN 0:e70cf0da7c72 126
hongyunAHN 0:e70cf0da7c72 127
hongyunAHN 0:e70cf0da7c72 128 Direction get_direction();
hongyunAHN 0:e70cf0da7c72 129
hongyunAHN 0:e70cf0da7c72 130
hongyunAHN 0:e70cf0da7c72 131 Vector2D get_coord();
hongyunAHN 0:e70cf0da7c72 132
hongyunAHN 0:e70cf0da7c72 133
hongyunAHN 0:e70cf0da7c72 134 Vector2D get_mapped_coord();
hongyunAHN 0:e70cf0da7c72 135
hongyunAHN 0:e70cf0da7c72 136
hongyunAHN 0:e70cf0da7c72 137 Polar get_polar();
hongyunAHN 0:e70cf0da7c72 138
hongyunAHN 0:e70cf0da7c72 139 private:
hongyunAHN 0:e70cf0da7c72 140 void init_buttons();
hongyunAHN 0:e70cf0da7c72 141 void tone_off();
hongyunAHN 0:e70cf0da7c72 142
hongyunAHN 0:e70cf0da7c72 143 void a_isr();
hongyunAHN 0:e70cf0da7c72 144 void b_isr();
hongyunAHN 0:e70cf0da7c72 145 void x_isr();
hongyunAHN 0:e70cf0da7c72 146 void y_isr();
hongyunAHN 0:e70cf0da7c72 147 void l_isr();
hongyunAHN 0:e70cf0da7c72 148 void r_isr();
hongyunAHN 0:e70cf0da7c72 149 void back_isr();
hongyunAHN 0:e70cf0da7c72 150 void start_isr();
hongyunAHN 0:e70cf0da7c72 151 void joy_isr();
hongyunAHN 0:e70cf0da7c72 152 };
hongyunAHN 0:e70cf0da7c72 153
hongyunAHN 0:e70cf0da7c72 154 #endif