This is a part of the Kinetiszer project.
util.c@0:cb80470434eb, 2014-10-28 (annotated)
- Committer:
- Clemo
- Date:
- Tue Oct 28 12:19:42 2014 +0000
- Revision:
- 0:cb80470434eb
Error & warning free.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Clemo | 0:cb80470434eb | 1 | #include "atmegatron.h" |
Clemo | 0:cb80470434eb | 2 | |
Clemo | 0:cb80470434eb | 3 | |
Clemo | 0:cb80470434eb | 4 | // The Arduino map function. |
Clemo | 0:cb80470434eb | 5 | long map(long x, long in_min, long in_max, long out_min, long out_max) |
Clemo | 0:cb80470434eb | 6 | { |
Clemo | 0:cb80470434eb | 7 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; |
Clemo | 0:cb80470434eb | 8 | } |
Clemo | 0:cb80470434eb | 9 | |
Clemo | 0:cb80470434eb | 10 | |
Clemo | 0:cb80470434eb | 11 | /*int round(double number) |
Clemo | 0:cb80470434eb | 12 | { |
Clemo | 0:cb80470434eb | 13 | return (number >= 0) ? (int)(number + 0.5) : (int)(number - 0.5); |
Clemo | 0:cb80470434eb | 14 | }*/ |
Clemo | 0:cb80470434eb | 15 | |
Clemo | 0:cb80470434eb | 16 | |
Clemo | 0:cb80470434eb | 17 | void randomSeed(unsigned int seed) |
Clemo | 0:cb80470434eb | 18 | { |
Clemo | 0:cb80470434eb | 19 | if (seed != 0) |
Clemo | 0:cb80470434eb | 20 | { |
Clemo | 0:cb80470434eb | 21 | srand(seed); |
Clemo | 0:cb80470434eb | 22 | } |
Clemo | 0:cb80470434eb | 23 | } |
Clemo | 0:cb80470434eb | 24 | |
Clemo | 0:cb80470434eb | 25 | |
Clemo | 0:cb80470434eb | 26 | // Adapted from Arduino. |
Clemo | 0:cb80470434eb | 27 | static long random_(long howbig) |
Clemo | 0:cb80470434eb | 28 | { |
Clemo | 0:cb80470434eb | 29 | if (howbig == 0) |
Clemo | 0:cb80470434eb | 30 | { |
Clemo | 0:cb80470434eb | 31 | return 0; |
Clemo | 0:cb80470434eb | 32 | } |
Clemo | 0:cb80470434eb | 33 | return rand() % howbig; |
Clemo | 0:cb80470434eb | 34 | } |
Clemo | 0:cb80470434eb | 35 | |
Clemo | 0:cb80470434eb | 36 | |
Clemo | 0:cb80470434eb | 37 | // Adapted from Arduino. |
Clemo | 0:cb80470434eb | 38 | long random(long howsmall, long howbig) |
Clemo | 0:cb80470434eb | 39 | { |
Clemo | 0:cb80470434eb | 40 | if (howsmall >= howbig) |
Clemo | 0:cb80470434eb | 41 | { |
Clemo | 0:cb80470434eb | 42 | return howsmall; |
Clemo | 0:cb80470434eb | 43 | } |
Clemo | 0:cb80470434eb | 44 | long diff = howbig - howsmall; |
Clemo | 0:cb80470434eb | 45 | return random_(diff) + howsmall; |
Clemo | 0:cb80470434eb | 46 | } |
Clemo | 0:cb80470434eb | 47 | |
Clemo | 0:cb80470434eb | 48 | |
Clemo | 0:cb80470434eb | 49 | void cli(void) |
Clemo | 0:cb80470434eb | 50 | { |
Clemo | 0:cb80470434eb | 51 | } |
Clemo | 0:cb80470434eb | 52 | |
Clemo | 0:cb80470434eb | 53 | |
Clemo | 0:cb80470434eb | 54 | void sei(void) |
Clemo | 0:cb80470434eb | 55 | { |
Clemo | 0:cb80470434eb | 56 | } |