Commit 5f0cf293449863ee04f134715784d8a26c113b14
1 parent
9ba93c86
Some more Hantek::Control redesign
Showing
4 changed files
with
42 additions
and
81 deletions
openhantek/ChangeLog
| ... | ... | @@ -131,5 +131,8 @@ |
| 131 | 131 | * Redesign of Hantek::Control to make it easier to add support for new models |
| 132 | 132 | * Removed buggy destructor from GlGenerator, proper cleanup still missing |
| 133 | 133 | |
| 134 | -2011-11-16 Oliver Haag <oliver.haag@gmail.com> | |
| 134 | +2011-11-27 Oliver Haag <oliver.haag@gmail.com> | |
| 135 | 135 | * Bugfix: Copy-paste in Hantek::Control::setOffset, thanks to tinosnitso |
| 136 | + | |
| 137 | +2011-12-02 Oliver Haag <oliver.haag@gmail.com> | |
| 138 | +* Moved values needed to control gain into lists, initialized in connectDevice | ... | ... |
openhantek/src/hantek/control.cpp
| ... | ... | @@ -52,16 +52,13 @@ namespace Hantek { |
| 52 | 52 | this->specification.command.values.offsetLimits = VALUE_OFFSETLIMITS; |
| 53 | 53 | this->specification.command.values.voltageLimits = (ControlValue) -1; |
| 54 | 54 | |
| 55 | - this->specification.gainSteps << 0.08 << 0.16 << 0.40 << 0.80 << 1.60 | |
| 56 | - << 4.00 << 8.0 << 16.0 << 40.0; | |
| 57 | - | |
| 58 | 55 | this->specification.samplerate.single.base = 50e6; |
| 59 | 56 | this->specification.samplerate.single.max = 50e6; |
| 60 | 57 | this->specification.samplerate.multi.base = 100e6; |
| 61 | 58 | this->specification.samplerate.multi.max = 100e6; |
| 62 | 59 | |
| 63 | 60 | for(unsigned int channel = 0; channel < HANTEK_CHANNELS; channel++) { |
| 64 | - for(unsigned int gainId = 0; gainId < GAIN_COUNT; gainId++) { | |
| 61 | + for(unsigned int gainId = 0; gainId < 9; gainId++) { | |
| 65 | 62 | this->specification.offsetLimit[channel][gainId][OFFSET_START] = 0x0000; |
| 66 | 63 | this->specification.offsetLimit[channel][gainId][OFFSET_END] = 0xffff; |
| 67 | 64 | } |
| ... | ... | @@ -589,6 +586,9 @@ namespace Hantek { |
| 589 | 586 | // Maximum possible samplerate for a single channel and dividers for buffer sizes |
| 590 | 587 | this->specification.bufferDividers.clear(); |
| 591 | 588 | this->specification.bufferSizes.clear(); |
| 589 | + this->specification.gainSteps.clear(); | |
| 590 | + for(int channel = 0; channel < HANTEK_CHANNELS; channel++) | |
| 591 | + this->specification.voltageLimit[channel].clear(); | |
| 592 | 592 | |
| 593 | 593 | switch(this->device->getModel()) { |
| 594 | 594 | case MODEL_DSO2250: |
| ... | ... | @@ -600,6 +600,14 @@ namespace Hantek { |
| 600 | 600 | this->specification.samplerate.multi.max = 250e6; |
| 601 | 601 | this->specification.bufferDividers << 1000 << 1 << 2; |
| 602 | 602 | this->specification.bufferSizes << ULONG_MAX << 10240 << 14336; |
| 603 | + this->specification.gainSteps | |
| 604 | + << 0.16 << 0.40 << 0.80 << 1.60 << 4.00 << 8.0 << 16.0 << 40.0 << 80.0; | |
| 605 | + /// \todo Use calibration data to get the DSO-5200(A) sample ranges | |
| 606 | + for(int channel = 0; channel < HANTEK_CHANNELS; channel++) | |
| 607 | + this->specification.voltageLimit[channel] | |
| 608 | + << 368 << 454 << 908 << 368 << 454 << 908 << 368 << 454 << 908; | |
| 609 | + this->specification.gainIndex | |
| 610 | + << 1 << 0 << 0 << 1 << 0 << 0 << 1 << 0 << 0; | |
| 603 | 611 | break; |
| 604 | 612 | |
| 605 | 613 | case MODEL_DSO2150: |
| ... | ... | @@ -609,6 +617,13 @@ namespace Hantek { |
| 609 | 617 | this->specification.samplerate.multi.max = 150e6; |
| 610 | 618 | this->specification.bufferDividers << 1000 << 1 << 2; |
| 611 | 619 | this->specification.bufferSizes << ULONG_MAX << 10240 << 32768; |
| 620 | + this->specification.gainSteps | |
| 621 | + << 0.08 << 0.16 << 0.40 << 0.80 << 1.60 << 4.00 << 8.0 << 16.0 << 40.0; | |
| 622 | + for(int channel = 0; channel < HANTEK_CHANNELS; channel++) | |
| 623 | + this->specification.voltageLimit[channel] | |
| 624 | + << 255 << 255 << 255 << 255 << 255 << 255 << 255 << 255 << 255; | |
| 625 | + this->specification.gainIndex | |
| 626 | + << 0 << 1 << 2 << 0 << 1 << 2 << 0 << 1 << 2; | |
| 612 | 627 | break; |
| 613 | 628 | |
| 614 | 629 | default: |
| ... | ... | @@ -618,6 +633,13 @@ namespace Hantek { |
| 618 | 633 | this->specification.samplerate.multi.max = 100e6; |
| 619 | 634 | this->specification.bufferDividers << 1000 << 1 << 2; |
| 620 | 635 | this->specification.bufferSizes << ULONG_MAX << 10240 << 32768; |
| 636 | + this->specification.gainSteps | |
| 637 | + << 0.08 << 0.16 << 0.40 << 0.80 << 1.60 << 4.00 << 8.0 << 16.0 << 40.0; | |
| 638 | + for(int channel = 0; channel < HANTEK_CHANNELS; channel++) | |
| 639 | + this->specification.voltageLimit[channel] | |
| 640 | + << 255 << 255 << 255 << 255 << 255 << 255 << 255 << 255 << 255; | |
| 641 | + this->specification.gainIndex | |
| 642 | + << 0 << 1 << 2 << 0 << 1 << 2 << 0 << 1 << 2; | |
| 621 | 643 | break; |
| 622 | 644 | } |
| 623 | 645 | this->settings.samplerate.limits = &(this->specification.samplerate.single); |
| ... | ... | @@ -812,64 +834,21 @@ namespace Hantek { |
| 812 | 834 | |
| 813 | 835 | // Find lowest gain voltage thats at least as high as the requested |
| 814 | 836 | int gainId; |
| 815 | - for(gainId = 0; gainId < GAIN_COUNT - 1; gainId++) | |
| 837 | + for(gainId = 0; gainId < this->specification.gainSteps.count() - 1; gainId++) | |
| 816 | 838 | if(this->specification.gainSteps[gainId] >= gain) |
| 817 | 839 | break; |
| 818 | 840 | |
| 819 | - // Get the voltage scaler id and it's sample range for this gain | |
| 820 | - int scalerId; | |
| 821 | - switch(this->device->getModel()) { | |
| 822 | - case MODEL_DSO5200: | |
| 823 | - case MODEL_DSO5200A: | |
| 824 | - /// \todo Use calibration data to get the DSO-5200(A) sample ranges | |
| 825 | - if(gainId == GAIN_10MV) { | |
| 826 | - scalerId = 1; | |
| 827 | - this->specification.voltageLimit[channel][gainId] = 184; | |
| 828 | - } | |
| 829 | - else { | |
| 830 | - switch(gainId % 3) { | |
| 831 | - case 1: | |
| 832 | - scalerId = 1; | |
| 833 | - this->specification.voltageLimit[channel][gainId] = 368; | |
| 834 | - break; | |
| 835 | - case 2: | |
| 836 | - scalerId = 0; | |
| 837 | - this->specification.voltageLimit[channel][gainId] = 454; | |
| 838 | - break; | |
| 839 | - default: | |
| 840 | - scalerId = 0; | |
| 841 | - this->specification.voltageLimit[channel][gainId] = 908; | |
| 842 | - break; | |
| 843 | - } | |
| 844 | - } | |
| 845 | - break; | |
| 846 | - | |
| 847 | - default: | |
| 848 | - scalerId = gainId % 3; | |
| 849 | - this->specification.voltageLimit[channel][gainId] = 0xff; | |
| 850 | - break; | |
| 851 | - } | |
| 852 | - | |
| 853 | 841 | // SetGain bulk command for gain |
| 854 | - ((BulkSetGain *) this->command[BULK_SETGAIN])->setGain(channel, scalerId); | |
| 842 | + ((BulkSetGain *) this->command[BULK_SETGAIN])->setGain(channel, this->specification.gainIndex[gainId]); | |
| 855 | 843 | this->commandPending[BULK_SETGAIN] = true; |
| 856 | 844 | |
| 857 | 845 | // SetRelays control command for gain relays |
| 858 | 846 | ControlSetRelays *controlSetRelays = (ControlSetRelays *) this->control[CONTROLINDEX_SETRELAYS]; |
| 859 | - switch(this->device->getModel()) { | |
| 860 | - case MODEL_DSO5200: | |
| 861 | - case MODEL_DSO5200A: | |
| 862 | - controlSetRelays->setBelow1V(channel, gainId <= GAIN_1V); | |
| 863 | - controlSetRelays->setBelow100mV(channel, gainId <= GAIN_100MV); | |
| 864 | - break; | |
| 865 | - default: | |
| 866 | - controlSetRelays->setBelow1V(channel, gainId < GAIN_1V); | |
| 867 | - controlSetRelays->setBelow100mV(channel, gainId < GAIN_100MV); | |
| 868 | - break; | |
| 869 | - } | |
| 847 | + controlSetRelays->setBelow1V(channel, gainId < 3); | |
| 848 | + controlSetRelays->setBelow100mV(channel, gainId < 6); | |
| 870 | 849 | this->controlPending[CONTROLINDEX_SETRELAYS] = true; |
| 871 | 850 | |
| 872 | - this->settings.voltage[channel].gain = (Gain) gainId; | |
| 851 | + this->settings.voltage[channel].gain = gainId; | |
| 873 | 852 | |
| 874 | 853 | this->setOffset(channel, this->settings.voltage[channel].offset); |
| 875 | 854 | |
| ... | ... | @@ -988,7 +967,7 @@ namespace Hantek { |
| 988 | 967 | case MODEL_DSO5200A: |
| 989 | 968 | // The range is the same as used for the offsets for 10 bit models |
| 990 | 969 | minimum = ((unsigned short int) *((unsigned char *) &(this->specification.offsetLimit[channel][this->settings.voltage[channel].gain][OFFSET_START])) << 8) + *((unsigned char *) &(this->specification.offsetLimit[channel][this->settings.voltage[channel].gain][OFFSET_START]) + 1); |
| 991 | - maximum = ((unsigned short int) *((unsigned char *) &(this->specification.offsetLimit[channel][this->settings.voltage[channel].gain][OFFSET_START])) << 8) + *((unsigned char *) &(this->specification.offsetLimit[channel][this->settings.voltage[channel].gain][OFFSET_END]) + 1); | |
| 970 | + maximum = ((unsigned short int) *((unsigned char *) &(this->specification.offsetLimit[channel][this->settings.voltage[channel].gain][OFFSET_END])) << 8) + *((unsigned char *) &(this->specification.offsetLimit[channel][this->settings.voltage[channel].gain][OFFSET_END]) + 1); | |
| 992 | 971 | break; |
| 993 | 972 | |
| 994 | 973 | default: | ... | ... |
openhantek/src/hantek/control.h
| ... | ... | @@ -119,9 +119,11 @@ namespace Hantek { |
| 119 | 119 | |
| 120 | 120 | // Calibration |
| 121 | 121 | /// The sample values at the top of the screen |
| 122 | - unsigned short int voltageLimit[HANTEK_CHANNELS][GAIN_COUNT]; | |
| 123 | - /// Calibration data for the channel offsets | |
| 124 | - unsigned short int offsetLimit[HANTEK_CHANNELS][GAIN_COUNT][OFFSET_COUNT]; | |
| 122 | + QList<unsigned short int> voltageLimit[HANTEK_CHANNELS]; | |
| 123 | + /// The index of the selected gain on the hardware | |
| 124 | + QList<unsigned char> gainIndex; | |
| 125 | + /// Calibration data for the channel offsets \todo Should probably be a QList too | |
| 126 | + unsigned short int offsetLimit[HANTEK_CHANNELS][9][OFFSET_COUNT]; | |
| 125 | 127 | }; |
| 126 | 128 | |
| 127 | 129 | ////////////////////////////////////////////////////////////////////////////// |
| ... | ... | @@ -151,7 +153,7 @@ namespace Hantek { |
| 151 | 153 | /// \struct ControlSettingsSamplerate hantek/control.h |
| 152 | 154 | /// \brief Stores the current amplification settings of the device. |
| 153 | 155 | struct ControlSettingsVoltage { |
| 154 | - Gain gain; ///< The gain id | |
| 156 | + unsigned int gain; ///< The gain id | |
| 155 | 157 | double offset; ///< The screen offset for each channel |
| 156 | 158 | double offsetReal; ///< The real offset for each channel (Due to quantization) |
| 157 | 159 | bool used; ///< true, if the channel is used | ... | ... |
openhantek/src/hantek/types.h
| ... | ... | @@ -500,29 +500,6 @@ namespace Hantek { |
| 500 | 500 | }; |
| 501 | 501 | |
| 502 | 502 | ////////////////////////////////////////////////////////////////////////////// |
| 503 | - /// \enum Samplerate hantek/types.h | |
| 504 | - /// \brief The different samplerates supported by Hantek DSOs. | |
| 505 | - enum Samplerate { | |
| 506 | - SAMPLERATE_100MS, | |
| 507 | - SAMPLERATE_50MS, SAMPLERATE_25MS, SAMPLERATE_10MS, | |
| 508 | - SAMPLERATE_5MS, SAMPLERATE_2_5MS, SAMPLERATE_1MS, | |
| 509 | - SAMPLERATE_500KS, SAMPLERATE_250KS, SAMPLERATE_100KS, | |
| 510 | - SAMPLERATE_50KS, SAMPLERATE_25KS, SAMPLERATE_10KS, | |
| 511 | - SAMPLERATE_5KS, SAMPLERATE_2_5KS, SAMPLERATE_1KS, | |
| 512 | - SAMPLERATE_COUNT | |
| 513 | - }; | |
| 514 | - | |
| 515 | - ////////////////////////////////////////////////////////////////////////////// | |
| 516 | - /// \enum Gain hantek/types.h | |
| 517 | - /// \brief The different gain steps supported by Hantek DSOs. | |
| 518 | - enum Gain { | |
| 519 | - GAIN_10MV, GAIN_20MV, GAIN_50MV, | |
| 520 | - GAIN_100MV, GAIN_200MV, GAIN_500MV, | |
| 521 | - GAIN_1V, GAIN_2V, GAIN_5V, | |
| 522 | - GAIN_COUNT | |
| 523 | - }; | |
| 524 | - | |
| 525 | - ////////////////////////////////////////////////////////////////////////////// | |
| 526 | 503 | /// \enum UsedChannels hantek/types.h |
| 527 | 504 | /// \brief The enabled channels. |
| 528 | 505 | enum UsedChannels { | ... | ... |