summaryrefslogtreecommitdiff
path: root/device-functions.c
diff options
context:
space:
mode:
authorMichael J. Chudobiak <mjc@avtechpulse.com>2014-08-13 15:43:49 -0400
committerMichael J. Chudobiak <mjc@avtechpulse.com>2014-08-13 15:43:49 -0400
commit6959b9dadb91c32c2582afe0b4abaa040af53504 (patch)
treeb105c8016878b8fd7b3dfc86e1bcbb3e80d28d5b /device-functions.c
parent2691b7441d1a8cad7ccb23b766180d9f5176b567 (diff)
first attempt at better AVRQ amplitude handling
Diffstat (limited to 'device-functions.c')
-rw-r--r--device-functions.c73
1 files changed, 68 insertions, 5 deletions
diff --git a/device-functions.c b/device-functions.c
index 263758d..4bff9f5 100644
--- a/device-functions.c
+++ b/device-functions.c
@@ -89,11 +89,7 @@ void Main_Rst (void)
globals.ChannelState[i].pw=0.0;
}
- if (globals.Flash.ampl_min_max_only[i] || (globals.Flash.min_ampl[i] > 0.0)) {
- globals.ChannelState[i].amplitude = globals.Flash.min_ampl[i];
- } else {
- globals.ChannelState[i].amplitude=0.0;
- }
+ globals.ChannelState[i].amplitude = rst_fixed_ampl_point(i);
globals.ChannelState[i].offset=0.0;
globals.ChannelState[i].zout=globals.Flash.zout_min[i];
@@ -4930,3 +4926,70 @@ static void set_shiftreg_bits(int shiftreg, int start_at_bit, int numbits, int v
// printf ("out %lx\n", globals.Registers.shift_reg_out[shiftreg]);
}
+
+int number_of_fixed_ampl_points(int channel)
+{
+ int i, count;
+ count = 0;
+
+ for (i=0; i<max_fixed_ampl_points; i++) {
+ if (fabs(globals.Flash.fixed_ampl_points[channel][i]) > 0.0) {
+ count = i+1;
+ }
+ }
+
+ return count;
+}
+
+
+float rst_fixed_ampl_point (int channel)
+{
+ // smallest positive value, or zero
+
+ int i, max, pos_count, neg_count;
+ pos_count = 0;
+ neg_count = 0;
+
+ float smallest_pos, smallest_neg;
+ smallest_pos = 1e9;
+ smallest_neg = -1e9;
+
+ max = number_of_fixed_ampl_points(channel);
+
+ // any zeroes?
+ for (i=0; i<max; i++) {
+ if (globals.Flash.fixed_ampl_points[channel][i] >= 0.0 ) {
+ ++pos_count;
+ if (globals.Flash.fixed_ampl_points[channel][i] < smallest_pos) {
+ smallest_pos = globals.Flash.fixed_ampl_points[channel][i];
+ }
+ } else if (globals.Flash.fixed_ampl_points[channel][i] < 0.0 ) {
+ ++neg_count;
+ if (globals.Flash.fixed_ampl_points[channel][i] > smallest_neg) {
+ smallest_neg = globals.Flash.fixed_ampl_points[channel][i];
+ }
+ }
+ }
+
+ if (pos_count > 0) {
+ return smallest_pos;
+ } else if (neg_count > 0) {
+ return smallest_neg;
+ } else {
+ return 0.0;
+ }
+}
+
+
+gboolean fixed_ampl_ok (int channel, float use_ampl) {
+
+ int i,max;
+ max = number_of_fixed_ampl_points(channel);
+
+ for (i=0; i<max; i++) {
+ if (fabs(use_ampl-globals.Flash.fixed_ampl_points[channel][i])<globals.Flash.ampl_zero_equiv[channel])
+ return TRUE;
+ }
+
+ return FALSE;
+}