aboutsummaryrefslogtreecommitdiff
path: root/src/survive_cal.c
diff options
context:
space:
mode:
authorcnlohr <lohr85@gmail.com>2017-02-16 14:44:54 -0500
committercnlohr <lohr85@gmail.com>2017-02-16 14:44:54 -0500
commitf2d014016d73f067c224ee222bc3eab910848914 (patch)
treee98df6e5d4e85f8bd35c184b0136968c7e07af90 /src/survive_cal.c
parentf782146df94b3b54965c2aed696d49e86870046d (diff)
parent05ff11b162145e327ba5839f77be09df5289f4d1 (diff)
downloadlibsurvive-f2d014016d73f067c224ee222bc3eab910848914.tar.gz
libsurvive-f2d014016d73f067c224ee222bc3eab910848914.tar.bz2
Merge branch 'axlecrusher-master'
Diffstat (limited to 'src/survive_cal.c')
-rw-r--r--src/survive_cal.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/survive_cal.c b/src/survive_cal.c
new file mode 100644
index 0000000..adcb7bc
--- /dev/null
+++ b/src/survive_cal.c
@@ -0,0 +1,72 @@
+// (C) 2016, 2017 Joshua Allen, MIT/x11 License.
+// (C) 2016, 2017 <>< C. N. Lohr, Under MIT/x11 License.
+
+// All OOTX code was written by J. Allen. Rest of the code is probably mostly CNLohr.
+
+#include "survive_cal.h"
+#include "survive_internal.h"
+
+void ootx_packet_clbk_d(ootx_decoder_context *ct, ootx_packet* packet)
+{
+ struct SurviveContext * ctx = (struct SurviveContext*)(ct->user);
+ struct SurviveCalData * cd = ctx->calptr;
+ int id = ct->user1;
+
+ printf( "Got OOTX packet %d %p\n", id, cd );
+
+ lighthouse_info_v6 v6;
+ init_lighthouse_info_v6(&v6, packet->data);
+ print_lighthouse_info_v6(&v6);
+}
+
+
+void survive_cal_install( struct SurviveContext * ctx )
+{
+ int i;
+ struct SurviveCalData * cd = ctx->calptr = calloc( 1, sizeof( struct SurviveCalData ) );
+
+ for( i = 0; i < NUM_LIGHTHOUSES; i++ )
+ {
+ ootx_init_decoder_context(&cd->ootx_decoders[i]);
+ cd->ootx_decoders[i].user = ctx;
+ cd->ootx_decoders[i].user1 = i;
+ }
+
+ cd->stage = 1;
+
+ ootx_packet_clbk = ootx_packet_clbk_d;
+
+ ctx->calptr = cd;
+}
+
+
+void survive_cal_light( struct SurviveObject * so, int sensor_id, int acode, int timeinsweep, uint32_t timecode, uint32_t length )
+{
+ struct SurviveContext * ctx = so->ctx;
+ struct SurviveCalData * cd = ctx->calptr;
+
+ if( !cd ) return;
+
+ switch( cd->stage )
+ {
+ default:
+ case 0: //Default, inactive.
+ break;
+
+ case 1:
+ //Collecting OOTX data.
+ if( sensor_id < 0 )
+ {
+ int lhid = -sensor_id-1;
+ if( lhid < NUM_LIGHTHOUSES && so->codename[0] == 'H' )
+ {
+ uint8_t dbit = (acode & 2)>>1;
+ //printf( "%s %d %d %d\n", so->codename, lhid, acode, dbit );
+ ootx_pump_bit( &cd->ootx_decoders[lhid], dbit );
+ }
+ }
+
+ break;
+ }
+}
+