Maxim Integrated
/
MAXREFDES99_demo
Demo for MAXREFDES99
maxrefdes99.cpp@2:9fdd01cf0f88, 2016-03-24 (annotated)
- Committer:
- j3
- Date:
- Thu Mar 24 23:35:56 2016 +0000
- Revision:
- 2:9fdd01cf0f88
- Parent:
- 0:6b0161c3e440
- Child:
- 3:41bdbc9b3cec
fixed buffer delay
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
j3 | 0:6b0161c3e440 | 1 | /******************************************************************//** |
j3 | 0:6b0161c3e440 | 2 | * @file maxrefdes99.cpp |
j3 | 0:6b0161c3e440 | 3 | * |
j3 | 0:6b0161c3e440 | 4 | * @author Justin Jordan |
j3 | 0:6b0161c3e440 | 5 | * |
j3 | 0:6b0161c3e440 | 6 | * @version 0.0 |
j3 | 0:6b0161c3e440 | 7 | * |
j3 | 0:6b0161c3e440 | 8 | * Started: 08JAN16 |
j3 | 0:6b0161c3e440 | 9 | * |
j3 | 0:6b0161c3e440 | 10 | * Updated: |
j3 | 0:6b0161c3e440 | 11 | * |
j3 | 0:6b0161c3e440 | 12 | * @brief Source file for maxrefdes99 demo |
j3 | 0:6b0161c3e440 | 13 | *********************************************************************** |
j3 | 0:6b0161c3e440 | 14 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
j3 | 0:6b0161c3e440 | 15 | * |
j3 | 0:6b0161c3e440 | 16 | * Permission is hereby granted, free of charge, to any person obtaining a |
j3 | 0:6b0161c3e440 | 17 | * copy of this software and associated documentation files (the "Software"), |
j3 | 0:6b0161c3e440 | 18 | * to deal in the Software without restriction, including without limitation |
j3 | 0:6b0161c3e440 | 19 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
j3 | 0:6b0161c3e440 | 20 | * and/or sell copies of the Software, and to permit persons to whom the |
j3 | 0:6b0161c3e440 | 21 | * Software is furnished to do so, subject to the following conditions: |
j3 | 0:6b0161c3e440 | 22 | * |
j3 | 0:6b0161c3e440 | 23 | * The above copyright notice and this permission notice shall be included |
j3 | 0:6b0161c3e440 | 24 | * in all copies or substantial portions of the Software. |
j3 | 0:6b0161c3e440 | 25 | * |
j3 | 0:6b0161c3e440 | 26 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
j3 | 0:6b0161c3e440 | 27 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
j3 | 0:6b0161c3e440 | 28 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
j3 | 0:6b0161c3e440 | 29 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
j3 | 0:6b0161c3e440 | 30 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
j3 | 0:6b0161c3e440 | 31 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
j3 | 0:6b0161c3e440 | 32 | * OTHER DEALINGS IN THE SOFTWARE. |
j3 | 0:6b0161c3e440 | 33 | * |
j3 | 0:6b0161c3e440 | 34 | * Except as contained in this notice, the name of Maxim Integrated |
j3 | 0:6b0161c3e440 | 35 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
j3 | 0:6b0161c3e440 | 36 | * Products, Inc. Branding Policy. |
j3 | 0:6b0161c3e440 | 37 | * |
j3 | 0:6b0161c3e440 | 38 | * The mere transfer of this software does not imply any licenses |
j3 | 0:6b0161c3e440 | 39 | * of trade secrets, proprietary technology, copyrights, patents, |
j3 | 0:6b0161c3e440 | 40 | * trademarks, maskwork rights, or any other form of intellectual |
j3 | 0:6b0161c3e440 | 41 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
j3 | 0:6b0161c3e440 | 42 | * ownership rights. |
j3 | 0:6b0161c3e440 | 43 | **********************************************************************/ |
j3 | 0:6b0161c3e440 | 44 | |
j3 | 0:6b0161c3e440 | 45 | |
j3 | 0:6b0161c3e440 | 46 | #include "maxrefdes99.h" |
j3 | 0:6b0161c3e440 | 47 | |
j3 | 0:6b0161c3e440 | 48 | |
j3 | 0:6b0161c3e440 | 49 | //5x7 character bit map |
j3 | 0:6b0161c3e440 | 50 | static const uint8_t font_5x7[95][6] = { |
j3 | 0:6b0161c3e440 | 51 | {0x00,0x00,0x00,0x00,0x00,0x00}, // SPACE |
j3 | 0:6b0161c3e440 | 52 | {0x00,0x00,0x00,0x4F,0x00,0x00}, // ! |
j3 | 0:6b0161c3e440 | 53 | {0x00,0x00,0x07,0x00,0x07,0x00}, // " |
j3 | 0:6b0161c3e440 | 54 | {0x00,0x14,0x7F,0x14,0x7F,0x14}, // # |
j3 | 0:6b0161c3e440 | 55 | {0x00,0x24,0x2A,0x7F,0x2A,0x12}, // $ |
j3 | 0:6b0161c3e440 | 56 | {0x00,0x23,0x13,0x08,0x64,0x62}, // % |
j3 | 0:6b0161c3e440 | 57 | {0x00,0x36,0x49,0x55,0x22,0x50}, // & |
j3 | 0:6b0161c3e440 | 58 | {0x00,0x00,0x05,0x03,0x00,0x00}, // ' |
j3 | 0:6b0161c3e440 | 59 | {0x00,0x00,0x1C,0x22,0x41,0x00}, // ( |
j3 | 0:6b0161c3e440 | 60 | {0x00,0x00,0x41,0x22,0x1C,0x00}, // ) |
j3 | 0:6b0161c3e440 | 61 | {0x00,0x14,0x08,0x3E,0x08,0x14}, // * |
j3 | 0:6b0161c3e440 | 62 | {0x00,0x08,0x08,0x3E,0x08,0x08}, // + |
j3 | 0:6b0161c3e440 | 63 | {0x00,0x00,0x50,0x30,0x00,0x00}, // , |
j3 | 0:6b0161c3e440 | 64 | {0x00,0x08,0x08,0x08,0x08,0x08}, // - |
j3 | 0:6b0161c3e440 | 65 | {0x00,0x00,0x60,0x60,0x00,0x00}, // . |
j3 | 0:6b0161c3e440 | 66 | {0x00,0x20,0x10,0x08,0x04,0x02}, // / |
j3 | 0:6b0161c3e440 | 67 | {0x00,0x3E,0x51,0x49,0x45,0x3E}, // 0 |
j3 | 0:6b0161c3e440 | 68 | {0x00,0x00,0x42,0x7F,0x40,0x00}, // 1 |
j3 | 0:6b0161c3e440 | 69 | {0x00,0x42,0x61,0x51,0x49,0x46}, // 2 |
j3 | 0:6b0161c3e440 | 70 | {0x00,0x21,0x41,0x45,0x4B,0x31}, // 3 |
j3 | 0:6b0161c3e440 | 71 | {0x00,0x18,0x14,0x12,0x7F,0x10}, // 4 |
j3 | 0:6b0161c3e440 | 72 | {0x00,0x27,0x45,0x45,0x45,0x39}, // 5 |
j3 | 0:6b0161c3e440 | 73 | {0x00,0x3C,0x4A,0x49,0x49,0x30}, // 6 |
j3 | 0:6b0161c3e440 | 74 | {0x00,0x01,0x71,0x09,0x05,0x03}, // 7 |
j3 | 0:6b0161c3e440 | 75 | {0x00,0x36,0x49,0x49,0x49,0x36}, // 8 |
j3 | 0:6b0161c3e440 | 76 | {0x00,0x06,0x49,0x49,0x29,0x1E}, // 9 |
j3 | 0:6b0161c3e440 | 77 | {0x00,0x36,0x36,0x00,0x00,0x00}, // : |
j3 | 0:6b0161c3e440 | 78 | {0x00,0x56,0x36,0x00,0x00,0x00}, // ; |
j3 | 0:6b0161c3e440 | 79 | {0x00,0x08,0x14,0x22,0x41,0x00}, // < |
j3 | 0:6b0161c3e440 | 80 | {0x00,0x14,0x14,0x14,0x14,0x14}, // = |
j3 | 0:6b0161c3e440 | 81 | {0x00,0x00,0x41,0x22,0x14,0x08}, // > |
j3 | 0:6b0161c3e440 | 82 | {0x00,0x02,0x01,0x51,0x09,0x06}, // ? |
j3 | 0:6b0161c3e440 | 83 | {0x00,0x30,0x49,0x79,0x41,0x3E}, // @ |
j3 | 0:6b0161c3e440 | 84 | {0x00,0x7E,0x11,0x11,0x11,0x7E}, // A |
j3 | 0:6b0161c3e440 | 85 | {0x00,0x7F,0x49,0x49,0x49,0x36}, // B |
j3 | 0:6b0161c3e440 | 86 | {0x00,0x3E,0x41,0x41,0x41,0x22}, // C |
j3 | 0:6b0161c3e440 | 87 | {0x00,0x7F,0x41,0x41,0x22,0x1C}, // D |
j3 | 0:6b0161c3e440 | 88 | {0x00,0x7F,0x49,0x49,0x49,0x41}, // E |
j3 | 0:6b0161c3e440 | 89 | {0x00,0x7F,0x09,0x09,0x09,0x01}, // F |
j3 | 0:6b0161c3e440 | 90 | {0x00,0x3E,0x41,0x49,0x49,0x7A}, // G |
j3 | 0:6b0161c3e440 | 91 | {0x00,0x7F,0x08,0x08,0x08,0x7F}, // H |
j3 | 0:6b0161c3e440 | 92 | {0x00,0x00,0x41,0x7F,0x41,0x00}, // I |
j3 | 0:6b0161c3e440 | 93 | {0x00,0x20,0x40,0x41,0x3F,0x01}, // J |
j3 | 0:6b0161c3e440 | 94 | {0x00,0x7F,0x08,0x14,0x22,0x41}, // K |
j3 | 0:6b0161c3e440 | 95 | {0x00,0x7F,0x40,0x40,0x40,0x40}, // L |
j3 | 0:6b0161c3e440 | 96 | {0x00,0x7F,0x02,0x0C,0x02,0x7F}, // M |
j3 | 0:6b0161c3e440 | 97 | {0x00,0x7F,0x04,0x08,0x10,0x7F}, // N |
j3 | 0:6b0161c3e440 | 98 | {0x00,0x3E,0x41,0x41,0x41,0x3E}, // O |
j3 | 0:6b0161c3e440 | 99 | {0x00,0x7F,0x09,0x09,0x09,0x06}, // P |
j3 | 0:6b0161c3e440 | 100 | {0x00,0x3E,0x41,0x51,0x21,0x5E}, // Q |
j3 | 0:6b0161c3e440 | 101 | {0x00,0x7F,0x09,0x19,0x29,0x46}, // R |
j3 | 0:6b0161c3e440 | 102 | {0x00,0x46,0x49,0x49,0x49,0x31}, // S |
j3 | 0:6b0161c3e440 | 103 | {0x00,0x01,0x01,0x7F,0x01,0x01}, // T |
j3 | 0:6b0161c3e440 | 104 | {0x00,0x3F,0x40,0x40,0x40,0x3F}, // U |
j3 | 0:6b0161c3e440 | 105 | {0x00,0x1F,0x20,0x40,0x20,0x1F}, // V |
j3 | 0:6b0161c3e440 | 106 | {0x00,0x3F,0x40,0x30,0x40,0x3F}, // W |
j3 | 0:6b0161c3e440 | 107 | {0x00,0x63,0x14,0x08,0x14,0x63}, // X |
j3 | 0:6b0161c3e440 | 108 | {0x00,0x07,0x08,0x70,0x08,0x07}, // Y |
j3 | 0:6b0161c3e440 | 109 | {0x00,0x61,0x51,0x49,0x45,0x43}, // Z |
j3 | 0:6b0161c3e440 | 110 | {0x00,0x00,0x7F,0x41,0x41,0x00}, // [ |
j3 | 0:6b0161c3e440 | 111 | {0x00,0x02,0x04,0x08,0x10,0x20}, // backslash |
j3 | 0:6b0161c3e440 | 112 | {0x00,0x00,0x41,0x41,0x7F,0x00}, // ] |
j3 | 0:6b0161c3e440 | 113 | {0x00,0x04,0x02,0x01,0x02,0x04}, // ^ |
j3 | 0:6b0161c3e440 | 114 | {0x00,0x40,0x40,0x40,0x40,0x40}, // _ |
j3 | 0:6b0161c3e440 | 115 | {0x00,0x00,0x01,0x02,0x04,0x00}, // ` |
j3 | 0:6b0161c3e440 | 116 | {0x00,0x20,0x54,0x54,0x54,0x78}, // a |
j3 | 0:6b0161c3e440 | 117 | {0x00,0x7F,0x50,0x48,0x48,0x30}, // b |
j3 | 0:6b0161c3e440 | 118 | {0x00,0x38,0x44,0x44,0x44,0x20}, // c |
j3 | 0:6b0161c3e440 | 119 | {0x00,0x38,0x44,0x44,0x48,0x7F}, // d |
j3 | 0:6b0161c3e440 | 120 | {0x00,0x38,0x54,0x54,0x54,0x18}, // e |
j3 | 0:6b0161c3e440 | 121 | {0x00,0x08,0x7E,0x09,0x01,0x02}, // f |
j3 | 0:6b0161c3e440 | 122 | {0x00,0x0C,0x52,0x52,0x52,0x3E}, // g |
j3 | 0:6b0161c3e440 | 123 | {0x00,0x7F,0x08,0x04,0x04,0x78}, // h |
j3 | 0:6b0161c3e440 | 124 | {0x00,0x00,0x44,0x7D,0x40,0x00}, // i |
j3 | 0:6b0161c3e440 | 125 | {0x00,0x20,0x40,0x44,0x3D,0x00}, // j |
j3 | 0:6b0161c3e440 | 126 | {0x00,0x7F,0x10,0x28,0x44,0x00}, // k |
j3 | 0:6b0161c3e440 | 127 | {0x00,0x00,0x41,0x7F,0x40,0x00}, // l |
j3 | 0:6b0161c3e440 | 128 | {0x00,0x78,0x04,0x58,0x44,0x78}, // m |
j3 | 0:6b0161c3e440 | 129 | {0x00,0x7C,0x08,0x04,0x04,0x78}, // n |
j3 | 0:6b0161c3e440 | 130 | {0x00,0x38,0x44,0x44,0x44,0x38}, // o |
j3 | 0:6b0161c3e440 | 131 | {0x00,0x7C,0x14,0x14,0x14,0x08}, // p |
j3 | 0:6b0161c3e440 | 132 | {0x00,0x08,0x14,0x14,0x18,0x7C}, // q |
j3 | 0:6b0161c3e440 | 133 | {0x00,0x7C,0x08,0x04,0x04,0x08}, // r |
j3 | 0:6b0161c3e440 | 134 | {0x00,0x48,0x54,0x54,0x54,0x20}, // s |
j3 | 0:6b0161c3e440 | 135 | {0x00,0x04,0x3F,0x44,0x40,0x20}, // t |
j3 | 0:6b0161c3e440 | 136 | {0x00,0x3C,0x40,0x40,0x20,0x7C}, // u |
j3 | 0:6b0161c3e440 | 137 | {0x00,0x1C,0x20,0x40,0x20,0x1C}, // v |
j3 | 0:6b0161c3e440 | 138 | {0x00,0x3C,0x40,0x30,0x40,0x3C}, // w |
j3 | 0:6b0161c3e440 | 139 | {0x00,0x44,0x28,0x10,0x28,0x44}, // x |
j3 | 0:6b0161c3e440 | 140 | {0x00,0x0C,0x50,0x50,0x50,0x3C}, // y |
j3 | 0:6b0161c3e440 | 141 | {0x00,0x44,0x64,0x54,0x4C,0x44}, // z |
j3 | 0:6b0161c3e440 | 142 | {0x00,0x00,0x08,0x36,0x41,0x00}, // { |
j3 | 0:6b0161c3e440 | 143 | {0x00,0x00,0x00,0x7F,0x00,0x00}, // | |
j3 | 0:6b0161c3e440 | 144 | {0x00,0x00,0x41,0x36,0x08,0x00}, // } |
j3 | 0:6b0161c3e440 | 145 | {0x00,0x0C,0x02,0x0C,0x10,0x0C} // ~ |
j3 | 0:6b0161c3e440 | 146 | }; |
j3 | 0:6b0161c3e440 | 147 | |
j3 | 0:6b0161c3e440 | 148 | |
j3 | 0:6b0161c3e440 | 149 | static uint8_t display_buff[256]; |
j3 | 0:6b0161c3e440 | 150 | static uint8_t temp_buff[256]; |
j3 | 0:6b0161c3e440 | 151 | |
j3 | 2:9fdd01cf0f88 | 152 | static const uint8_t DISPLAY_BUFF_START = 0; |
j3 | 2:9fdd01cf0f88 | 153 | static const uint8_t DISPLAY_BUFF_END = 31; |
j3 | 2:9fdd01cf0f88 | 154 | |
j3 | 2:9fdd01cf0f88 | 155 | static uint8_t buff_end = 0; |
j3 | 0:6b0161c3e440 | 156 | |
j3 | 0:6b0161c3e440 | 157 | static const uint32_t MAX_STRING_LENGTH = 32; |
j3 | 0:6b0161c3e440 | 158 | static char str[MAX_STRING_LENGTH]; |
j3 | 0:6b0161c3e440 | 159 | |
j3 | 0:6b0161c3e440 | 160 | |
j3 | 0:6b0161c3e440 | 161 | //********************************************************************* |
j3 | 0:6b0161c3e440 | 162 | void get_5x7_character(char c, uint8_t *char_buff) |
j3 | 0:6b0161c3e440 | 163 | { |
j3 | 0:6b0161c3e440 | 164 | uint16_t temp_data; |
j3 | 0:6b0161c3e440 | 165 | uint8_t idx, idy; |
j3 | 0:6b0161c3e440 | 166 | |
j3 | 0:6b0161c3e440 | 167 | for(idx = 0; idx < 6; idx++) |
j3 | 0:6b0161c3e440 | 168 | { |
j3 | 0:6b0161c3e440 | 169 | //get byte of char from map and flip it, bit 0 becomes bit 7 and so on |
j3 | 0:6b0161c3e440 | 170 | temp_data = (0x00FF & (font_5x7[c - 0x20][idx])); |
j3 | 0:6b0161c3e440 | 171 | for(idy = 0; idy < 8; idy++) |
j3 | 0:6b0161c3e440 | 172 | { |
j3 | 0:6b0161c3e440 | 173 | temp_data = (temp_data | (((temp_data & (1 << idy)) << (15 - (idy*2))))); |
j3 | 0:6b0161c3e440 | 174 | } |
j3 | 0:6b0161c3e440 | 175 | temp_data = ((temp_data >> 8) & 0x00FF); |
j3 | 0:6b0161c3e440 | 176 | |
j3 | 0:6b0161c3e440 | 177 | char_buff[idx] = ((uint8_t) temp_data); |
j3 | 0:6b0161c3e440 | 178 | } |
j3 | 0:6b0161c3e440 | 179 | } |
j3 | 0:6b0161c3e440 | 180 | |
j3 | 0:6b0161c3e440 | 181 | |
j3 | 0:6b0161c3e440 | 182 | //********************************************************************* |
j3 | 2:9fdd01cf0f88 | 183 | void print_char(Max7219 *p_display, uint8_t position99, char c) |
j3 | 0:6b0161c3e440 | 184 | { |
j3 | 0:6b0161c3e440 | 185 | uint8_t idx; |
j3 | 2:9fdd01cf0f88 | 186 | uint8_t char_buff[6]; |
j3 | 2:9fdd01cf0f88 | 187 | uint8_t device; |
j3 | 0:6b0161c3e440 | 188 | uint8_t wrap_device; |
j3 | 0:6b0161c3e440 | 189 | uint8_t wrap_idx; |
j3 | 2:9fdd01cf0f88 | 190 | uint8_t buff_start = position99; |
j3 | 0:6b0161c3e440 | 191 | |
j3 | 0:6b0161c3e440 | 192 | get_5x7_character(c, char_buff); |
j3 | 2:9fdd01cf0f88 | 193 | |
j3 | 2:9fdd01cf0f88 | 194 | if(position99 < 33) |
j3 | 0:6b0161c3e440 | 195 | { |
j3 | 2:9fdd01cf0f88 | 196 | //get device and device_position |
j3 | 2:9fdd01cf0f88 | 197 | if(position99 > 8) |
j3 | 2:9fdd01cf0f88 | 198 | { |
j3 | 2:9fdd01cf0f88 | 199 | if(position99%8) |
j3 | 2:9fdd01cf0f88 | 200 | { |
j3 | 2:9fdd01cf0f88 | 201 | device = ((position99/8) + 1); |
j3 | 2:9fdd01cf0f88 | 202 | position99 = position99%8; |
j3 | 2:9fdd01cf0f88 | 203 | } |
j3 | 2:9fdd01cf0f88 | 204 | else |
j3 | 2:9fdd01cf0f88 | 205 | { |
j3 | 2:9fdd01cf0f88 | 206 | device = position99/8; |
j3 | 2:9fdd01cf0f88 | 207 | position99 = 8; |
j3 | 2:9fdd01cf0f88 | 208 | } |
j3 | 2:9fdd01cf0f88 | 209 | } |
j3 | 2:9fdd01cf0f88 | 210 | else |
j3 | 2:9fdd01cf0f88 | 211 | { |
j3 | 2:9fdd01cf0f88 | 212 | device = 1; |
j3 | 2:9fdd01cf0f88 | 213 | } |
j3 | 2:9fdd01cf0f88 | 214 | |
j3 | 2:9fdd01cf0f88 | 215 | //check for dispaly wrap around |
j3 | 2:9fdd01cf0f88 | 216 | //(moving to next 8x8 grid cause character doesn't fit on current one) |
j3 | 2:9fdd01cf0f88 | 217 | if(position99 > 3) |
j3 | 2:9fdd01cf0f88 | 218 | { |
j3 | 2:9fdd01cf0f88 | 219 | wrap_idx = (9 - position99); |
j3 | 2:9fdd01cf0f88 | 220 | if(device < 4) |
j3 | 2:9fdd01cf0f88 | 221 | { |
j3 | 2:9fdd01cf0f88 | 222 | wrap_device = (device + 1); |
j3 | 2:9fdd01cf0f88 | 223 | } |
j3 | 2:9fdd01cf0f88 | 224 | else |
j3 | 2:9fdd01cf0f88 | 225 | { |
j3 | 2:9fdd01cf0f88 | 226 | wrap_device = 1; |
j3 | 2:9fdd01cf0f88 | 227 | } |
j3 | 2:9fdd01cf0f88 | 228 | } |
j3 | 2:9fdd01cf0f88 | 229 | else |
j3 | 2:9fdd01cf0f88 | 230 | { |
j3 | 2:9fdd01cf0f88 | 231 | wrap_idx = 6; //make bigger than idx, not used |
j3 | 2:9fdd01cf0f88 | 232 | wrap_device = 0; //not used |
j3 | 2:9fdd01cf0f88 | 233 | } |
j3 | 2:9fdd01cf0f88 | 234 | |
j3 | 2:9fdd01cf0f88 | 235 | //print character to position |
j3 | 2:9fdd01cf0f88 | 236 | for(idx = 0; idx < 6; idx++) |
j3 | 2:9fdd01cf0f88 | 237 | { |
j3 | 2:9fdd01cf0f88 | 238 | //check for wrap |
j3 | 2:9fdd01cf0f88 | 239 | if((idx >= wrap_idx) && (device != 4)) |
j3 | 2:9fdd01cf0f88 | 240 | { |
j3 | 2:9fdd01cf0f88 | 241 | p_display->write_digit(wrap_device, ((idx - wrap_idx) + 1), char_buff[idx]); |
j3 | 2:9fdd01cf0f88 | 242 | } |
j3 | 2:9fdd01cf0f88 | 243 | else |
j3 | 2:9fdd01cf0f88 | 244 | { |
j3 | 2:9fdd01cf0f88 | 245 | p_display->write_digit(device, (position99 + idx), char_buff[idx]); |
j3 | 2:9fdd01cf0f88 | 246 | } |
j3 | 2:9fdd01cf0f88 | 247 | |
j3 | 2:9fdd01cf0f88 | 248 | buff_end = ((buff_start - 1) + idx); |
j3 | 2:9fdd01cf0f88 | 249 | display_buff[buff_end] = char_buff[idx]; |
j3 | 2:9fdd01cf0f88 | 250 | } |
j3 | 0:6b0161c3e440 | 251 | } |
j3 | 0:6b0161c3e440 | 252 | else |
j3 | 0:6b0161c3e440 | 253 | { |
j3 | 2:9fdd01cf0f88 | 254 | for(idx = 0; idx < 6; idx++) |
j3 | 2:9fdd01cf0f88 | 255 | { |
j3 | 2:9fdd01cf0f88 | 256 | buff_end = ((buff_start - 1) + idx); |
j3 | 2:9fdd01cf0f88 | 257 | display_buff[buff_end] = char_buff[idx]; |
j3 | 2:9fdd01cf0f88 | 258 | } |
j3 | 0:6b0161c3e440 | 259 | } |
j3 | 0:6b0161c3e440 | 260 | } |
j3 | 0:6b0161c3e440 | 261 | |
j3 | 0:6b0161c3e440 | 262 | |
j3 | 0:6b0161c3e440 | 263 | //********************************************************************* |
j3 | 0:6b0161c3e440 | 264 | void print_string(Max7219 *p_display, uint8_t position, const char *s) |
j3 | 0:6b0161c3e440 | 265 | { |
j3 | 0:6b0161c3e440 | 266 | uint8_t idx = 0; |
j3 | 0:6b0161c3e440 | 267 | |
j3 | 0:6b0161c3e440 | 268 | while(s[idx] != '\0') |
j3 | 0:6b0161c3e440 | 269 | { |
j3 | 0:6b0161c3e440 | 270 | print_char(p_display, (position + (idx*6)), s[idx]); |
j3 | 0:6b0161c3e440 | 271 | idx++; |
j3 | 0:6b0161c3e440 | 272 | } |
j3 | 0:6b0161c3e440 | 273 | } |
j3 | 0:6b0161c3e440 | 274 | |
j3 | 0:6b0161c3e440 | 275 | |
j3 | 0:6b0161c3e440 | 276 | //********************************************************************* |
j3 | 2:9fdd01cf0f88 | 277 | void shift_display_right(Max7219 *p_display, uint8_t count, uint8_t ms_delay) |
j3 | 0:6b0161c3e440 | 278 | { |
j3 | 0:6b0161c3e440 | 279 | uint16_t idx, idy; |
j3 | 2:9fdd01cf0f88 | 280 | uint8_t position99; |
j3 | 0:6b0161c3e440 | 281 | |
j3 | 0:6b0161c3e440 | 282 | for(idx = 0; idx < count; idx++) |
j3 | 0:6b0161c3e440 | 283 | { |
j3 | 2:9fdd01cf0f88 | 284 | for(idy = 0; idy < (buff_end + 1); idy++) |
j3 | 0:6b0161c3e440 | 285 | { |
j3 | 2:9fdd01cf0f88 | 286 | if(idy == buff_end) |
j3 | 0:6b0161c3e440 | 287 | { |
j3 | 0:6b0161c3e440 | 288 | temp_buff[0] = display_buff[idy]; |
j3 | 0:6b0161c3e440 | 289 | } |
j3 | 0:6b0161c3e440 | 290 | else |
j3 | 0:6b0161c3e440 | 291 | { |
j3 | 0:6b0161c3e440 | 292 | temp_buff[idy + 1] = display_buff[idy]; |
j3 | 0:6b0161c3e440 | 293 | } |
j3 | 0:6b0161c3e440 | 294 | } |
j3 | 0:6b0161c3e440 | 295 | |
j3 | 2:9fdd01cf0f88 | 296 | for(idy = 0; idy < (buff_end + 1); idy++) |
j3 | 0:6b0161c3e440 | 297 | { |
j3 | 0:6b0161c3e440 | 298 | //save shifted display in buffer |
j3 | 0:6b0161c3e440 | 299 | display_buff[idy] = temp_buff[idy]; |
j3 | 0:6b0161c3e440 | 300 | |
j3 | 2:9fdd01cf0f88 | 301 | if(idy <= DISPLAY_BUFF_END) |
j3 | 0:6b0161c3e440 | 302 | { |
j3 | 2:9fdd01cf0f88 | 303 | position99 = ((idy - DISPLAY_BUFF_START) + 1); |
j3 | 2:9fdd01cf0f88 | 304 | if(position99 > 24) |
j3 | 0:6b0161c3e440 | 305 | { |
j3 | 2:9fdd01cf0f88 | 306 | if(position99 % 8) |
j3 | 0:6b0161c3e440 | 307 | { |
j3 | 2:9fdd01cf0f88 | 308 | position99 = position99 % 8; |
j3 | 0:6b0161c3e440 | 309 | } |
j3 | 0:6b0161c3e440 | 310 | else |
j3 | 0:6b0161c3e440 | 311 | { |
j3 | 2:9fdd01cf0f88 | 312 | position99 = 8; |
j3 | 0:6b0161c3e440 | 313 | } |
j3 | 2:9fdd01cf0f88 | 314 | p_display->write_digit(4, position99, display_buff[idy]); |
j3 | 0:6b0161c3e440 | 315 | } |
j3 | 2:9fdd01cf0f88 | 316 | else if(position99 > 16) |
j3 | 0:6b0161c3e440 | 317 | { |
j3 | 2:9fdd01cf0f88 | 318 | if(position99 % 8) |
j3 | 0:6b0161c3e440 | 319 | { |
j3 | 2:9fdd01cf0f88 | 320 | position99 = position99 % 8; |
j3 | 0:6b0161c3e440 | 321 | } |
j3 | 0:6b0161c3e440 | 322 | else |
j3 | 0:6b0161c3e440 | 323 | { |
j3 | 2:9fdd01cf0f88 | 324 | position99 = 8; |
j3 | 0:6b0161c3e440 | 325 | } |
j3 | 2:9fdd01cf0f88 | 326 | p_display->write_digit(3, position99, display_buff[idy]); |
j3 | 0:6b0161c3e440 | 327 | } |
j3 | 2:9fdd01cf0f88 | 328 | else if(position99 > 8) |
j3 | 0:6b0161c3e440 | 329 | { |
j3 | 2:9fdd01cf0f88 | 330 | if(position99 % 8) |
j3 | 0:6b0161c3e440 | 331 | { |
j3 | 2:9fdd01cf0f88 | 332 | position99 = position99 % 8; |
j3 | 0:6b0161c3e440 | 333 | } |
j3 | 0:6b0161c3e440 | 334 | else |
j3 | 0:6b0161c3e440 | 335 | { |
j3 | 2:9fdd01cf0f88 | 336 | position99 = 8; |
j3 | 0:6b0161c3e440 | 337 | } |
j3 | 2:9fdd01cf0f88 | 338 | p_display->write_digit(2, position99, display_buff[idy]); |
j3 | 0:6b0161c3e440 | 339 | } |
j3 | 0:6b0161c3e440 | 340 | else |
j3 | 0:6b0161c3e440 | 341 | { |
j3 | 2:9fdd01cf0f88 | 342 | p_display->write_digit(1, position99, display_buff[idy]); |
j3 | 0:6b0161c3e440 | 343 | } |
j3 | 0:6b0161c3e440 | 344 | } |
j3 | 0:6b0161c3e440 | 345 | } |
j3 | 2:9fdd01cf0f88 | 346 | |
j3 | 2:9fdd01cf0f88 | 347 | wait_ms(ms_delay); |
j3 | 0:6b0161c3e440 | 348 | } |
j3 | 0:6b0161c3e440 | 349 | } |
j3 | 0:6b0161c3e440 | 350 | |
j3 | 0:6b0161c3e440 | 351 | |
j3 | 2:9fdd01cf0f88 | 352 | //********************************************************************* |
j3 | 2:9fdd01cf0f88 | 353 | void shift_display_left(Max7219 *p_display, uint8_t count, uint8_t ms_delay) |
j3 | 0:6b0161c3e440 | 354 | { |
j3 | 0:6b0161c3e440 | 355 | uint16_t idx, idy; |
j3 | 2:9fdd01cf0f88 | 356 | uint8_t position99; |
j3 | 0:6b0161c3e440 | 357 | |
j3 | 0:6b0161c3e440 | 358 | for(idx = 0; idx < count; idx++) |
j3 | 0:6b0161c3e440 | 359 | { |
j3 | 2:9fdd01cf0f88 | 360 | for(idy = 0; idy < (buff_end + 1); idy++) |
j3 | 0:6b0161c3e440 | 361 | { |
j3 | 0:6b0161c3e440 | 362 | if(idy == 0) |
j3 | 0:6b0161c3e440 | 363 | { |
j3 | 2:9fdd01cf0f88 | 364 | temp_buff[buff_end] = display_buff[idy]; |
j3 | 0:6b0161c3e440 | 365 | } |
j3 | 0:6b0161c3e440 | 366 | else |
j3 | 0:6b0161c3e440 | 367 | { |
j3 | 0:6b0161c3e440 | 368 | temp_buff[idy - 1] = display_buff[idy]; |
j3 | 0:6b0161c3e440 | 369 | } |
j3 | 0:6b0161c3e440 | 370 | } |
j3 | 0:6b0161c3e440 | 371 | |
j3 | 2:9fdd01cf0f88 | 372 | for(idy = 0; idy < (buff_end + 1); idy++) |
j3 | 0:6b0161c3e440 | 373 | { |
j3 | 0:6b0161c3e440 | 374 | //save shifted display in buffer |
j3 | 0:6b0161c3e440 | 375 | display_buff[idy] = temp_buff[idy]; |
j3 | 0:6b0161c3e440 | 376 | |
j3 | 2:9fdd01cf0f88 | 377 | if(idy <= DISPLAY_BUFF_END) |
j3 | 0:6b0161c3e440 | 378 | { |
j3 | 2:9fdd01cf0f88 | 379 | position99 = ((idy - DISPLAY_BUFF_START) + 1); |
j3 | 2:9fdd01cf0f88 | 380 | if(position99 > 24) |
j3 | 0:6b0161c3e440 | 381 | { |
j3 | 2:9fdd01cf0f88 | 382 | if(position99 % 8) |
j3 | 0:6b0161c3e440 | 383 | { |
j3 | 2:9fdd01cf0f88 | 384 | position99 = position99 % 8; |
j3 | 0:6b0161c3e440 | 385 | } |
j3 | 0:6b0161c3e440 | 386 | else |
j3 | 0:6b0161c3e440 | 387 | { |
j3 | 2:9fdd01cf0f88 | 388 | position99 = 8; |
j3 | 0:6b0161c3e440 | 389 | } |
j3 | 2:9fdd01cf0f88 | 390 | p_display->write_digit(4, position99, display_buff[idy]); |
j3 | 0:6b0161c3e440 | 391 | } |
j3 | 2:9fdd01cf0f88 | 392 | else if(position99 > 16) |
j3 | 0:6b0161c3e440 | 393 | { |
j3 | 2:9fdd01cf0f88 | 394 | if(position99 % 8) |
j3 | 0:6b0161c3e440 | 395 | { |
j3 | 2:9fdd01cf0f88 | 396 | position99 = position99 % 8; |
j3 | 0:6b0161c3e440 | 397 | } |
j3 | 0:6b0161c3e440 | 398 | else |
j3 | 0:6b0161c3e440 | 399 | { |
j3 | 2:9fdd01cf0f88 | 400 | position99 = 8; |
j3 | 0:6b0161c3e440 | 401 | } |
j3 | 2:9fdd01cf0f88 | 402 | p_display->write_digit(3, position99, display_buff[idy]); |
j3 | 0:6b0161c3e440 | 403 | } |
j3 | 2:9fdd01cf0f88 | 404 | else if(position99 > 8) |
j3 | 0:6b0161c3e440 | 405 | { |
j3 | 2:9fdd01cf0f88 | 406 | if(position99 % 8) |
j3 | 0:6b0161c3e440 | 407 | { |
j3 | 2:9fdd01cf0f88 | 408 | position99 = position99 % 8; |
j3 | 0:6b0161c3e440 | 409 | } |
j3 | 0:6b0161c3e440 | 410 | else |
j3 | 0:6b0161c3e440 | 411 | { |
j3 | 2:9fdd01cf0f88 | 412 | position99 = 8; |
j3 | 0:6b0161c3e440 | 413 | } |
j3 | 2:9fdd01cf0f88 | 414 | p_display->write_digit(2, position99, display_buff[idy]); |
j3 | 0:6b0161c3e440 | 415 | } |
j3 | 0:6b0161c3e440 | 416 | else |
j3 | 0:6b0161c3e440 | 417 | { |
j3 | 2:9fdd01cf0f88 | 418 | p_display->write_digit(1, position99, display_buff[idy]); |
j3 | 0:6b0161c3e440 | 419 | } |
j3 | 0:6b0161c3e440 | 420 | } |
j3 | 0:6b0161c3e440 | 421 | } |
j3 | 2:9fdd01cf0f88 | 422 | |
j3 | 2:9fdd01cf0f88 | 423 | wait_ms(ms_delay); |
j3 | 0:6b0161c3e440 | 424 | } |
j3 | 0:6b0161c3e440 | 425 | } |
j3 | 0:6b0161c3e440 | 426 | |
j3 | 0:6b0161c3e440 | 427 | |
j3 | 0:6b0161c3e440 | 428 | //********************************************************************* |
j3 | 0:6b0161c3e440 | 429 | void quad_all_on(Max7219 *p_display, uint8_t quad) |
j3 | 0:6b0161c3e440 | 430 | { |
j3 | 0:6b0161c3e440 | 431 | if(quad > 1) |
j3 | 0:6b0161c3e440 | 432 | { |
j3 | 0:6b0161c3e440 | 433 | for(uint8_t idx = 0; idx < 8; idx++) |
j3 | 0:6b0161c3e440 | 434 | { |
j3 | 0:6b0161c3e440 | 435 | display_buff[((quad - 1)*8) + DISPLAY_BUFF_START + idx] = 0xFF; |
j3 | 0:6b0161c3e440 | 436 | } |
j3 | 0:6b0161c3e440 | 437 | } |
j3 | 0:6b0161c3e440 | 438 | else |
j3 | 0:6b0161c3e440 | 439 | { |
j3 | 0:6b0161c3e440 | 440 | for(uint8_t idx = 0; idx < 8; idx++) |
j3 | 0:6b0161c3e440 | 441 | { |
j3 | 0:6b0161c3e440 | 442 | display_buff[idx + DISPLAY_BUFF_START] = 0xFF; |
j3 | 0:6b0161c3e440 | 443 | } |
j3 | 0:6b0161c3e440 | 444 | } |
j3 | 2:9fdd01cf0f88 | 445 | |
j3 | 2:9fdd01cf0f88 | 446 | if(buff_end < (quad * 8)) |
j3 | 2:9fdd01cf0f88 | 447 | { |
j3 | 2:9fdd01cf0f88 | 448 | buff_end = (quad * 8); |
j3 | 2:9fdd01cf0f88 | 449 | } |
j3 | 0:6b0161c3e440 | 450 | |
j3 | 0:6b0161c3e440 | 451 | p_display->device_all_on(quad); |
j3 | 0:6b0161c3e440 | 452 | } |
j3 | 0:6b0161c3e440 | 453 | |
j3 | 0:6b0161c3e440 | 454 | |
j3 | 0:6b0161c3e440 | 455 | //********************************************************************* |
j3 | 0:6b0161c3e440 | 456 | void quad_all_off(Max7219 *p_display, uint8_t quad) |
j3 | 0:6b0161c3e440 | 457 | { |
j3 | 0:6b0161c3e440 | 458 | if(quad > 1) |
j3 | 0:6b0161c3e440 | 459 | { |
j3 | 0:6b0161c3e440 | 460 | for(uint8_t idx = 0; idx < 8; idx++) |
j3 | 0:6b0161c3e440 | 461 | { |
j3 | 0:6b0161c3e440 | 462 | display_buff[((quad - 1)*8) + DISPLAY_BUFF_START + idx] = 0; |
j3 | 0:6b0161c3e440 | 463 | } |
j3 | 0:6b0161c3e440 | 464 | } |
j3 | 0:6b0161c3e440 | 465 | else |
j3 | 0:6b0161c3e440 | 466 | { |
j3 | 0:6b0161c3e440 | 467 | for(uint8_t idx = 0; idx < 8; idx++) |
j3 | 0:6b0161c3e440 | 468 | { |
j3 | 0:6b0161c3e440 | 469 | display_buff[idx + DISPLAY_BUFF_START] = 0; |
j3 | 0:6b0161c3e440 | 470 | } |
j3 | 0:6b0161c3e440 | 471 | } |
j3 | 2:9fdd01cf0f88 | 472 | |
j3 | 2:9fdd01cf0f88 | 473 | //is buff_end in the quad? |
j3 | 2:9fdd01cf0f88 | 474 | if((((quad - 1) * 8) < buff_end) && ((quad * 8) > buff_end)) |
j3 | 2:9fdd01cf0f88 | 475 | { |
j3 | 2:9fdd01cf0f88 | 476 | buff_end = ((quad - 1) * 8); |
j3 | 2:9fdd01cf0f88 | 477 | } |
j3 | 2:9fdd01cf0f88 | 478 | //leave it alone otherwise |
j3 | 0:6b0161c3e440 | 479 | |
j3 | 0:6b0161c3e440 | 480 | p_display->device_all_off(quad); |
j3 | 0:6b0161c3e440 | 481 | } |
j3 | 0:6b0161c3e440 | 482 | |
j3 | 0:6b0161c3e440 | 483 | |
j3 | 0:6b0161c3e440 | 484 | //********************************************************************* |
j3 | 0:6b0161c3e440 | 485 | void all_on(Max7219 *p_display) |
j3 | 0:6b0161c3e440 | 486 | { |
j3 | 2:9fdd01cf0f88 | 487 | for(uint16_t idx = 0; idx < 32; idx++) |
j3 | 0:6b0161c3e440 | 488 | { |
j3 | 0:6b0161c3e440 | 489 | display_buff[idx] = 0xFF; |
j3 | 0:6b0161c3e440 | 490 | } |
j3 | 2:9fdd01cf0f88 | 491 | |
j3 | 2:9fdd01cf0f88 | 492 | if(buff_end < 32) |
j3 | 2:9fdd01cf0f88 | 493 | { |
j3 | 2:9fdd01cf0f88 | 494 | buff_end = 32; |
j3 | 2:9fdd01cf0f88 | 495 | } |
j3 | 0:6b0161c3e440 | 496 | |
j3 | 0:6b0161c3e440 | 497 | p_display->display_all_on(); |
j3 | 0:6b0161c3e440 | 498 | } |
j3 | 0:6b0161c3e440 | 499 | |
j3 | 0:6b0161c3e440 | 500 | |
j3 | 0:6b0161c3e440 | 501 | //********************************************************************* |
j3 | 0:6b0161c3e440 | 502 | void all_off(Max7219 *p_display) |
j3 | 0:6b0161c3e440 | 503 | { |
j3 | 2:9fdd01cf0f88 | 504 | for(uint16_t idx = 0; idx < 32; idx++) |
j3 | 0:6b0161c3e440 | 505 | { |
j3 | 0:6b0161c3e440 | 506 | display_buff[idx] = 0; |
j3 | 0:6b0161c3e440 | 507 | } |
j3 | 2:9fdd01cf0f88 | 508 | |
j3 | 2:9fdd01cf0f88 | 509 | if(buff_end < 32) |
j3 | 2:9fdd01cf0f88 | 510 | { |
j3 | 2:9fdd01cf0f88 | 511 | buff_end = 0; |
j3 | 2:9fdd01cf0f88 | 512 | } |
j3 | 0:6b0161c3e440 | 513 | |
j3 | 0:6b0161c3e440 | 514 | p_display->display_all_off(); |
j3 | 0:6b0161c3e440 | 515 | } |
j3 | 0:6b0161c3e440 | 516 | |
j3 | 0:6b0161c3e440 | 517 | |
j3 | 0:6b0161c3e440 | 518 | //********************************************************************* |
j3 | 0:6b0161c3e440 | 519 | void demo(Max7219 *display, max7219_configuration_t display_config, bool endless_loop) |
j3 | 0:6b0161c3e440 | 520 | { |
j3 | 0:6b0161c3e440 | 521 | uint8_t position = 1; |
j3 | 0:6b0161c3e440 | 522 | uint8_t idx = 0; |
j3 | 0:6b0161c3e440 | 523 | |
j3 | 0:6b0161c3e440 | 524 | do |
j3 | 0:6b0161c3e440 | 525 | { |
j3 | 0:6b0161c3e440 | 526 | all_off(display); |
j3 | 0:6b0161c3e440 | 527 | |
j3 | 0:6b0161c3e440 | 528 | if(position > 25) |
j3 | 0:6b0161c3e440 | 529 | { |
j3 | 0:6b0161c3e440 | 530 | position = 1; |
j3 | 0:6b0161c3e440 | 531 | } |
j3 | 0:6b0161c3e440 | 532 | printf("\nPosition = %d\n", position); |
j3 | 0:6b0161c3e440 | 533 | |
j3 | 0:6b0161c3e440 | 534 | for(idx = 0x20; idx < 0x7F; idx++) |
j3 | 0:6b0161c3e440 | 535 | { |
j3 | 0:6b0161c3e440 | 536 | print_char(display, position, (char) idx); |
j3 | 0:6b0161c3e440 | 537 | wait(0.25); |
j3 | 0:6b0161c3e440 | 538 | } |
j3 | 0:6b0161c3e440 | 539 | position = (position + 8); |
j3 | 0:6b0161c3e440 | 540 | |
j3 | 0:6b0161c3e440 | 541 | all_on(display); |
j3 | 0:6b0161c3e440 | 542 | |
j3 | 0:6b0161c3e440 | 543 | for(idx = 0; idx < 16; idx++) |
j3 | 0:6b0161c3e440 | 544 | { |
j3 | 0:6b0161c3e440 | 545 | display_config.intensity = 15 - idx; |
j3 | 0:6b0161c3e440 | 546 | display->init_display(display_config); |
j3 | 0:6b0161c3e440 | 547 | wait_ms(50); |
j3 | 0:6b0161c3e440 | 548 | } |
j3 | 0:6b0161c3e440 | 549 | |
j3 | 0:6b0161c3e440 | 550 | for(idx = 0; idx < 16; idx++) |
j3 | 0:6b0161c3e440 | 551 | { |
j3 | 0:6b0161c3e440 | 552 | display_config.intensity = idx; |
j3 | 0:6b0161c3e440 | 553 | display->init_display(display_config); |
j3 | 0:6b0161c3e440 | 554 | wait_ms(100); |
j3 | 0:6b0161c3e440 | 555 | } |
j3 | 0:6b0161c3e440 | 556 | |
j3 | 0:6b0161c3e440 | 557 | wait_ms(100); |
j3 | 0:6b0161c3e440 | 558 | all_off(display); |
j3 | 0:6b0161c3e440 | 559 | wait_ms(100); |
j3 | 0:6b0161c3e440 | 560 | |
j3 | 0:6b0161c3e440 | 561 | quad_all_on(display, 1); |
j3 | 0:6b0161c3e440 | 562 | wait_ms(500); |
j3 | 0:6b0161c3e440 | 563 | shift_display_right(display, 32, 100); |
j3 | 0:6b0161c3e440 | 564 | shift_display_left(display, 32, 100); |
j3 | 0:6b0161c3e440 | 565 | all_off(display); |
j3 | 0:6b0161c3e440 | 566 | wait_ms(100); |
j3 | 0:6b0161c3e440 | 567 | |
j3 | 0:6b0161c3e440 | 568 | print_string(display, 1, "Maxim"); |
j3 | 0:6b0161c3e440 | 569 | wait_ms(100); |
j3 | 0:6b0161c3e440 | 570 | shift_display_right(display, 32, 100); |
j3 | 0:6b0161c3e440 | 571 | shift_display_left(display, 32, 100); |
j3 | 0:6b0161c3e440 | 572 | wait_ms(100); |
j3 | 0:6b0161c3e440 | 573 | } |
j3 | 0:6b0161c3e440 | 574 | while(endless_loop); |
j3 | 0:6b0161c3e440 | 575 | } |
j3 | 0:6b0161c3e440 | 576 | |
j3 | 0:6b0161c3e440 | 577 | |
j3 | 0:6b0161c3e440 | 578 | //********************************************************************* |
j3 | 0:6b0161c3e440 | 579 | void endless_scroll_display(Max7219 *display, uint32_t scroll_right) |
j3 | 0:6b0161c3e440 | 580 | { |
j3 | 0:6b0161c3e440 | 581 | if(scroll_right) |
j3 | 0:6b0161c3e440 | 582 | { |
j3 | 0:6b0161c3e440 | 583 | printf("\nScrolling Right\n"); |
j3 | 0:6b0161c3e440 | 584 | while(1) |
j3 | 0:6b0161c3e440 | 585 | { |
j3 | 0:6b0161c3e440 | 586 | shift_display_right(display, 1, 100); |
j3 | 0:6b0161c3e440 | 587 | } |
j3 | 0:6b0161c3e440 | 588 | } |
j3 | 0:6b0161c3e440 | 589 | else |
j3 | 0:6b0161c3e440 | 590 | { |
j3 | 0:6b0161c3e440 | 591 | printf("\nScrolling Left\n"); |
j3 | 0:6b0161c3e440 | 592 | while(1) |
j3 | 0:6b0161c3e440 | 593 | { |
j3 | 0:6b0161c3e440 | 594 | shift_display_left(display, 1, 100); |
j3 | 0:6b0161c3e440 | 595 | } |
j3 | 0:6b0161c3e440 | 596 | } |
j3 | 0:6b0161c3e440 | 597 | } |
j3 | 0:6b0161c3e440 | 598 | |
j3 | 0:6b0161c3e440 | 599 | |
j3 | 0:6b0161c3e440 | 600 | //********************************************************************* |
j3 | 0:6b0161c3e440 | 601 | uint32_t print_menu(void) |
j3 | 0:6b0161c3e440 | 602 | { |
j3 | 0:6b0161c3e440 | 603 | uint32_t user_input; |
j3 | 0:6b0161c3e440 | 604 | |
j3 | 0:6b0161c3e440 | 605 | printf("\nPlease select an option below:\n"); |
j3 | 0:6b0161c3e440 | 606 | printf("%t1. Set Brightness\n"); |
j3 | 0:6b0161c3e440 | 607 | printf("%t2. Print a characther to given position\n"); |
j3 | 0:6b0161c3e440 | 608 | printf("%t3. Print a string to position\n");//TODO fix this case |
j3 | 0:6b0161c3e440 | 609 | printf("%t4. Shift display given number of position and direction\n"); //TODO fix this case |
j3 | 0:6b0161c3e440 | 610 | printf("%t5. Clear display\n"); |
j3 | 0:6b0161c3e440 | 611 | printf("%t6. Run the Demo Rotuine\n"); |
j3 | 0:6b0161c3e440 | 612 | printf("%t7. Run the Demo Rotuine In Endless Loop\n"); |
j3 | 0:6b0161c3e440 | 613 | printf("%t8. Scroll Display In Endless Loop, left or right\n"); |
j3 | 0:6b0161c3e440 | 614 | printf("%t9. Quit\n\n"); |
j3 | 0:6b0161c3e440 | 615 | |
j3 | 0:6b0161c3e440 | 616 | user_input = get_user_input(NULL, 9); |
j3 | 0:6b0161c3e440 | 617 | |
j3 | 0:6b0161c3e440 | 618 | return(user_input); |
j3 | 0:6b0161c3e440 | 619 | } |
j3 | 0:6b0161c3e440 | 620 | |
j3 | 0:6b0161c3e440 | 621 | |
j3 | 0:6b0161c3e440 | 622 | //********************************************************************* |
j3 | 0:6b0161c3e440 | 623 | uint32_t get_user_input(char *msg, uint32_t max_val) |
j3 | 0:6b0161c3e440 | 624 | { |
j3 | 0:6b0161c3e440 | 625 | uint32_t user_input; |
j3 | 0:6b0161c3e440 | 626 | |
j3 | 0:6b0161c3e440 | 627 | do |
j3 | 0:6b0161c3e440 | 628 | { |
j3 | 0:6b0161c3e440 | 629 | printf(msg); |
j3 | 0:6b0161c3e440 | 630 | |
j3 | 0:6b0161c3e440 | 631 | //get user input |
j3 | 0:6b0161c3e440 | 632 | fgets(str, MAX_STRING_LENGTH, stdin); |
j3 | 0:6b0161c3e440 | 633 | |
j3 | 0:6b0161c3e440 | 634 | //Remove trailing newline and CR, if there. |
j3 | 0:6b0161c3e440 | 635 | if((strlen(str) > 0 ) && (str[strlen(str) - 1] == 0x0A) && (str[strlen(str) - 2] == 0x0D)) |
j3 | 0:6b0161c3e440 | 636 | { |
j3 | 0:6b0161c3e440 | 637 | str[strlen(str) - 1] = '\0'; |
j3 | 0:6b0161c3e440 | 638 | str[strlen(str) - 1] = '\0'; |
j3 | 0:6b0161c3e440 | 639 | } |
j3 | 0:6b0161c3e440 | 640 | |
j3 | 0:6b0161c3e440 | 641 | user_input = strtoul(str, NULL, 0); |
j3 | 0:6b0161c3e440 | 642 | |
j3 | 0:6b0161c3e440 | 643 | printf("\nYou entered = %d\n", user_input); |
j3 | 0:6b0161c3e440 | 644 | |
j3 | 0:6b0161c3e440 | 645 | if(user_input > max_val) |
j3 | 0:6b0161c3e440 | 646 | { |
j3 | 0:6b0161c3e440 | 647 | printf("\nOut of range\n"); |
j3 | 0:6b0161c3e440 | 648 | } |
j3 | 0:6b0161c3e440 | 649 | |
j3 | 0:6b0161c3e440 | 650 | } |
j3 | 0:6b0161c3e440 | 651 | while(user_input > max_val); |
j3 | 0:6b0161c3e440 | 652 | |
j3 | 0:6b0161c3e440 | 653 | return(user_input); |
j3 | 0:6b0161c3e440 | 654 | } |
j3 | 0:6b0161c3e440 | 655 | |
j3 | 0:6b0161c3e440 | 656 | |
j3 | 0:6b0161c3e440 | 657 | //********************************************************************* |
j3 | 0:6b0161c3e440 | 658 | char get_user_char(char *msg) |
j3 | 0:6b0161c3e440 | 659 | { |
j3 | 0:6b0161c3e440 | 660 | |
j3 | 0:6b0161c3e440 | 661 | do |
j3 | 0:6b0161c3e440 | 662 | { |
j3 | 0:6b0161c3e440 | 663 | printf(msg); |
j3 | 0:6b0161c3e440 | 664 | |
j3 | 0:6b0161c3e440 | 665 | //get user input |
j3 | 2:9fdd01cf0f88 | 666 | fgets(str, 4, stdin); |
j3 | 0:6b0161c3e440 | 667 | |
j3 | 0:6b0161c3e440 | 668 | //Remove trailing newline and CR, if there. |
j3 | 0:6b0161c3e440 | 669 | if((strlen(str) > 0 ) && (str[strlen(str) - 1] == 0x0A) && (str[strlen(str) - 2] == 0x0D)) |
j3 | 0:6b0161c3e440 | 670 | { |
j3 | 0:6b0161c3e440 | 671 | str[strlen(str) - 1] = '\0'; |
j3 | 0:6b0161c3e440 | 672 | str[strlen(str) - 1] = '\0'; |
j3 | 0:6b0161c3e440 | 673 | } |
j3 | 0:6b0161c3e440 | 674 | |
j3 | 0:6b0161c3e440 | 675 | printf("\nYou entered = %c\n", str[0]); |
j3 | 0:6b0161c3e440 | 676 | |
j3 | 0:6b0161c3e440 | 677 | if((str[0] < 0x20) || (str[0] > 0x7E)) |
j3 | 0:6b0161c3e440 | 678 | { |
j3 | 0:6b0161c3e440 | 679 | printf("\nOut of range\n"); |
j3 | 0:6b0161c3e440 | 680 | } |
j3 | 0:6b0161c3e440 | 681 | } |
j3 | 0:6b0161c3e440 | 682 | while((str[0] < 0x20) || (str[0] > 0x7E)); |
j3 | 0:6b0161c3e440 | 683 | |
j3 | 0:6b0161c3e440 | 684 | return(str[0]); |
j3 | 0:6b0161c3e440 | 685 | } |
j3 | 0:6b0161c3e440 | 686 | |
j3 | 0:6b0161c3e440 | 687 | |
j3 | 0:6b0161c3e440 | 688 | //********************************************************************* |
j3 | 0:6b0161c3e440 | 689 | char * get_user_string(char *msg) |
j3 | 0:6b0161c3e440 | 690 | { |
j3 | 0:6b0161c3e440 | 691 | printf(msg); |
j3 | 0:6b0161c3e440 | 692 | //get user input |
j3 | 0:6b0161c3e440 | 693 | fgets(str, MAX_STRING_LENGTH, stdin); |
j3 | 0:6b0161c3e440 | 694 | //Remove trailing newline and CR, if there. |
j3 | 0:6b0161c3e440 | 695 | if((strlen(str) > 0 ) && (str[strlen(str) - 1] == 0x0A) && (str[strlen(str) - 2] == 0x0D)) |
j3 | 0:6b0161c3e440 | 696 | { |
j3 | 0:6b0161c3e440 | 697 | str[strlen(str) - 1] = '\0'; |
j3 | 0:6b0161c3e440 | 698 | str[strlen(str) - 1] = '\0'; |
j3 | 0:6b0161c3e440 | 699 | } |
j3 | 0:6b0161c3e440 | 700 | |
j3 | 0:6b0161c3e440 | 701 | return(str); |
j3 | 0:6b0161c3e440 | 702 | } |
j3 | 0:6b0161c3e440 | 703 |