Fork of serial_connected_mcu by tarou yamada

Committer:
inst
Date:
Sun Jul 10 06:26:41 2016 +0000
Revision:
2:9d7a03c79cd3
Parent:
1:0ba151c701a3
Child:
4:1323ef48a984
fix bug;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
inst 0:9ca9a6eddffa 1 #include "serial_connected_mcu.hpp"
inst 0:9ca9a6eddffa 2 #include "mbed.h"
inst 0:9ca9a6eddffa 3
inst 0:9ca9a6eddffa 4 namespace serial_connected_mcu {
inst 0:9ca9a6eddffa 5
inst 0:9ca9a6eddffa 6 serial_connected_mcu* serial_connected_mcu::_instance = NULL;
inst 0:9ca9a6eddffa 7 const PinName serial_connected_mcu::_servo_pins[SERVO_NUM] = {
inst 0:9ca9a6eddffa 8 PB_6,
inst 0:9ca9a6eddffa 9 PB_7,
inst 0:9ca9a6eddffa 10 PB_8
inst 0:9ca9a6eddffa 11 };
inst 0:9ca9a6eddffa 12
inst 0:9ca9a6eddffa 13 TIM_TypeDef* serial_connected_mcu::_encoder_timers[ENCODER_NUM] = {
inst 0:9ca9a6eddffa 14 TIM1,
inst 0:9ca9a6eddffa 15 TIM2,
inst 0:9ca9a6eddffa 16 TIM3
inst 0:9ca9a6eddffa 17 };
inst 0:9ca9a6eddffa 18
inst 0:9ca9a6eddffa 19 const size_t serial_connected_mcu::_encoder_pulse_per_revol = 100;
inst 0:9ca9a6eddffa 20
inst 0:9ca9a6eddffa 21 const PinName serial_connected_mcu::_analog_input_pins[ANALOG_INPUT_NUM] = {
inst 0:9ca9a6eddffa 22 A3,
inst 0:9ca9a6eddffa 23 A4,
inst 0:9ca9a6eddffa 24 A5
inst 0:9ca9a6eddffa 25 };
inst 0:9ca9a6eddffa 26
inst 0:9ca9a6eddffa 27
inst 0:9ca9a6eddffa 28 serial_connected_mcu* serial_connected_mcu::instance() {
inst 0:9ca9a6eddffa 29 if (_instance == NULL) {
inst 0:9ca9a6eddffa 30 _instance = new serial_connected_mcu;
inst 0:9ca9a6eddffa 31 }
inst 0:9ca9a6eddffa 32 return _instance;
inst 0:9ca9a6eddffa 33 }
inst 0:9ca9a6eddffa 34
inst 0:9ca9a6eddffa 35 serial_connected_mcu::serial_connected_mcu() {
inst 0:9ca9a6eddffa 36 for (size_t i = 0; i < SERVO_NUM; ++i) {
inst 0:9ca9a6eddffa 37 _servos[i] = new servo(_servo_pins[i]);
inst 0:9ca9a6eddffa 38 }
inst 0:9ca9a6eddffa 39 for (size_t i = 0; i < ENCODER_NUM; ++i) {
inst 0:9ca9a6eddffa 40 _encoders[i] = new rotary_encoder_ab_phase(_encoder_timers[i], _encoder_pulse_per_revol);
inst 0:9ca9a6eddffa 41 }
inst 0:9ca9a6eddffa 42 for (size_t i = 0; i < SERVO_NUM; ++i) {
inst 0:9ca9a6eddffa 43 _analog_inputs[i] = new AnalogIn(_analog_input_pins[i]);
inst 0:9ca9a6eddffa 44 }
inst 0:9ca9a6eddffa 45 }
inst 0:9ca9a6eddffa 46
inst 1:0ba151c701a3 47 serial_connected_mcu::~serial_connected_mcu() {
inst 1:0ba151c701a3 48 for (size_t i = 0; i < SERVO_NUM; ++i) {
inst 1:0ba151c701a3 49 delete _servos[i];
inst 2:9d7a03c79cd3 50 }
inst 1:0ba151c701a3 51 for (size_t i = 0; i < ENCODER_NUM; ++i) {
inst 1:0ba151c701a3 52 delete _encoders[i];
inst 1:0ba151c701a3 53 }
inst 1:0ba151c701a3 54 for (size_t i = 0; i < SERVO_NUM; ++i) {
inst 1:0ba151c701a3 55 delete _analog_inputs[i];
inst 1:0ba151c701a3 56 }
inst 1:0ba151c701a3 57 }
inst 1:0ba151c701a3 58
inst 0:9ca9a6eddffa 59 void serial_connected_mcu::update() {
inst 0:9ca9a6eddffa 60
inst 0:9ca9a6eddffa 61 }
inst 0:9ca9a6eddffa 62
inst 0:9ca9a6eddffa 63 } /* namespace serial_connected_mcu */