nullpointer check added
This commit is contained in:
parent
8547dbb1bd
commit
faefaed63c
|
@ -24,7 +24,7 @@ help:
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@echo "Cleaning..."
|
@echo "Cleaning..."
|
||||||
rm -f $(OBJECTS) $(OUT)
|
rm -f $(OBJECTS) $(OUT) *.bin gnuplotscript.gp
|
||||||
|
|
||||||
.cpp.o:
|
.cpp.o:
|
||||||
$(COMPILE) -c $< -o $@
|
$(COMPILE) -c $< -o $@
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include <b15f/b15f.h>
|
#include <b15f/b15f.h>
|
||||||
#include <b15f/plottyfile.h>
|
#include <b15f/plottyfile.h>
|
||||||
|
|
||||||
constexpr char * PLOT_FILE = "plot.bin";
|
const char PLOT_FILE[] = "plot.bin";
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
@ -12,7 +12,6 @@ int main()
|
||||||
PlottyFile pf;
|
PlottyFile pf;
|
||||||
|
|
||||||
uint16_t ba[1024];
|
uint16_t ba[1024];
|
||||||
uint16_t bb[1024];
|
|
||||||
|
|
||||||
const uint16_t sample_count = 1024;
|
const uint16_t sample_count = 1024;
|
||||||
const uint16_t delta = 1;
|
const uint16_t delta = 1;
|
||||||
|
@ -31,14 +30,12 @@ int main()
|
||||||
uint8_t curve = 0;
|
uint8_t curve = 0;
|
||||||
|
|
||||||
|
|
||||||
drv.analogSequence(0, &ba[0], 0, 1, &bb[0], 0, 0, delta, sample_count);
|
drv.analogSequence(0, &ba[0], 0, 1, nullptr, 0, 0, delta, sample_count);
|
||||||
|
|
||||||
for(uint16_t x = 0; x < sample_count * delta; x += delta)
|
for(uint16_t x = 0; x < sample_count * delta; x += delta)
|
||||||
{
|
{
|
||||||
drv.analogWrite0(x);
|
std::cout << x << " - " << ba[x] << std::endl;
|
||||||
uint16_t y = drv.analogRead(0);
|
pf.addDot(Dot(x, ba[x], curve));
|
||||||
std::cout << x << " - " << y << std::endl;
|
|
||||||
pf.addDot(Dot(x, y, curve));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// speichern und plotty starten
|
// speichern und plotty starten
|
||||||
|
|
|
@ -240,8 +240,12 @@ uint16_t B15F::analogRead(uint8_t channel)
|
||||||
|
|
||||||
void B15F::analogSequence(uint8_t channel_a, uint16_t* buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t* buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count)
|
void B15F::analogSequence(uint8_t channel_a, uint16_t* buffer_a, uint32_t offset_a, uint8_t channel_b, uint16_t* buffer_b, uint32_t offset_b, uint16_t start, int16_t delta, uint16_t count)
|
||||||
{
|
{
|
||||||
buffer_a += offset_a;
|
// check pointers
|
||||||
buffer_b += offset_b;
|
if(buffer_a)
|
||||||
|
buffer_a += offset_a;
|
||||||
|
if(buffer_b)
|
||||||
|
buffer_b += offset_b;
|
||||||
|
|
||||||
|
|
||||||
usart.clearInputBuffer();
|
usart.clearInputBuffer();
|
||||||
usart.writeByte(RQ_ADC_DAC_STROKE);
|
usart.writeByte(RQ_ADC_DAC_STROKE);
|
||||||
|
@ -249,15 +253,33 @@ void B15F::analogSequence(uint8_t channel_a, uint16_t* buffer_a, uint32_t offset
|
||||||
usart.writeByte(channel_b);
|
usart.writeByte(channel_b);
|
||||||
usart.writeInt(start);
|
usart.writeInt(start);
|
||||||
usart.writeInt(static_cast<uint16_t>(delta));
|
usart.writeInt(static_cast<uint16_t>(delta));
|
||||||
usart.writeInt(count);
|
usart.writeInt(count);
|
||||||
|
|
||||||
|
|
||||||
for(uint16_t i = 0; i < count; i++)
|
for(uint16_t i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
buffer_a[i] = usart.readInt();
|
if(buffer_a)
|
||||||
buffer_b[i] = usart.readInt();
|
{
|
||||||
if(buffer_a[i] > 1023 || buffer_b[i] > 1023)
|
buffer_a[i] = usart.readInt();
|
||||||
abort("Bad ADC data detected (2)");
|
|
||||||
|
if(buffer_a[i] > 1023) // check for broken usart connection
|
||||||
|
abort("Bad ADC data detected (2)");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
usart.readInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(buffer_b)
|
||||||
|
{
|
||||||
|
buffer_b[i] = usart.readInt();
|
||||||
|
|
||||||
|
if(buffer_b[i] > 1023) // check for broken usart connection
|
||||||
|
abort("Bad ADC data detected (3)");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
usart.readInt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t aw = usart.readByte();
|
uint8_t aw = usart.readByte();
|
||||||
|
|
Loading…
Reference in a new issue