-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLepton_Stream.h
80 lines (71 loc) · 2.38 KB
/
Lepton_Stream.h
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
#pragma once
//Using:
//Lepton_Packet_Is_Discard
//Lepton_Packet_Is_Row
//Lepton_Packet_Is_Match
#include "Lepton.h"
#include "Lepton_Packets.h"
#include "Lepton_SPI.h"
#include "Lepton_Pixels.h"
#include "Lepton_Conversions.h"
//Using:
//size_t
#include <stddef.h>
#include <stdbool.h>
enum Lepton_Stream_Result
{
Lepton_Stream_Invalid_Segment = Lepton_Error_Generator (1),
Lepton_Stream_Discard = Lepton_Error_Generator (2),
Lepton_Stream_Mismatch = Lepton_Error_Generator (3),
Lepton_Stream_Invalid_Row = Lepton_Error_Generator (4),
Lepton_Stream_Shifting = Lepton_Error_Generator (5)
};
//Return 1 if Stream is ordered.
//Return 0 if Stream is not ordered.
bool
Lepton_Stream_Check_Climbing_Number
(struct Lepton_Packet * Stream, size_t Count)
{
Lepton_Assert (Count > 0, Lepton_Error_Range, "Count %i is non posetive", Count);
for (size_t I = 0; I < (Count - 1); I = I + 1)
{
uint_fast8_t X0 = Stream [I + 0].Number;
uint_fast8_t X1 = Stream [I + 1].Number;
if ((X0 + 1) != X1) {return false;}
}
return true;
}
//Assigns the segment pixel map to correct position in `Pixmap`.
//Automaticly shifting the stream when the stream has an offset.
//Returns `Lepton_Stream_Shifting` when the stream is shifting.
//Returns the segment number `1 .. 4` on succesful.
//Returns error code on error.
int32_t
Lepton_Stream_Accept
(int Device, struct Lepton_Pixel_Grayscale16 * Pixmap)
{
struct Lepton_Packet Stream [Lepton_Height];
int32_t Result;
Result = Lepton_SPI_Transfer_Stream8 ((uint8_t *) Stream, sizeof (Stream), Device);
if (Result != sizeof (Stream)) {return Result;}
for (size_t I = 0; I < Lepton_Height; I = I + 1)
{
if (Lepton_Packet_Is_Discard (Stream + I) == 1) {return Lepton_Stream_Discard;}
if (Lepton_Packet_Is_Row (Stream + I) == 0) {return Lepton_Stream_Invalid_Row;}
if (Lepton_Packet_Is_Match (Stream + I) == 0) {return Lepton_Stream_Mismatch;}
}
if (Stream [20].Number != 20)
{
Lepton_SPI_Transfer_Stream (Stream, 1, Device);
return Lepton_Stream_Shifting;
}
int32_t Segment;
Segment = Stream [20].Reserved >> 4;
if
((Segment <= 0) || (Segment > 4))
{return Lepton_Stream_Invalid_Segment;}
for
(size_t I = 0; I < Lepton_Height; I = I + 1)
{Lepton_Conversions_Packet_To_Grayscale16 (Stream + I, Pixmap, Segment - 1);}
return Segment;
}