Blank program for v0.9 API
Dependencies: PsiSwarmV9 mbed
Fork of PsiSwarm_V8_Blank_CPP by
main.cpp@4:3af6e6afbfef, 2017-06-05 (annotated)
- Committer:
- jah128
- Date:
- Mon Jun 05 22:47:38 2017 +0000
- Revision:
- 4:3af6e6afbfef
- Parent:
- 3:53cc107bcff1
Fixed animation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jah128 | 0:9c0ccd879613 | 1 | /*********************************************************************** |
jah128 | 0:9c0ccd879613 | 2 | ** ██████╗ ███████╗██╗███████╗██╗ ██╗ █████╗ ██████╗ ███╗ ███╗ ** |
jah128 | 0:9c0ccd879613 | 3 | ** ██╔══██╗██╔════╝██║██╔════╝██║ ██║██╔══██╗██╔══██╗████╗ ████║ ** |
jah128 | 0:9c0ccd879613 | 4 | ** ██████╔╝███████╗██║███████╗██║ █╗ ██║███████║██████╔╝██╔████╔██║ ** |
jah128 | 0:9c0ccd879613 | 5 | ** ██╔═══╝ ╚════██║██║╚════██║██║███╗██║██╔══██║██╔══██╗██║╚██╔╝██║ ** |
jah128 | 0:9c0ccd879613 | 6 | ** ██║ ███████║██║███████║╚███╔███╔╝██║ ██║██║ ██║██║ ╚═╝ ██║ ** |
jah128 | 0:9c0ccd879613 | 7 | ** ╚═╝ ╚══════╝╚═╝╚══════╝ ╚══╝╚══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ** |
jah128 | 0:9c0ccd879613 | 8 | ************************************************************************ |
jah128 | 3:53cc107bcff1 | 9 | ** Copyright 2017 University of York - See notice at end of file ** |
jah128 | 0:9c0ccd879613 | 10 | ***********************************************************************/ |
jah128 | 0:9c0ccd879613 | 11 | |
jah128 | 3:53cc107bcff1 | 12 | /// PsiSwarm C++ Blank Example Code - Version 0.9 - June 2017 |
jah128 | 0:9c0ccd879613 | 13 | /// James Hilder, Alan Millard, Alexander Horsfield, Homero Elizondo, Jon Timmis |
jah128 | 0:9c0ccd879613 | 14 | |
jah128 | 0:9c0ccd879613 | 15 | /// Include main.h - this includes psiswarm.h all the other necessary core files |
jah128 | 0:9c0ccd879613 | 16 | #include "main.h" |
jah128 | 0:9c0ccd879613 | 17 | |
jah128 | 2:5d37e5fd7141 | 18 | Psiswarm psi; |
jah128 | 2:5d37e5fd7141 | 19 | |
jah128 | 0:9c0ccd879613 | 20 | char * program_name = "Blank"; |
jah128 | 0:9c0ccd879613 | 21 | char * author_name = "YRL"; |
jah128 | 3:53cc107bcff1 | 22 | char * version_name = "0.90"; |
jah128 | 3:53cc107bcff1 | 23 | |
jah128 | 3:53cc107bcff1 | 24 | ///Place user code here that should be run after initialisation but before the main loop |
jah128 | 3:53cc107bcff1 | 25 | void user_code_setup() |
jah128 | 3:53cc107bcff1 | 26 | { |
jah128 | 3:53cc107bcff1 | 27 | wait(0.8); // The display is still updating from init so wait a short while |
jah128 | 3:53cc107bcff1 | 28 | display.clear_display(); |
jah128 | 3:53cc107bcff1 | 29 | display.set_position(0,0); |
jah128 | 4:3af6e6afbfef | 30 | animations.set_colour(1); |
jah128 | 4:3af6e6afbfef | 31 | display.write_string(" [ No Code ]"); |
jah128 | 3:53cc107bcff1 | 32 | } |
jah128 | 0:9c0ccd879613 | 33 | |
jah128 | 2:5d37e5fd7141 | 34 | ///User code loop: This is where user code should go; it is run as an infinite loop |
jah128 | 0:9c0ccd879613 | 35 | void user_code_loop() |
jah128 | 0:9c0ccd879613 | 36 | { |
jah128 | 3:53cc107bcff1 | 37 | // Replace this code with your main loop |
jah128 | 3:53cc107bcff1 | 38 | animations.led_run1(); |
jah128 | 3:53cc107bcff1 | 39 | wait(1.2); |
jah128 | 0:9c0ccd879613 | 40 | } |
jah128 | 0:9c0ccd879613 | 41 | |
jah128 | 0:9c0ccd879613 | 42 | /// Code goes here to handle what should happen when the user switch is pressed |
jah128 | 0:9c0ccd879613 | 43 | void handle_switch_event(char switch_state) |
jah128 | 0:9c0ccd879613 | 44 | { |
jah128 | 0:9c0ccd879613 | 45 | /// Switch_state = 1 if up is pressed, 2 if down is pressed, 4 if left is pressed, 8 if right is pressed and 16 if the center button is pressed |
jah128 | 0:9c0ccd879613 | 46 | /// NB For maximum compatability it is recommended to minimise reliance on center button press |
jah128 | 0:9c0ccd879613 | 47 | } |
jah128 | 0:9c0ccd879613 | 48 | |
jah128 | 0:9c0ccd879613 | 49 | void handle_user_serial_message(char * message, char length, char interface) |
jah128 | 0:9c0ccd879613 | 50 | { |
jah128 | 0:9c0ccd879613 | 51 | // This is where user code for handling a (non-system) serial message should go |
jah128 | 0:9c0ccd879613 | 52 | // |
jah128 | 0:9c0ccd879613 | 53 | // message = pointer to message char array |
jah128 | 0:9c0ccd879613 | 54 | // length = length of message |
jah128 | 0:9c0ccd879613 | 55 | // interface = 0 for PC serial connection, 1 for Bluetooth |
jah128 | 0:9c0ccd879613 | 56 | } |
jah128 | 0:9c0ccd879613 | 57 | |
jah128 | 0:9c0ccd879613 | 58 | /// The main routine: it is recommended to leave this function alone and add user code to the above functions |
jah128 | 0:9c0ccd879613 | 59 | int main() |
jah128 | 0:9c0ccd879613 | 60 | { |
jah128 | 2:5d37e5fd7141 | 61 | psi.init(); ///psi.init() in psiswarm.cpp sets up the robot |
jah128 | 2:5d37e5fd7141 | 62 | user_code_setup(); ///run user code setup block |
jah128 | 2:5d37e5fd7141 | 63 | user_code_running = 1; ///nb. user code can be paused by external commands sent from PC\BT interfaces |
jah128 | 0:9c0ccd879613 | 64 | while(1) { |
jah128 | 4:3af6e6afbfef | 65 | if(user_code_running == 1) user_code_loop(); ///run user code |
jah128 | 4:3af6e6afbfef | 66 | else wait_us(1000); |
jah128 | 0:9c0ccd879613 | 67 | } |
jah128 | 2:5d37e5fd7141 | 68 | } |
jah128 | 2:5d37e5fd7141 | 69 | |
jah128 | 2:5d37e5fd7141 | 70 | |
jah128 | 2:5d37e5fd7141 | 71 | /*********************************************************************** |
jah128 | 3:53cc107bcff1 | 72 | ** Copyright 2017 University of York ** |
jah128 | 2:5d37e5fd7141 | 73 | ** ** |
jah128 | 2:5d37e5fd7141 | 74 | ** Licensed under the Apache License, Version 2.0 (the "License") ** |
jah128 | 2:5d37e5fd7141 | 75 | ** You may not use this file except in compliance with the License. ** |
jah128 | 2:5d37e5fd7141 | 76 | ** You may obtain a copy of the License at ** |
jah128 | 2:5d37e5fd7141 | 77 | ** http://www.apache.org/licenses/LICENSE-2.0 Unless required by ** |
jah128 | 2:5d37e5fd7141 | 78 | ** applicable law or agreed to in writing, software distributed under ** |
jah128 | 3:53cc107bcff1 | 79 | ** under the License is distributed on an "AS IS" BASIS WITHOUT ** |
jah128 | 3:53cc107bcff1 | 80 | ** WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** |
jah128 | 3:53cc107bcff1 | 81 | ** See the License for the specific language governing permissions ** |
jah128 | 2:5d37e5fd7141 | 82 | ** and limitations under the License. ** |
jah128 | 2:5d37e5fd7141 | 83 | ***********************************************************************/ |