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 OmniWheels by
Main.cpp@2:798925c9e4a8, 2018-05-01 (annotated)
- Committer:
- gustavatmel
- Date:
- Tue May 01 15:55:34 2018 +0000
- Revision:
- 2:798925c9e4a8
- Parent:
- 1:9c5af431a1f1
bluetooth
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gustavatmel | 0:d698f15ceaf1 | 1 | /* |
gustavatmel | 0:d698f15ceaf1 | 2 | * Main.cpp |
gustavatmel | 0:d698f15ceaf1 | 3 | * Copyright (c) 2017, ZHAW |
gustavatmel | 0:d698f15ceaf1 | 4 | * All rights reserved. |
gustavatmel | 0:d698f15ceaf1 | 5 | * |
gustavatmel | 0:d698f15ceaf1 | 6 | * Created on: 06.10.2017 |
gustavatmel | 0:d698f15ceaf1 | 7 | * Author: Marcel Honegger |
gustavatmel | 0:d698f15ceaf1 | 8 | */ |
gustavatmel | 2:798925c9e4a8 | 9 | #include "SerialCom.h" |
gustavatmel | 0:d698f15ceaf1 | 10 | #include <cstdlib> |
gustavatmel | 0:d698f15ceaf1 | 11 | #include <mbed.h> |
gustavatmel | 1:9c5af431a1f1 | 12 | |
gustavatmel | 1:9c5af431a1f1 | 13 | |
gustavatmel | 1:9c5af431a1f1 | 14 | |
gustavatmel | 1:9c5af431a1f1 | 15 | |
gustavatmel | 0:d698f15ceaf1 | 16 | |
gustavatmel | 0:d698f15ceaf1 | 17 | using namespace std; |
gustavatmel | 0:d698f15ceaf1 | 18 | |
gustavatmel | 0:d698f15ceaf1 | 19 | class Main { |
gustavatmel | 0:d698f15ceaf1 | 20 | |
gustavatmel | 0:d698f15ceaf1 | 21 | public: |
gustavatmel | 0:d698f15ceaf1 | 22 | |
gustavatmel | 0:d698f15ceaf1 | 23 | Main(); |
gustavatmel | 0:d698f15ceaf1 | 24 | virtual ~Main(); |
gustavatmel | 0:d698f15ceaf1 | 25 | |
gustavatmel | 0:d698f15ceaf1 | 26 | private: |
gustavatmel | 0:d698f15ceaf1 | 27 | |
gustavatmel | 0:d698f15ceaf1 | 28 | static const uint32_t STACK_SIZE = 8192; // stack size of thread, given in [bytes] |
gustavatmel | 0:d698f15ceaf1 | 29 | |
gustavatmel | 0:d698f15ceaf1 | 30 | Thread thread; |
gustavatmel | 0:d698f15ceaf1 | 31 | void run(); |
gustavatmel | 0:d698f15ceaf1 | 32 | }; |
gustavatmel | 0:d698f15ceaf1 | 33 | |
gustavatmel | 0:d698f15ceaf1 | 34 | Main::Main() : thread(osPriorityNormal, STACK_SIZE) { |
gustavatmel | 0:d698f15ceaf1 | 35 | |
gustavatmel | 0:d698f15ceaf1 | 36 | thread.start(callback(this, &Main::run)); |
gustavatmel | 0:d698f15ceaf1 | 37 | } |
gustavatmel | 0:d698f15ceaf1 | 38 | |
gustavatmel | 0:d698f15ceaf1 | 39 | Main::~Main() {} |
gustavatmel | 0:d698f15ceaf1 | 40 | |
gustavatmel | 0:d698f15ceaf1 | 41 | void Main::run() { |
gustavatmel | 0:d698f15ceaf1 | 42 | |
gustavatmel | 0:d698f15ceaf1 | 43 | // create miscellaneous periphery objects |
gustavatmel | 0:d698f15ceaf1 | 44 | |
gustavatmel | 0:d698f15ceaf1 | 45 | DigitalOut led(LED1); |
gustavatmel | 0:d698f15ceaf1 | 46 | DigitalIn button(USER_BUTTON); |
gustavatmel | 0:d698f15ceaf1 | 47 | |
gustavatmel | 1:9c5af431a1f1 | 48 | // create serial server object |
gustavatmel | 1:9c5af431a1f1 | 49 | |
gustavatmel | 0:d698f15ceaf1 | 50 | |
gustavatmel | 0:d698f15ceaf1 | 51 | |
gustavatmel | 1:9c5af431a1f1 | 52 | RawSerial serial(PA_0, PA_1); |
gustavatmel | 0:d698f15ceaf1 | 53 | serial.baud(38400); |
gustavatmel | 0:d698f15ceaf1 | 54 | serial.format(8, SerialBase::None, 1); |
gustavatmel | 0:d698f15ceaf1 | 55 | |
gustavatmel | 0:d698f15ceaf1 | 56 | DigitalOut reset(PB_12); |
gustavatmel | 0:d698f15ceaf1 | 57 | DigitalOut modes1(PB_0); |
gustavatmel | 0:d698f15ceaf1 | 58 | |
gustavatmel | 0:d698f15ceaf1 | 59 | modes1 = 0; |
gustavatmel | 0:d698f15ceaf1 | 60 | |
gustavatmel | 0:d698f15ceaf1 | 61 | reset = 1; Thread::wait(100); |
gustavatmel | 0:d698f15ceaf1 | 62 | reset = 0; Thread::wait(100); |
gustavatmel | 0:d698f15ceaf1 | 63 | reset = 1; Thread::wait(100); |
gustavatmel | 0:d698f15ceaf1 | 64 | |
gustavatmel | 2:798925c9e4a8 | 65 | SerialCom serialCom(serial); |
gustavatmel | 0:d698f15ceaf1 | 66 | |
gustavatmel | 0:d698f15ceaf1 | 67 | // enter main loop |
gustavatmel | 0:d698f15ceaf1 | 68 | |
gustavatmel | 0:d698f15ceaf1 | 69 | while (true) { |
gustavatmel | 0:d698f15ceaf1 | 70 | |
gustavatmel | 0:d698f15ceaf1 | 71 | led = !led; |
gustavatmel | 1:9c5af431a1f1 | 72 | /* |
gustavatmel | 1:9c5af431a1f1 | 73 | if (//stateMachine.getState() == StateMachine::STATE_MANUAL) { |
gustavatmel | 0:d698f15ceaf1 | 74 | Thread::wait(100); |
gustavatmel | 1:9c5af431a1f1 | 75 | } else if (//stateMachine.getState() == StateMachine::STATE_AUTOMATIC) { |
gustavatmel | 0:d698f15ceaf1 | 76 | Thread::wait(200); |
gustavatmel | 0:d698f15ceaf1 | 77 | } else { |
gustavatmel | 0:d698f15ceaf1 | 78 | Thread::wait(500); |
gustavatmel | 0:d698f15ceaf1 | 79 | } |
gustavatmel | 1:9c5af431a1f1 | 80 | */ |
gustavatmel | 0:d698f15ceaf1 | 81 | } |
gustavatmel | 0:d698f15ceaf1 | 82 | } |
gustavatmel | 0:d698f15ceaf1 | 83 | |
gustavatmel | 0:d698f15ceaf1 | 84 | /** |
gustavatmel | 0:d698f15ceaf1 | 85 | * This is the main program of the ROME2RevG firmware. |
gustavatmel | 0:d698f15ceaf1 | 86 | */ |
gustavatmel | 0:d698f15ceaf1 | 87 | int32_t main() { |
gustavatmel | 0:d698f15ceaf1 | 88 | |
gustavatmel | 1:9c5af431a1f1 | 89 | /* Serial pc(USBTX, USBRX); // tx, rx |
gustavatmel | 1:9c5af431a1f1 | 90 | pc.baud(9600); |
gustavatmel | 1:9c5af431a1f1 | 91 | pc.printf("was here\r\n");*/ |
gustavatmel | 1:9c5af431a1f1 | 92 | |
gustavatmel | 0:d698f15ceaf1 | 93 | Main main; |
gustavatmel | 0:d698f15ceaf1 | 94 | |
gustavatmel | 0:d698f15ceaf1 | 95 | Thread::wait(osWaitForever); |
gustavatmel | 0:d698f15ceaf1 | 96 | } |