00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "libraryitem.h"
00012 #include "logic.h"
00013 #include "matrixdisplaydriver.h"
00014
00015 #include <klocale.h>
00016 #include <qpainter.h>
00017 #include <qstring.h>
00018
00019 #include <cassert>
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 static char characterMap[256][5] = {
00034 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00035 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00036 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00037 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00038 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00039 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00040 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00041 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00042 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00043 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00044 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00045 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00046 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00047 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00048 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00049 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00050 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00051 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00052 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00053 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00054 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00055 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00056 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00057 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00058 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00059 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00060 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00061 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00062 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00063 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00064 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00065 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00066 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00067 { 0x00, 0x00, 0x7d, 0x00, 0x00 },
00068 { 0x00, 0x70, 0x00, 0x70, 0x00 },
00069 { 0x14, 0x7f, 0x14, 0x7f, 0x14 },
00070 { 0x12, 0x2a, 0x7f, 0x2a, 0x24 },
00071 { 0x62, 0x64, 0x08, 0x13, 0x23 },
00072 { 0x36, 0x49, 0x55, 0x22, 0x05 },
00073 { 0x00, 0x50, 0x60, 0x00, 0x00 },
00074 { 0x00, 0x1c, 0x22, 0x41, 0x00 },
00075 { 0x00, 0x41, 0x22, 0x1c, 0x00 },
00076 { 0x14, 0x08, 0x3e, 0x08, 0x14 },
00077 { 0x08, 0x08, 0x3e, 0x08, 0x08 },
00078 { 0x00, 0x05, 0x06, 0x00, 0x00 },
00079 { 0x08, 0x08, 0x08, 0x08, 0x08 },
00080 { 0x00, 0x03, 0x03, 0x00, 0x00 },
00081 { 0x02, 0x04, 0x08, 0x10, 0x20 },
00082 { 0x3e, 0x45, 0x49, 0x51, 0x3e },
00083 { 0x00, 0x21, 0x7f, 0x01, 0x00 },
00084 { 0x21, 0x43, 0x45, 0x49, 0x31 },
00085 { 0x42, 0x41, 0x51, 0x69, 0x46 },
00086 { 0x0c, 0x14, 0x24, 0x7f, 0x04 },
00087 { 0x72, 0x51, 0x51, 0x51, 0x4e },
00088 { 0x1e, 0x29, 0x49, 0x49, 0x06 },
00089 { 0x40, 0x47, 0x48, 0x50, 0x60 },
00090 { 0x36, 0x49, 0x49, 0x49, 0x36 },
00091 { 0x30, 0x49, 0x49, 0x4a, 0x3c },
00092 { 0x00, 0x36, 0x36, 0x00, 0x00 },
00093 { 0x00, 0x35, 0x36, 0x00, 0x00 },
00094 { 0x08, 0x14, 0x22, 0x41, 0x00 },
00095 { 0x14, 0x14, 0x14, 0x14, 0x14 },
00096 { 0x41, 0x22, 0x14, 0x08, 0x00 },
00097 { 0x20, 0x40, 0x45, 0x48, 0x30 },
00098 { 0x26, 0x49, 0x4f, 0x41, 0x3e },
00099 { 0x3f, 0x44, 0x44, 0x44, 0x3f },
00100 { 0x7f, 0x49, 0x49, 0x49, 0x36 },
00101 { 0x3e, 0x41, 0x41, 0x41, 0x22 },
00102 { 0x7f, 0x41, 0x41, 0x41, 0x3e },
00103 { 0x7f, 0x49, 0x49, 0x49, 0x41 },
00104 { 0x7f, 0x48, 0x48, 0x48, 0x40 },
00105 { 0x3e, 0x41, 0x49, 0x49, 0x2f },
00106 { 0x7f, 0x08, 0x08, 0x08, 0x7f },
00107 { 0x00, 0x41, 0x7f, 0x41, 0x00 },
00108 { 0x02, 0x01, 0x41, 0x7e, 0x40 },
00109 { 0x7f, 0x08, 0x14, 0x22, 0x41 },
00110 { 0x7f, 0x01, 0x01, 0x01, 0x01 },
00111 { 0x7f, 0x40, 0x20, 0x40, 0x7f },
00112 { 0x7f, 0x10, 0x08, 0x04, 0x7f },
00113 { 0x3e, 0x41, 0x41, 0x41, 0x3e },
00114 { 0x7f, 0x48, 0x48, 0x48, 0x30 },
00115 { 0x3e, 0x41, 0x45, 0x42, 0x3d },
00116 { 0x7f, 0x48, 0x4c, 0x4a, 0x31 },
00117 { 0x31, 0x49, 0x49, 0x49, 0x46 },
00118 { 0x40, 0x40, 0x7f, 0x40, 0x40 },
00119 { 0x7e, 0x01, 0x01, 0x01, 0x7e },
00120 { 0x7c, 0x02, 0x01, 0x02, 0x7c },
00121 { 0x7e, 0x01, 0x0e, 0x01, 0x7e },
00122 { 0x63, 0x14, 0x08, 0x14, 0x63 },
00123 { 0x70, 0x08, 0x07, 0x08, 0x70 },
00124 { 0x43, 0x45, 0x49, 0x51, 0x61 },
00125 { 0x00, 0x7f, 0x41, 0x41, 0x00 },
00126 { 0x54, 0x34, 0x1f, 0x34, 0x54 },
00127 { 0x00, 0x41, 0x41, 0x7f, 0x00 },
00128 { 0x10, 0x20, 0x40, 0x20, 0x10 },
00129 { 0x01, 0x01, 0x01, 0x01, 0x01 },
00130 { 0x00, 0x40, 0x20, 0x10, 0x00 },
00131 { 0x02, 0x15, 0x15, 0x15, 0x0f },
00132 { 0x7f, 0x09, 0x11, 0x11, 0x0e },
00133 { 0x0e, 0x11, 0x11, 0x11, 0x02 },
00134 { 0x0e, 0x11, 0x11, 0x09, 0x7f },
00135 { 0x0e, 0x15, 0x15, 0x15, 0x0c },
00136 { 0x08, 0x3f, 0x48, 0x40, 0x20 },
00137 { 0x30, 0x49, 0x49, 0x49, 0x7e },
00138 { 0x7f, 0x08, 0x10, 0x10, 0x0f },
00139 { 0x00, 0x11, 0x5f, 0x01, 0x00 },
00140 { 0x02, 0x01, 0x21, 0x7e, 0x00 },
00141 { 0x7f, 0x04, 0x0a, 0x11, 0x00 },
00142 { 0x00, 0x41, 0x7f, 0x01, 0x00 },
00143 { 0x1f, 0x10, 0x0c, 0x10, 0x0f },
00144 { 0x1f, 0x08, 0x10, 0x10, 0x0f },
00145 { 0x0e, 0x11, 0x11, 0x11, 0x0e },
00146 { 0x1f, 0x14, 0x14, 0x14, 0x08 },
00147 { 0x08, 0x14, 0x14, 0x0c, 0x1f },
00148 { 0x1f, 0x08, 0x10, 0x10, 0x08 },
00149 { 0x09, 0x15, 0x15, 0x15, 0x12 },
00150 { 0x20, 0x7e, 0x21, 0x01, 0x02 },
00151 { 0x1e, 0x01, 0x01, 0x02, 0x1f },
00152 { 0x1c, 0x02, 0x01, 0x02, 0x1c },
00153 { 0x1e, 0x01, 0x06, 0x01, 0x1e },
00154 { 0x11, 0x0a, 0x04, 0x0a, 0x11 },
00155 { 0x18, 0x05, 0x05, 0x05, 0x1e },
00156 { 0x11, 0x13, 0x15, 0x19, 0x11 },
00157 { 0x00, 0x08, 0x36, 0x41, 0x00 },
00158 { 0x00, 0x00, 0x7f, 0x00, 0x00 },
00159 { 0x00, 0x41, 0x36, 0x08, 0x00 },
00160 { 0x08, 0x08, 0x2a, 0x1c, 0x08 },
00161 { 0x08, 0x1c, 0x2a, 0x08, 0x08 },
00162 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00163 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00164 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00165 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00166 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00167 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00168 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00169 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00170 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00171 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00172 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00173 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00174 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00175 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00176 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00177 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00178 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00179 { 0x07, 0x05, 0x07, 0x00, 0x00 },
00180 { 0x00, 0x00, 0x78, 0x40, 0x40 },
00181 { 0x01, 0x01, 0x0f, 0x00, 0x00 },
00182 { 0x04, 0x02, 0x01, 0x00, 0x00 },
00183 { 0x00, 0x0c, 0x0c, 0x00, 0x00 },
00184 { 0x28, 0x28, 0x29, 0x2a, 0x3c },
00185 { 0x10, 0x11, 0x16, 0x14, 0x18 },
00186 { 0x02, 0x04, 0x0f, 0x10, 0x00 },
00187 { 0x0c, 0x08, 0x19, 0x09, 0x0e },
00188 { 0x09, 0x09, 0x0f, 0x09, 0x09 },
00189 { 0x09, 0x0a, 0x0c, 0x1f, 0x08 },
00190 { 0x08, 0x1f, 0x08, 0x0a, 0x0c },
00191 { 0x01, 0x09, 0x09, 0x0f, 0x01 },
00192 { 0x15, 0x15, 0x15, 0x1f, 0x00 },
00193 { 0x0c, 0x00, 0x0d, 0x01, 0x0e },
00194 { 0x04, 0x04, 0x04, 0x04, 0x04 },
00195 { 0x40, 0x41, 0x5e, 0x48, 0x70 },
00196 { 0x04, 0x08, 0x1f, 0x20, 0x40 },
00197 { 0x38, 0x20, 0x61, 0x22, 0x3c },
00198 { 0x11, 0x11, 0x1f, 0x11, 0x11 },
00199 { 0x22, 0x24, 0x28, 0x7f, 0x20 },
00200 { 0x21, 0x7e, 0x20, 0x21, 0x3e },
00201 { 0x28, 0x28, 0x7f, 0x28, 0x28 },
00202 { 0x08, 0x31, 0x21, 0x22, 0x3c },
00203 { 0x10, 0x60, 0x21, 0x3e, 0x20 },
00204 { 0x21, 0x21, 0x21, 0x21, 0x3f },
00205 { 0x20, 0x79, 0x22, 0x7c, 0x20 },
00206 { 0x29, 0x29, 0x01, 0x02, 0x1c },
00207 { 0x21, 0x22, 0x24, 0x2a, 0x31 },
00208 { 0x20, 0x7e, 0x21, 0x29, 0x31 },
00209 { 0x30, 0x09, 0x01, 0x02, 0x3c },
00210 { 0x08, 0x31, 0x29, 0x26, 0x3c },
00211 { 0x28, 0x29, 0x3e, 0x48, 0x08 },
00212 { 0x30, 0x00, 0x31, 0x02, 0x3c },
00213 { 0x10, 0x51, 0x5e, 0x50, 0x10 },
00214 { 0x00, 0x7f, 0x08, 0x04, 0x00 },
00215 { 0x11, 0x12, 0x7c, 0x10, 0x10 },
00216 { 0x01, 0x21, 0x21, 0x21, 0x01 },
00217 { 0x21, 0x2a, 0x24, 0x2a, 0x30 },
00218 { 0x22, 0x24, 0x6f, 0x34, 0x22 },
00219 { 0x00, 0x01, 0x02, 0x7c, 0x00 },
00220 { 0x0f, 0x00, 0x20, 0x10, 0x0f },
00221 { 0x7e, 0x11, 0x11, 0x11, 0x11 },
00222 { 0x20, 0x21, 0x21, 0x22, 0x3c },
00223 { 0x10, 0x20, 0x10, 0x08, 0x06 },
00224 { 0x26, 0x20, 0x7f, 0x20, 0x26 },
00225 { 0x20, 0x24, 0x22, 0x25, 0x38 },
00226 { 0x00, 0x2a, 0x2a, 0x2a, 0x01 },
00227 { 0x0e, 0x12, 0x22, 0x02, 0x07 },
00228 { 0x01, 0x0a, 0x04, 0x0a, 0x30 },
00229 { 0x28, 0x3e, 0x29, 0x29, 0x29 },
00230 { 0x10, 0x7f, 0x10, 0x14, 0x18 },
00231 { 0x01, 0x21, 0x21, 0x3f, 0x01 },
00232 { 0x29, 0x29, 0x29, 0x29, 0x3f },
00233 { 0x10, 0x50, 0x51, 0x52, 0x1c },
00234 { 0x78, 0x01, 0x02, 0x7c, 0x00 },
00235 { 0x1f, 0x00, 0x3f, 0x01, 0x06 },
00236 { 0x3f, 0x01, 0x02, 0x04, 0x08 },
00237 { 0x3f, 0x21, 0x21, 0x21, 0x3f },
00238 { 0x38, 0x20, 0x21, 0x22, 0x3c },
00239 { 0x21, 0x21, 0x01, 0x02, 0x0c },
00240 { 0x20, 0x10, 0x40, 0x20, 0x00 },
00241 { 0x70, 0x50, 0x70, 0x00, 0x00 },
00242 { 0x0e, 0x11, 0x09, 0x06, 0x19 },
00243 { 0x02, 0x55, 0x15, 0x55, 0x0f },
00244 { 0x1f, 0x2a, 0x2a, 0x2a, 0x14 },
00245 { 0x0a, 0x15, 0x15, 0x11, 0x02 },
00246 { 0x3f, 0x02, 0x02, 0x04, 0x3e },
00247 { 0x0e, 0x11, 0x19, 0x15, 0x12 },
00248 { 0x0f, 0x12, 0x22, 0x22, 0x1c },
00249 { 0x1c, 0x22, 0x22, 0x22, 0x3f },
00250 { 0x02, 0x01, 0x1e, 0x10, 0x10 },
00251 { 0x20, 0x20, 0x00, 0x70, 0x00 },
00252 { 0x00, 0x00, 0x10, 0x5f, 0x00 },
00253 { 0x28, 0x10, 0x28, 0x00, 0x00 },
00254 { 0x18, 0x24, 0x7e, 0x24, 0x08 },
00255 { 0x14, 0x7f, 0x15, 0x01, 0x01 },
00256 { 0x1f, 0x48, 0x50, 0x50, 0x0f },
00257 { 0x0e, 0x51, 0x11, 0x51, 0x0e },
00258 { 0x3f, 0x12, 0x22, 0x22, 0x1c },
00259 { 0x1c, 0x22, 0x22, 0x12, 0x3f },
00260 { 0x3c, 0x52, 0x52, 0x52, 0x3c },
00261 { 0x03, 0x05, 0x02, 0x05, 0x06 },
00262 { 0x1a, 0x26, 0x20, 0x26, 0x1a },
00263 { 0x1e, 0x41, 0x01, 0x42, 0x1f },
00264 { 0x63, 0x55, 0x49, 0x41, 0x41 },
00265 { 0x22, 0x3c, 0x20, 0x3e, 0x22 },
00266 { 0x51, 0x4a, 0x44, 0x4a, 0x51 },
00267 { 0x3c, 0x02, 0x02, 0x02, 0x3f },
00268 { 0x28, 0x28, 0x3e, 0x28, 0x48 },
00269 { 0x22, 0x3c, 0x28, 0x28, 0x2e },
00270 { 0x3e, 0x28, 0x38, 0x28, 0x3e },
00271 { 0x04, 0x04, 0x15, 0x04, 0x04 },
00272 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00273 { 0x7f, 0x7f, 0x7f, 0x7f, 0x7f },
00274 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00275 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00276 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00277 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00278 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00279 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00280 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00281 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00282 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00283 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00284 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00285 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00286 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00287 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00288 { 0x00, 0x00, 0x00, 0x00, 0x00 },
00289 { 0x00, 0x00, 0x00, 0x00, 0x00 }
00290 };
00291
00292 inline static bool displayBit(unsigned value, unsigned row, unsigned column ) {
00293 assert( value < 256 );
00294 assert( row < 7 );
00295 assert( column < 5 );
00296 return characterMap[value][column] & (1 << row);
00297 }
00298
00299 Item* MatrixDisplayDriver::construct(ItemDocument *itemDocument, bool newItem, const char *id )
00300 {
00301 return new MatrixDisplayDriver( (ICNDocument*)itemDocument, newItem, id );
00302 }
00303
00304 LibraryItem *MatrixDisplayDriver::libraryItem()
00305 {
00306 return new LibraryItem(
00307 "ec/matrix_display_driver",
00308 i18n("Matrix Display Driver"),
00309 i18n("Integrated Circuits"),
00310 "ic2.png",
00311 LibraryItem::lit_component,
00312 MatrixDisplayDriver::construct );
00313 }
00314
00315 MatrixDisplayDriver::MatrixDisplayDriver( ICNDocument *icnDocument, bool newItem, const char *id )
00316 : Component( icnDocument, newItem, id ? id : "Matrix Display Driver" )
00317 {
00318 m_name = i18n("Matrix Display Driver");
00319
00320 m_prevCol = 0;
00321 m_nextCol = 0;
00322 m_scanCount = 2;
00323
00324 createProperty( "diode-configuration", Variant::Type::Select );
00325 property("diode-configuration")->setCaption( i18n("Configuration") );
00326 property("diode-configuration")->setAllowed( QStringList::split(',',"Row Cathode,Column Cathode") );
00327 property("diode-configuration")->setValue("Row Cathode");
00328 property("diode-configuration")->setAdvanced(true);
00329
00330 QStringList pins = QStringList::split( ',', "D0,D1,D2,D3,D4,D5,D6,D7,,,,,,C4,C3,C2,C1,C0,,R0,R1,R2,R3,R4,R5,R6", true );
00331 initDIPSymbol( pins, 64 );
00332 initDIP(pins);
00333
00334 m_pValueLogic.resize(8, 0);
00335 for ( unsigned i = 0; i < 8; ++i )
00336 m_pValueLogic[i] = createLogicIn( ecNodeWithID("D"+QString::number(i)) );
00337
00338 m_pRowLogic.resize(7, 0);
00339 for ( unsigned i = 0; i < 7; ++i ) {
00340 m_pRowLogic[i] = createLogicOut( ecNodeWithID("R"+QString::number(i)), false );
00341 m_pRowLogic[i]->setOutputLowConductance( 1.0 );
00342 m_pRowLogic[i]->setOutputHighVoltage(5.0);
00343 }
00344
00345 m_pColLogic.resize(5, 0);
00346 for ( unsigned i = 0; i < 5; ++i ) {
00347 m_pColLogic[i] = createLogicOut( ecNodeWithID("C"+QString::number(i)), false );
00348 m_pColLogic[i]->setOutputHighVoltage(5.0);
00349 }
00350 }
00351
00352 MatrixDisplayDriver::~MatrixDisplayDriver()
00353 {
00354 }
00355
00356 void MatrixDisplayDriver::stepNonLogic()
00357 {
00358 if(++m_scanCount < 5 ) return;
00359
00360 m_scanCount = 0;
00361
00362 m_pColLogic[m_prevCol]->setHigh(false);
00363 m_pColLogic[m_nextCol]->setHigh(true);
00364
00365 unsigned value = 0;
00366 for(unsigned i = 0; i < 8; ++i )
00367 value |= ( m_pValueLogic[i]->isHigh() ) ? (1 << i) : 0;
00368
00369 for(unsigned row = 0; row < 7; row++ ) {
00370 m_pRowLogic[row]->setHigh(!displayBit(value, row, m_nextCol));
00371 }
00372
00373 m_prevCol = m_nextCol;
00374
00375 m_nextCol++;
00376 if(m_nextCol >= 5 ) m_nextCol = 0;
00377 }
00378