GHI Electronics
/
Official_USBPrank
The preloaded firmware shipped on the USB Prank.
main.cpp@1:2449ac218b24, 2014-09-15 (annotated)
- Committer:
- Experiment626
- Date:
- Mon Sep 15 16:05:40 2014 +0000
- Revision:
- 1:2449ac218b24
- Parent:
- 0:01e3d602e31f
Added Apache 2 license text
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Experiment626 | 1:2449ac218b24 | 1 | /* |
Experiment626 | 1:2449ac218b24 | 2 | ** This software can be freely used, even comercially, as highlighted in the license. |
Experiment626 | 1:2449ac218b24 | 3 | ** |
Experiment626 | 1:2449ac218b24 | 4 | ** Copyright 2014 GHI Electronics, LLC |
Experiment626 | 1:2449ac218b24 | 5 | ** |
Experiment626 | 1:2449ac218b24 | 6 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
Experiment626 | 1:2449ac218b24 | 7 | ** you may not use this file except in compliance with the License. |
Experiment626 | 1:2449ac218b24 | 8 | ** You may obtain a copy of the License at |
Experiment626 | 1:2449ac218b24 | 9 | ** |
Experiment626 | 1:2449ac218b24 | 10 | ** http://www.apache.org/licenses/LICENSE-2.0 |
Experiment626 | 1:2449ac218b24 | 11 | ** |
Experiment626 | 1:2449ac218b24 | 12 | ** Unless required by applicable law or agreed to in writing, software |
Experiment626 | 1:2449ac218b24 | 13 | ** distributed under the License is distributed on an "AS IS" BASIS, |
Experiment626 | 1:2449ac218b24 | 14 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Experiment626 | 1:2449ac218b24 | 15 | ** See the License for the specific language governing permissions and |
Experiment626 | 1:2449ac218b24 | 16 | ** limitations under the License. |
Experiment626 | 1:2449ac218b24 | 17 | ** |
Experiment626 | 1:2449ac218b24 | 18 | **/ |
Experiment626 | 1:2449ac218b24 | 19 | |
Experiment626 | 0:01e3d602e31f | 20 | #include "mbed.h" |
Experiment626 | 0:01e3d602e31f | 21 | #include "USBMouse.h" |
Experiment626 | 0:01e3d602e31f | 22 | #include <stdlib.h> |
Experiment626 | 0:01e3d602e31f | 23 | #include <math.h> |
Experiment626 | 0:01e3d602e31f | 24 | |
Experiment626 | 0:01e3d602e31f | 25 | #define DELAY_TO_NEXT_RADIUS (rand() % 5 + 1) |
Experiment626 | 0:01e3d602e31f | 26 | #define DELAY_TO_RESTART (rand() % 30 + 1) |
Experiment626 | 0:01e3d602e31f | 27 | |
Experiment626 | 0:01e3d602e31f | 28 | USBMouse mouse; |
Experiment626 | 0:01e3d602e31f | 29 | |
Experiment626 | 0:01e3d602e31f | 30 | main() |
Experiment626 | 0:01e3d602e31f | 31 | { |
Experiment626 | 0:01e3d602e31f | 32 | static const float DELAY_TO_START = 25.0; |
Experiment626 | 0:01e3d602e31f | 33 | float DELAY_TO_NEXT_POINT = 0.001; |
Experiment626 | 0:01e3d602e31f | 34 | static const int16_t RADIUS_INC = 2; |
Experiment626 | 0:01e3d602e31f | 35 | static const int16_t ANGLE_INC = 2; |
Experiment626 | 0:01e3d602e31f | 36 | static const int8_t NUM_CIRCLE_SIZES = 4; |
Experiment626 | 0:01e3d602e31f | 37 | |
Experiment626 | 0:01e3d602e31f | 38 | int16_t x = 0; |
Experiment626 | 0:01e3d602e31f | 39 | int16_t y = 0; |
Experiment626 | 0:01e3d602e31f | 40 | int16_t angle = 0; |
Experiment626 | 0:01e3d602e31f | 41 | int16_t radius = 5; // if radius is too large, OS dependent, Windows 8 it isn't visible |
Experiment626 | 0:01e3d602e31f | 42 | int16_t recenter_radius_correction = 0; |
Experiment626 | 0:01e3d602e31f | 43 | |
Experiment626 | 0:01e3d602e31f | 44 | |
Experiment626 | 0:01e3d602e31f | 45 | int8_t circle_count; |
Experiment626 | 0:01e3d602e31f | 46 | |
Experiment626 | 0:01e3d602e31f | 47 | int nextPointFrequency; |
Experiment626 | 0:01e3d602e31f | 48 | |
Experiment626 | 0:01e3d602e31f | 49 | // Start-up Code |
Experiment626 | 0:01e3d602e31f | 50 | for (circle_count = 1; circle_count <= 5; circle_count++) |
Experiment626 | 0:01e3d602e31f | 51 | { |
Experiment626 | 0:01e3d602e31f | 52 | while (angle <= 360) |
Experiment626 | 0:01e3d602e31f | 53 | { |
Experiment626 | 0:01e3d602e31f | 54 | x = cos((double)angle*3.14/180.0)*5; |
Experiment626 | 0:01e3d602e31f | 55 | y = sin((double)angle*3.14/180.0)*5; |
Experiment626 | 0:01e3d602e31f | 56 | mouse.move(x, y); |
Experiment626 | 0:01e3d602e31f | 57 | angle += ANGLE_INC; |
Experiment626 | 0:01e3d602e31f | 58 | wait(.001); |
Experiment626 | 0:01e3d602e31f | 59 | } // draw circle |
Experiment626 | 0:01e3d602e31f | 60 | |
Experiment626 | 0:01e3d602e31f | 61 | wait(.25); |
Experiment626 | 0:01e3d602e31f | 62 | x = y = angle = 0; |
Experiment626 | 0:01e3d602e31f | 63 | } // end circle_count |
Experiment626 | 0:01e3d602e31f | 64 | |
Experiment626 | 0:01e3d602e31f | 65 | wait(DELAY_TO_START); |
Experiment626 | 0:01e3d602e31f | 66 | |
Experiment626 | 0:01e3d602e31f | 67 | while (true) |
Experiment626 | 0:01e3d602e31f | 68 | { |
Experiment626 | 0:01e3d602e31f | 69 | for (circle_count = 1; circle_count <= NUM_CIRCLE_SIZES; circle_count++) |
Experiment626 | 0:01e3d602e31f | 70 | { |
Experiment626 | 0:01e3d602e31f | 71 | while (angle <= 360) |
Experiment626 | 0:01e3d602e31f | 72 | { |
Experiment626 | 0:01e3d602e31f | 73 | x = cos((double)angle*3.14/180.0)*radius; |
Experiment626 | 0:01e3d602e31f | 74 | y = sin((double)angle*3.14/180.0)*radius; |
Experiment626 | 0:01e3d602e31f | 75 | mouse.move(x, y); |
Experiment626 | 0:01e3d602e31f | 76 | recenter_radius_correction -= x; |
Experiment626 | 0:01e3d602e31f | 77 | angle += ANGLE_INC; |
Experiment626 | 0:01e3d602e31f | 78 | wait(DELAY_TO_NEXT_POINT); |
Experiment626 | 0:01e3d602e31f | 79 | } // draw circle |
Experiment626 | 0:01e3d602e31f | 80 | |
Experiment626 | 0:01e3d602e31f | 81 | nextPointFrequency = rand() % 1000 + 1; |
Experiment626 | 0:01e3d602e31f | 82 | |
Experiment626 | 0:01e3d602e31f | 83 | if(nextPointFrequency < 100) |
Experiment626 | 0:01e3d602e31f | 84 | nextPointFrequency = 100; |
Experiment626 | 0:01e3d602e31f | 85 | |
Experiment626 | 0:01e3d602e31f | 86 | DELAY_TO_NEXT_POINT = 1/(float)nextPointFrequency; |
Experiment626 | 0:01e3d602e31f | 87 | |
Experiment626 | 0:01e3d602e31f | 88 | wait(DELAY_TO_NEXT_RADIUS); |
Experiment626 | 0:01e3d602e31f | 89 | x = y = angle = 0; |
Experiment626 | 0:01e3d602e31f | 90 | radius += RADIUS_INC; |
Experiment626 | 0:01e3d602e31f | 91 | // FIX: Change ANGLE_INCREMENT and DELAY_TO_NEXT_POINT so circle drawn relative resolution and time |
Experiment626 | 0:01e3d602e31f | 92 | mouse.move(recenter_radius_correction,0); |
Experiment626 | 0:01e3d602e31f | 93 | recenter_radius_correction = 0; |
Experiment626 | 0:01e3d602e31f | 94 | } // end circle_count |
Experiment626 | 0:01e3d602e31f | 95 | |
Experiment626 | 0:01e3d602e31f | 96 | radius = 5; |
Experiment626 | 0:01e3d602e31f | 97 | |
Experiment626 | 0:01e3d602e31f | 98 | wait(DELAY_TO_RESTART); |
Experiment626 | 0:01e3d602e31f | 99 | } |
Experiment626 | 0:01e3d602e31f | 100 | } |