servodisc goodness
cube.h@11:16d807d6b9c5, 2018-03-07 (annotated)
- Committer:
- benkatz
- Date:
- Wed Mar 07 19:25:49 2018 +0000
- Revision:
- 11:16d807d6b9c5
- Parent:
- 6:1143996ac690
Seems to work;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
benkatz | 6:1143996ac690 | 1 | #ifndef _cube_h |
benkatz | 6:1143996ac690 | 2 | #define _cube_h |
benkatz | 6:1143996ac690 | 3 | |
benkatz | 6:1143996ac690 | 4 | #include <stdint.h> |
benkatz | 6:1143996ac690 | 5 | // special serial commands |
benkatz | 6:1143996ac690 | 6 | #define K_START (0x1<<6) |
benkatz | 6:1143996ac690 | 7 | #define K_MOVES (0x3<<6) |
benkatz | 6:1143996ac690 | 8 | #define K_END (0x2<<6) |
benkatz | 6:1143996ac690 | 9 | |
benkatz | 6:1143996ac690 | 10 | #define BYTE_TO_BINARY_PATTERN "%c%c%c%c%c%c%c%c" |
benkatz | 6:1143996ac690 | 11 | #define BYTE_TO_BINARY(byte) \ |
benkatz | 6:1143996ac690 | 12 | (byte & 0x80 ? '1' : '0'), \ |
benkatz | 6:1143996ac690 | 13 | (byte & 0x40 ? '1' : '0'), \ |
benkatz | 6:1143996ac690 | 14 | (byte & 0x20 ? '1' : '0'), \ |
benkatz | 6:1143996ac690 | 15 | (byte & 0x10 ? '1' : '0'), \ |
benkatz | 6:1143996ac690 | 16 | (byte & 0x08 ? '1' : '0'), \ |
benkatz | 6:1143996ac690 | 17 | (byte & 0x04 ? '1' : '0'), \ |
benkatz | 6:1143996ac690 | 18 | (byte & 0x02 ? '1' : '0'), \ |
benkatz | 6:1143996ac690 | 19 | (byte & 0x01 ? '1' : '0') |
benkatz | 6:1143996ac690 | 20 | // cube faces |
benkatz | 6:1143996ac690 | 21 | enum face_t |
benkatz | 6:1143996ac690 | 22 | { |
benkatz | 6:1143996ac690 | 23 | Us = 0, |
benkatz | 6:1143996ac690 | 24 | D = 1, |
benkatz | 6:1143996ac690 | 25 | L = 2, |
benkatz | 6:1143996ac690 | 26 | R = 3, |
benkatz | 6:1143996ac690 | 27 | F = 4, |
benkatz | 6:1143996ac690 | 28 | B = 5 |
benkatz | 6:1143996ac690 | 29 | }; |
benkatz | 6:1143996ac690 | 30 | |
benkatz | 6:1143996ac690 | 31 | // a single move, consisting of a face |
benkatz | 6:1143996ac690 | 32 | // and number of CW rotations |
benkatz | 6:1143996ac690 | 33 | struct move_t |
benkatz | 6:1143996ac690 | 34 | { |
benkatz | 6:1143996ac690 | 35 | face_t face; |
benkatz | 6:1143996ac690 | 36 | int8_t n_turns; |
benkatz | 6:1143996ac690 | 37 | }; |
benkatz | 6:1143996ac690 | 38 | |
benkatz | 6:1143996ac690 | 39 | // a sequence of moves: |
benkatz | 6:1143996ac690 | 40 | // pointer to start of an array of moves |
benkatz | 6:1143996ac690 | 41 | // length of the array |
benkatz | 6:1143996ac690 | 42 | struct sequence_t |
benkatz | 6:1143996ac690 | 43 | { |
benkatz | 6:1143996ac690 | 44 | move_t* moves; |
benkatz | 6:1143996ac690 | 45 | uint8_t n_moves; |
benkatz | 6:1143996ac690 | 46 | }; |
benkatz | 6:1143996ac690 | 47 | |
benkatz | 6:1143996ac690 | 48 | // all the information that the simulated board needs to run the sequence |
benkatz | 6:1143996ac690 | 49 | // for the actual implementation, keep only seq and face |
benkatz | 6:1143996ac690 | 50 | // calls to small_delay, rotate, {get,set}_and should be |
benkatz | 6:1143996ac690 | 51 | // replaced with calls to Ben's functions |
benkatz | 6:1143996ac690 | 52 | struct mbed_info_t |
benkatz | 6:1143996ac690 | 53 | { |
benkatz | 6:1143996ac690 | 54 | face_t face; // the face that this board corresponds to |
benkatz | 6:1143996ac690 | 55 | sequence_t* seq; // the sequence to follow |
benkatz | 6:1143996ac690 | 56 | void(*rotate)(int8_t, int8_t); // rotate a face n turns, second argument is board number (needed for simulation) |
benkatz | 6:1143996ac690 | 57 | void(*set_and)(int8_t, int8_t); // sets and output, second argument is board number (needed for simulation) |
benkatz | 6:1143996ac690 | 58 | int8_t(*get_and)(); // gets and board status |
benkatz | 6:1143996ac690 | 59 | }; |
benkatz | 6:1143996ac690 | 60 | |
benkatz | 6:1143996ac690 | 61 | int sequence_to_serial(sequence_t* seq, uint8_t* buffer, int n_bytes); |
benkatz | 6:1143996ac690 | 62 | int serial_to_sequence(sequence_t* seq, uint8_t* buffer, int n_bytes); |
benkatz | 6:1143996ac690 | 63 | void string_to_sequence(char* string); |
benkatz | 6:1143996ac690 | 64 | |
benkatz | 6:1143996ac690 | 65 | //void* run_sequence(void* command); |
benkatz | 6:1143996ac690 | 66 | void* run_sequence_2(void* command); |
benkatz | 6:1143996ac690 | 67 | void print_sequence(sequence_t* seq); |
benkatz | 6:1143996ac690 | 68 | void reset_mbed(); |
benkatz | 6:1143996ac690 | 69 | sequence_t* get_sequence(); |
benkatz | 6:1143996ac690 | 70 | #endif |