Lines Matching refs:sensor
495 static void resetBuffer(struct ActiveSensor *sensor) in resetBuffer() argument
497 sensor->discard = true; in resetBuffer()
498 sensor->buffer.length = 0; in resetBuffer()
499 memset(&sensor->buffer.firstSample, 0x00, sizeof(struct SensorFirstSample)); in resetBuffer()
511 struct ActiveSensor *sensor; in hostIntfPacketDequeue() local
517 sensor = mActiveSensorTable + mSensorList[buffer->sensType - 1]; in hostIntfPacketDequeue()
518 …if (sensor->sensorHandle == 0 && !buffer->firstSample.biasPresent && !buffer->firstSample.numFlush… in hostIntfPacketDequeue()
519 if (sensor->interrupt == NANOHUB_INT_WAKEUP) in hostIntfPacketDequeue()
521 else if (sensor->interrupt == NANOHUB_INT_NONWAKEUP) in hostIntfPacketDequeue()
523 sensor->curSamples -= buffer->firstSample.numSamples; in hostIntfPacketDequeue()
549 sensor = mActiveSensorTable + mSensorList[buffer->sensType - 1]; in hostIntfPacketDequeue()
550 if (sensor->interrupt == NANOHUB_INT_WAKEUP) in hostIntfPacketDequeue()
552 else if (sensor->interrupt == NANOHUB_INT_NONWAKEUP) in hostIntfPacketDequeue()
554 sensor->curSamples -= buffer->firstSample.numSamples; in hostIntfPacketDequeue()
555 sensor->firstTime = 0ull; in hostIntfPacketDequeue()
578 struct ActiveSensor *sensor; in queueDiscard() local
581 sensor = mActiveSensorTable + mSensorList[buffer->sensType - 1]; in queueDiscard()
583 if (sensor->curSamples - buffer->firstSample.numSamples >= sensor->minSamples || onDelete) { in queueDiscard()
584 if (sensor->interrupt == NANOHUB_INT_WAKEUP) in queueDiscard()
586 else if (sensor->interrupt == NANOHUB_INT_NONWAKEUP) in queueDiscard()
588 sensor->curSamples -= buffer->firstSample.numSamples; in queueDiscard()
760 static void copyTripleSamplesRaw(struct ActiveSensor *sensor, const struct TripleAxisDataEvent *tri… in copyTripleSamplesRaw() argument
767 if (sensor->buffer.firstSample.numSamples == sensor->packetSamples) { in copyTripleSamplesRaw()
768 …simpleQueueEnqueue(mOutputQ, &sensor->buffer, sizeof(uint32_t) + sensor->buffer.length, sensor->di… in copyTripleSamplesRaw()
769 resetBuffer(sensor); in copyTripleSamplesRaw()
772 if (sensor->buffer.firstSample.numSamples == 0) { in copyTripleSamplesRaw()
774 sensor->lastTime = sensor->buffer.referenceTime = triple->referenceTime; in copyTripleSamplesRaw()
776 sensor->lastTime += triple->samples[i].deltaTime; in copyTripleSamplesRaw()
777 sensor->buffer.referenceTime = sensor->lastTime; in copyTripleSamplesRaw()
779 …sensor->buffer.length = sizeof(struct RawTripleAxisDataEvent) + sizeof(struct RawTripleAxisDataPoi… in copyTripleSamplesRaw()
780 sensor->buffer.rawTriple[0].ix = floatToInt16(triple->samples[i].x * sensor->rawScale); in copyTripleSamplesRaw()
781 sensor->buffer.rawTriple[0].iy = floatToInt16(triple->samples[i].y * sensor->rawScale); in copyTripleSamplesRaw()
782 sensor->buffer.rawTriple[0].iz = floatToInt16(triple->samples[i].z * sensor->rawScale); in copyTripleSamplesRaw()
783 if (sensor->interrupt == NANOHUB_INT_WAKEUP) in copyTripleSamplesRaw()
785 else if (sensor->interrupt == NANOHUB_INT_NONWAKEUP) in copyTripleSamplesRaw()
787 sensor->buffer.firstSample.numSamples = 1; in copyTripleSamplesRaw()
788 sensor->buffer.firstSample.interrupt = sensor->interrupt; in copyTripleSamplesRaw()
789 if (sensor->curSamples++ == 0) in copyTripleSamplesRaw()
790 sensor->firstTime = sensor->buffer.referenceTime; in copyTripleSamplesRaw()
793 if (sensor->lastTime > triple->referenceTime) { in copyTripleSamplesRaw()
795 …simpleQueueEnqueue(mOutputQ, &sensor->buffer, sizeof(uint32_t) + sensor->buffer.length, sensor->di… in copyTripleSamplesRaw()
796 resetBuffer(sensor); in copyTripleSamplesRaw()
798 } else if (triple->referenceTime - sensor->lastTime >= delta_time_max) { in copyTripleSamplesRaw()
799 …simpleQueueEnqueue(mOutputQ, &sensor->buffer, sizeof(uint32_t) + sensor->buffer.length, sensor->di… in copyTripleSamplesRaw()
800 resetBuffer(sensor); in copyTripleSamplesRaw()
803 deltaTime = encodeDeltaTime(triple->referenceTime - sensor->lastTime); in copyTripleSamplesRaw()
804 numSamples = sensor->buffer.firstSample.numSamples; in copyTripleSamplesRaw()
806 sensor->buffer.length += sizeof(struct RawTripleAxisDataPoint); in copyTripleSamplesRaw()
807 sensor->buffer.rawTriple[numSamples].deltaTime = deltaTime; in copyTripleSamplesRaw()
808 … sensor->buffer.rawTriple[numSamples].ix = floatToInt16(triple->samples[0].x * sensor->rawScale); in copyTripleSamplesRaw()
809 … sensor->buffer.rawTriple[numSamples].iy = floatToInt16(triple->samples[0].y * sensor->rawScale); in copyTripleSamplesRaw()
810 … sensor->buffer.rawTriple[numSamples].iz = floatToInt16(triple->samples[0].z * sensor->rawScale); in copyTripleSamplesRaw()
811 sensor->lastTime = triple->referenceTime; in copyTripleSamplesRaw()
812 sensor->buffer.firstSample.numSamples++; in copyTripleSamplesRaw()
813 sensor->curSamples++; in copyTripleSamplesRaw()
817 numSamples = sensor->buffer.firstSample.numSamples; in copyTripleSamplesRaw()
819 sensor->buffer.length += sizeof(struct RawTripleAxisDataPoint); in copyTripleSamplesRaw()
820 sensor->buffer.rawTriple[numSamples].deltaTime = deltaTime | delta_time_fine_mask; in copyTripleSamplesRaw()
821 … sensor->buffer.rawTriple[numSamples].ix = floatToInt16(triple->samples[i].x * sensor->rawScale); in copyTripleSamplesRaw()
822 … sensor->buffer.rawTriple[numSamples].iy = floatToInt16(triple->samples[i].y * sensor->rawScale); in copyTripleSamplesRaw()
823 … sensor->buffer.rawTriple[numSamples].iz = floatToInt16(triple->samples[i].z * sensor->rawScale); in copyTripleSamplesRaw()
824 sensor->lastTime += deltaTime; in copyTripleSamplesRaw()
825 sensor->buffer.firstSample.numSamples++; in copyTripleSamplesRaw()
826 sensor->curSamples++; in copyTripleSamplesRaw()
832 static void copySingleSamples(struct ActiveSensor *sensor, const struct SingleAxisDataEvent *single) in copySingleSamples() argument
839 if (sensor->buffer.firstSample.numSamples == sensor->packetSamples) { in copySingleSamples()
840 …simpleQueueEnqueue(mOutputQ, &sensor->buffer, sizeof(uint32_t) + sensor->buffer.length, sensor->di… in copySingleSamples()
841 resetBuffer(sensor); in copySingleSamples()
844 if (sensor->buffer.firstSample.numSamples == 0) { in copySingleSamples()
846 sensor->lastTime = sensor->buffer.referenceTime = single->referenceTime; in copySingleSamples()
848 sensor->lastTime += single->samples[i].deltaTime; in copySingleSamples()
849 sensor->buffer.referenceTime = sensor->lastTime; in copySingleSamples()
851 … sensor->buffer.length = sizeof(struct SingleAxisDataEvent) + sizeof(struct SingleAxisDataPoint); in copySingleSamples()
852 sensor->buffer.single[0].idata = single->samples[i].idata; in copySingleSamples()
853 if (sensor->interrupt == NANOHUB_INT_WAKEUP) in copySingleSamples()
855 else if (sensor->interrupt == NANOHUB_INT_NONWAKEUP) in copySingleSamples()
857 sensor->buffer.firstSample.numSamples = 1; in copySingleSamples()
858 sensor->buffer.firstSample.interrupt = sensor->interrupt; in copySingleSamples()
859 if (sensor->curSamples++ == 0) in copySingleSamples()
860 sensor->firstTime = sensor->buffer.referenceTime; in copySingleSamples()
863 if (sensor->lastTime > single->referenceTime) { in copySingleSamples()
865 …simpleQueueEnqueue(mOutputQ, &sensor->buffer, sizeof(uint32_t) + sensor->buffer.length, sensor->di… in copySingleSamples()
866 resetBuffer(sensor); in copySingleSamples()
868 } else if (single->referenceTime - sensor->lastTime >= delta_time_max) { in copySingleSamples()
869 …simpleQueueEnqueue(mOutputQ, &sensor->buffer, sizeof(uint32_t) + sensor->buffer.length, sensor->di… in copySingleSamples()
870 resetBuffer(sensor); in copySingleSamples()
873 deltaTime = encodeDeltaTime(single->referenceTime - sensor->lastTime); in copySingleSamples()
874 numSamples = sensor->buffer.firstSample.numSamples; in copySingleSamples()
876 sensor->buffer.length += sizeof(struct SingleAxisDataPoint); in copySingleSamples()
877 sensor->buffer.single[numSamples].deltaTime = deltaTime; in copySingleSamples()
878 sensor->buffer.single[numSamples].idata = single->samples[0].idata; in copySingleSamples()
879 sensor->lastTime = single->referenceTime; in copySingleSamples()
880 sensor->buffer.firstSample.numSamples++; in copySingleSamples()
881 sensor->curSamples++; in copySingleSamples()
885 numSamples = sensor->buffer.firstSample.numSamples; in copySingleSamples()
887 sensor->buffer.length += sizeof(struct SingleAxisDataPoint); in copySingleSamples()
888 sensor->buffer.single[numSamples].deltaTime = deltaTime | delta_time_fine_mask; in copySingleSamples()
889 sensor->buffer.single[numSamples].idata = single->samples[i].idata; in copySingleSamples()
890 sensor->lastTime += deltaTime; in copySingleSamples()
891 sensor->buffer.firstSample.numSamples++; in copySingleSamples()
892 sensor->curSamples++; in copySingleSamples()
898 static void copyTripleSamples(struct ActiveSensor *sensor, const struct TripleAxisDataEvent *triple) in copyTripleSamples() argument
905 if (sensor->buffer.firstSample.numSamples == sensor->packetSamples) { in copyTripleSamples()
906 …simpleQueueEnqueue(mOutputQ, &sensor->buffer, sizeof(uint32_t) + sensor->buffer.length, sensor->di… in copyTripleSamples()
907 resetBuffer(sensor); in copyTripleSamples()
910 if (sensor->buffer.firstSample.numSamples == 0) { in copyTripleSamples()
912 sensor->lastTime = sensor->buffer.referenceTime = triple->referenceTime; in copyTripleSamples()
914 sensor->lastTime += triple->samples[i].deltaTime; in copyTripleSamples()
915 sensor->buffer.referenceTime = sensor->lastTime; in copyTripleSamples()
917 … sensor->buffer.length = sizeof(struct TripleAxisDataEvent) + sizeof(struct TripleAxisDataPoint); in copyTripleSamples()
918 sensor->buffer.triple[0].ix = triple->samples[i].ix; in copyTripleSamples()
919 sensor->buffer.triple[0].iy = triple->samples[i].iy; in copyTripleSamples()
920 sensor->buffer.triple[0].iz = triple->samples[i].iz; in copyTripleSamples()
922 sensor->buffer.firstSample.biasCurrent = triple->samples[0].firstSample.biasCurrent; in copyTripleSamples()
923 sensor->buffer.firstSample.biasPresent = 1; in copyTripleSamples()
924 sensor->buffer.firstSample.biasSample = 0; in copyTripleSamples()
925 sensor->discard = false; in copyTripleSamples()
927 if (sensor->interrupt == NANOHUB_INT_WAKEUP) in copyTripleSamples()
929 else if (sensor->interrupt == NANOHUB_INT_NONWAKEUP) in copyTripleSamples()
931 sensor->buffer.firstSample.numSamples = 1; in copyTripleSamples()
932 sensor->buffer.firstSample.interrupt = sensor->interrupt; in copyTripleSamples()
933 if (sensor->curSamples++ == 0) in copyTripleSamples()
934 sensor->firstTime = sensor->buffer.referenceTime; in copyTripleSamples()
937 if (sensor->lastTime > triple->referenceTime) { in copyTripleSamples()
939 …simpleQueueEnqueue(mOutputQ, &sensor->buffer, sizeof(uint32_t) + sensor->buffer.length, sensor->di… in copyTripleSamples()
940 resetBuffer(sensor); in copyTripleSamples()
942 } else if (triple->referenceTime - sensor->lastTime >= delta_time_max) { in copyTripleSamples()
943 …simpleQueueEnqueue(mOutputQ, &sensor->buffer, sizeof(uint32_t) + sensor->buffer.length, sensor->di… in copyTripleSamples()
944 resetBuffer(sensor); in copyTripleSamples()
947 deltaTime = encodeDeltaTime(triple->referenceTime - sensor->lastTime); in copyTripleSamples()
948 numSamples = sensor->buffer.firstSample.numSamples; in copyTripleSamples()
950 sensor->buffer.length += sizeof(struct TripleAxisDataPoint); in copyTripleSamples()
951 sensor->buffer.triple[numSamples].deltaTime = deltaTime; in copyTripleSamples()
952 sensor->buffer.triple[numSamples].ix = triple->samples[0].ix; in copyTripleSamples()
953 sensor->buffer.triple[numSamples].iy = triple->samples[0].iy; in copyTripleSamples()
954 sensor->buffer.triple[numSamples].iz = triple->samples[0].iz; in copyTripleSamples()
955 sensor->lastTime = triple->referenceTime; in copyTripleSamples()
957 … sensor->buffer.firstSample.biasCurrent = triple->samples[0].firstSample.biasCurrent; in copyTripleSamples()
958 sensor->buffer.firstSample.biasPresent = 1; in copyTripleSamples()
959 sensor->buffer.firstSample.biasSample = numSamples; in copyTripleSamples()
960 sensor->discard = false; in copyTripleSamples()
962 sensor->buffer.firstSample.numSamples++; in copyTripleSamples()
963 sensor->curSamples++; in copyTripleSamples()
967 numSamples = sensor->buffer.firstSample.numSamples; in copyTripleSamples()
969 sensor->buffer.length += sizeof(struct TripleAxisDataPoint); in copyTripleSamples()
970 sensor->buffer.triple[numSamples].deltaTime = deltaTime | delta_time_fine_mask; in copyTripleSamples()
971 sensor->buffer.triple[numSamples].ix = triple->samples[i].ix; in copyTripleSamples()
972 sensor->buffer.triple[numSamples].iy = triple->samples[i].iy; in copyTripleSamples()
973 sensor->buffer.triple[numSamples].iz = triple->samples[i].iz; in copyTripleSamples()
974 sensor->lastTime += deltaTime; in copyTripleSamples()
976 … sensor->buffer.firstSample.biasCurrent = triple->samples[0].firstSample.biasCurrent; in copyTripleSamples()
977 sensor->buffer.firstSample.biasPresent = 1; in copyTripleSamples()
978 sensor->buffer.firstSample.biasSample = numSamples; in copyTripleSamples()
979 sensor->discard = false; in copyTripleSamples()
981 sensor->buffer.firstSample.numSamples++; in copyTripleSamples()
982 sensor->curSamples++; in copyTripleSamples()
1013 static void queueFlush(struct ActiveSensor *sensor) in queueFlush() argument
1015 if (sensor->buffer.length == 0) { in queueFlush()
1016 … sensor->buffer.length = sizeof(sensor->buffer.referenceTime) + sizeof(struct SensorFirstSample); in queueFlush()
1017 sensor->buffer.referenceTime = 0ull; in queueFlush()
1018 if (sensor->interrupt == NANOHUB_INT_WAKEUP) in queueFlush()
1020 else if (sensor->interrupt == NANOHUB_INT_NONWAKEUP) in queueFlush()
1022 sensor->buffer.firstSample.numFlushes = 1; in queueFlush()
1024 sensor->buffer.firstSample.numFlushes++; in queueFlush()
1026 sensor->discard = false; in queueFlush()
1027 hostIntfSetInterrupt(sensor->interrupt); in queueFlush()
1049 struct ActiveSensor *sensor; in hostIntfHandleEvent() local
1118 sensor = mActiveSensorTable + mSensorList[cmd->sensType - 1]; in hostIntfHandleEvent()
1120 if (sensor->sensorHandle) { in hostIntfHandleEvent()
1122 sensorFlush(sensor->sensorHandle); in hostIntfHandleEvent()
1124 … if (sensorRequestRateChange(mHostIntfTid, sensor->sensorHandle, cmd->rate, cmd->latency)) { in hostIntfHandleEvent()
1125 sensor->rate = cmd->rate; in hostIntfHandleEvent()
1126 if (sensor->latency != cmd->latency) { in hostIntfHandleEvent()
1127 if (!sensor->latency) { in hostIntfHandleEvent()
1136 sensor->latency = cmd->latency; in hostIntfHandleEvent()
1140 sensorRelease(mHostIntfTid, sensor->sensorHandle); in hostIntfHandleEvent()
1142 if (sensor->latency) { in hostIntfHandleEvent()
1148 sensor->rate = 0; in hostIntfHandleEvent()
1149 sensor->latency = 0; in hostIntfHandleEvent()
1150 sensor->oneshot = false; in hostIntfHandleEvent()
1151 sensor->sensorHandle = 0; in hostIntfHandleEvent()
1152 if (sensor->buffer.length) { in hostIntfHandleEvent()
1153 …simpleQueueEnqueue(mOutputQ, &sensor->buffer, sizeof(uint32_t) + sensor->buffer.length, sensor->di… in hostIntfHandleEvent()
1154 hostIntfSetInterrupt(sensor->interrupt); in hostIntfHandleEvent()
1155 resetBuffer(sensor); in hostIntfHandleEvent()
1159 for (i = 0; sensorFind(cmd->sensType, i, &sensor->sensorHandle) != NULL; i++) { in hostIntfHandleEvent()
1162 sensor->oneshot = true; in hostIntfHandleEvent()
1164 sensor->oneshot = false; in hostIntfHandleEvent()
1167 … if (sensorRequest(mHostIntfTid, sensor->sensorHandle, cmd->rate, cmd->latency)) { in hostIntfHandleEvent()
1172 sensor->rate = cmd->rate; in hostIntfHandleEvent()
1173 sensor->latency = cmd->latency; in hostIntfHandleEvent()
1177 sensor->sensorHandle = 0; in hostIntfHandleEvent()
1187 queueFlush(sensor); in hostIntfHandleEvent()
1195 sensor = mActiveSensorTable + mSensorList[(evtType & 0xFF) - 1]; in hostIntfHandleEvent()
1197 if (sensor->sensorHandle) { in hostIntfHandleEvent()
1199 queueFlush(sensor); in hostIntfHandleEvent()
1201 if (sensor->buffer.length > 0) { in hostIntfHandleEvent()
1202 if (sensor->buffer.firstSample.numFlushes > 0) { in hostIntfHandleEvent()
1203 …if (!(simpleQueueEnqueue(mOutputQ, &sensor->buffer, sizeof(uint32_t) + sensor->buffer.length, sens… in hostIntfHandleEvent()
1206 resetBuffer(sensor); in hostIntfHandleEvent()
1207 } else if (sensor->buffer.firstSample.numSamples == sensor->packetSamples) { in hostIntfHandleEvent()
1208 …simpleQueueEnqueue(mOutputQ, &sensor->buffer, sizeof(uint32_t) + sensor->buffer.length, sensor->di… in hostIntfHandleEvent()
1209 resetBuffer(sensor); in hostIntfHandleEvent()
1213 switch (sensor->numAxis) { in hostIntfHandleEvent()
1216 if (sensor->buffer.length > 0 && rtcTime - sensor->lastTime >= delta_time_max) { in hostIntfHandleEvent()
1217 …simpleQueueEnqueue(mOutputQ, &sensor->buffer, sizeof(uint32_t) + sensor->buffer.length, sensor->di… in hostIntfHandleEvent()
1218 resetBuffer(sensor); in hostIntfHandleEvent()
1220 if (sensor->buffer.length == 0) { in hostIntfHandleEvent()
1221 … sensor->buffer.length = sizeof(struct SingleAxisDataEvent) + sizeof(struct SingleAxisDataPoint); in hostIntfHandleEvent()
1222 sensor->lastTime = sensor->buffer.referenceTime = rtcTime; in hostIntfHandleEvent()
1223 if (sensor->interrupt == NANOHUB_INT_WAKEUP) in hostIntfHandleEvent()
1225 else if (sensor->interrupt == NANOHUB_INT_NONWAKEUP) in hostIntfHandleEvent()
1227 sensor->buffer.firstSample.numSamples = 1; in hostIntfHandleEvent()
1228 sensor->buffer.firstSample.interrupt = sensor->interrupt; in hostIntfHandleEvent()
1229 sensor->buffer.single[0].idata = (uint32_t)evtData; in hostIntfHandleEvent()
1231 sensor->buffer.length += sizeof(struct SingleAxisDataPoint); in hostIntfHandleEvent()
1232 …sensor->buffer.single[sensor->buffer.firstSample.numSamples].deltaTime = encodeDeltaTime(rtcTime -… in hostIntfHandleEvent()
1233 sensor->lastTime = rtcTime; in hostIntfHandleEvent()
1234 … sensor->buffer.single[sensor->buffer.firstSample.numSamples].idata = (uint32_t)evtData; in hostIntfHandleEvent()
1235 sensor->buffer.firstSample.numSamples++; in hostIntfHandleEvent()
1237 if (sensor->curSamples++ == 0) in hostIntfHandleEvent()
1238 sensor->firstTime = sensor->buffer.referenceTime; in hostIntfHandleEvent()
1241 copySingleSamples(sensor, evtData); in hostIntfHandleEvent()
1244 if (sensor->raw) in hostIntfHandleEvent()
1245 copyTripleSamplesRaw(sensor, evtData); in hostIntfHandleEvent()
1247 copyTripleSamples(sensor, evtData); in hostIntfHandleEvent()
1256 if (sensor->firstTime && in hostIntfHandleEvent()
1257 ((rtcTime >= sensor->firstTime + sensor->latency) || in hostIntfHandleEvent()
1258 ((sensor->latency > sensorGetCurLatency(sensor->sensorHandle)) && in hostIntfHandleEvent()
1259 … (rtcTime + sensorGetCurLatency(sensor->sensorHandle) > sensor->firstTime + sensor->latency)))) { in hostIntfHandleEvent()
1260 interrupt = sensor->interrupt; in hostIntfHandleEvent()
1262 interrupt = sensor->interrupt; in hostIntfHandleEvent()
1267 if (sensor->oneshot) { in hostIntfHandleEvent()
1268 sensorRelease(mHostIntfTid, sensor->sensorHandle); in hostIntfHandleEvent()
1270 sensor->sensorHandle = 0; in hostIntfHandleEvent()
1271 sensor->oneshot = false; in hostIntfHandleEvent()
1276 switch (sensor->numAxis) { in hostIntfHandleEvent()
1279 copyTripleSamples(sensor, evtData); in hostIntfHandleEvent()
1280 nanohubPrefetchTx(sensor->interrupt, mWakeupBlocks, mNonWakeupBlocks); in hostIntfHandleEvent()