-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseg_hfm.c
151 lines (131 loc) · 5.92 KB
/
seg_hfm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/* mehPL:
* This is Open Source, but NOT GPL. I call it mehPL.
* I'm not too fond of long licenses at the top of the file.
* Please see the bottom.
* Enjoy!
*/
//seg_hfm.c (uses the rowSegBuffer):
//Uses "High-Frequency Modulation" to display an interesting pattern...
// HFM is kinda like PWM. The idea is to have an output ON for
// a certain percentage of the time...
// In PWM, that's done by turning it on for a fraction of a cycle
// (the "width" of the pulse), then off for the remainder.
// In HFM, it's accomplished by knowing the fraction of time it should be
// on... (the "power"). The fractions are automatically reduced 5/10->1/2.
// e.g. if the on-time should be 1/100th of the time, it will be on
// during one update-period, and off for 99, then repeat.
// If the on-time should be 1/2 of the time, it will be on during one
// update, off during the next, on again, and so-on.
// If the on-time is some strange fraction, like 3/5, it will distribute
// the pulses accordingly (e.g. on, off, on, off, on, repeat)
// Thus, the output toggles as quickly as possible to achieve the desired
// power... thus "High-Frequency"
// (See _commonCode.../hfModulation/...)
// I've been using HFM in ways never originally intended: e.g. it can be
// used for smoothing lines between two distant points...
// It's used this way in "SEG_RACER" in order to use a low-resolution
// course in memory, and increase the resolution by knowing that there are
// a certain number of rows in which it has to get from point1 to point2
// so the "power" of the HFM is set to (p2-p1)/numRows.
// The nice thing about it, is it doesn't use any actual division (which
// is quite slow) because it knows that every point inbetween will be
// traversed.
// SEG_HFM visualizes that, and actually looks pretty cool. Like moire
// patterns, or magnetic-field-lines.
// Each row increases in power, essentially: rowNum/NUM_SEGMENTS
// (Experimenting with NUM_SEGMENTS is fun, in this case, just don't exceed
// the available memory, and keep in mind that there's a stack and stuff)
void segHFM_loadRow(uint16_t rowNum) {
segClear();
//Just some experimenting... 1024/3+16 seems to be the width...
// == 357 segments (Where does this come from?)
//Pixel Segments...
#define BORDER_PSEGS 1
#define SEGS_AVAILABLE (NUM_SEGMENTS-2)
#define PSEGS_AVAILABLE (NUM_PSEGS-BORDER_PSEGS*2)
#define HFM_PSEGS (PSEGS_AVAILABLE/SEGS_AVAILABLE)
#define HFM_PSEGS_REMAINDER (PSEGS_AVAILABLE%SEGS_AVAILABLE)
addSegfb(BORDER_PSEGS,_W);
hfm_t hfmThing;
hfm_setup(&hfmThing, (uint8_t)((uint32_t)rowNum*(uint32_t)SEGS_AVAILABLE/V_COUNT), SEGS_AVAILABLE);
hfm_t hfmColStretcher;
hfm_setup(&hfmColStretcher, HFM_PSEGS_REMAINDER, SEGS_AVAILABLE);
uint16_t pseg;
for(pseg=0; pseg<SEGS_AVAILABLE; pseg++)
{
if(hfm_nextOutput(&hfmThing))
addSegfb(HFM_PSEGS + hfm_nextOutput(&hfmColStretcher),_R);
else
addSegfb(HFM_PSEGS + hfm_nextOutput(&hfmColStretcher),_C);
}
//addSegfb(NUM_PSEGS-BORDER_PSEGS*2-SEGS_AVAILABLE*HFM_PSEGS, _M);
addSegfb(BORDER_PSEGS,_W);
segTerminate();
}
/* mehPL:
* I would love to believe in a world where licensing shouldn't be
* necessary; where people would respect others' work and wishes,
* and give credit where it's due.
* A world where those who find people's work useful would at least
* send positive vibes--if not an email.
* A world where we wouldn't have to think about the potential
* legal-loopholes that others may take advantage of.
*
* Until that world exists:
*
* This software and associated hardware design is free to use,
* modify, and even redistribute, etc. with only a few exceptions
* I've thought-up as-yet (this list may be appended-to, hopefully it
* doesn't have to be):
*
* 1) Please do not change/remove this licensing info.
* 2) Please do not change/remove others' credit/licensing/copyright
* info, where noted.
* 3) If you find yourself profiting from my work, please send me a
* beer, a trinket, or cash is always handy as well.
* (Please be considerate. E.G. if you've reposted my work on a
* revenue-making (ad-based) website, please think of the
* years and years of hard work that went into this!)
* 4) If you *intend* to profit from my work, you must get my
* permission, first.
* 5) No permission is given for my work to be used in Military, NSA,
* or other creepy-ass purposes. No exceptions. And if there's
* any question in your mind as to whether your project qualifies
* under this category, you must get my explicit permission.
*
* The open-sourced project this originated from is ~98% the work of
* the original author, except where otherwise noted.
* That includes the "commonCode" and makefiles.
* Thanks, of course, should be given to those who worked on the tools
* I've used: avr-dude, avr-gcc, gnu-make, vim, usb-tiny, and
* I'm certain many others.
* And, as well, to the countless coders who've taken time to post
* solutions to issues I couldn't solve, all over the internets.
*
*
* I'd love to hear of how this is being used, suggestions for
* improvements, etc!
*
* The creator of the original code and original hardware can be
* contacted at:
*
* EricWazHung At Gmail Dotcom
*
* This code's origin (and latest versions) can be found at:
*
* https://code.google.com/u/ericwazhung/
*
* The site associated with the original open-sourced project is at:
*
* https://sites.google.com/site/geekattempts/
*
* If any of that ever changes, I will be sure to note it here,
* and add a link at the pages above.
*
* This license added to the original file located at:
* /Users/meh/_avrProjects/LCDdirectLVDS/93-checkingProcessAgain/seg_hfm.c
*
* (Wow, that's a lot longer than I'd hoped).
*
* Enjoy!
*/