Skip to content

Commit

Permalink
code optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Blue-Crescent committed Feb 14, 2024
1 parent 36856c9 commit e262645
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/JJYReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ time_t JJYReceiver::clock_tick(){
int JJYReceiver::distance(const volatile uint8_t* arr1,volatile uint8_t* arr2, int size) {
int hammingDistance = 0;
uint8_t temp;
for (int i = 0; i < size; i++) {
for (uint8_t i = 0; i < size; i++) {
temp = ~(arr1[i] ^ arr2[i]);
for(int j = 0; j < 8; j++){
for(uint8_t j = 0; j < 8; j++){
if (((temp >> j) & 0x1) == 1) {
hammingDistance++;
}
Expand Down Expand Up @@ -95,9 +95,9 @@ void JJYReceiver::shift_in(uint8_t data,volatile uint8_t* sampling, int length){
}

bool JJYReceiver::timeCheck(){
int compare[4][2] = {{0, 1}, {0, 2}, {1, 0}, {1, 2} };
int compare[3][2] = {{0, 1}, {0, 2}, {1, 2} };
uint8_t min1,min2;
for (int i = 0; i < 4; i++) {
for (int i = 0; i < 3; i++) {
min1 = ((jjydata[compare[i][0]].bits.min >> 5) & 0x7) * 10 + (jjydata[compare[i][0]].bits.min & 0x0f) + 1;
min2 = ((jjydata[compare[i][1]].bits.min >> 5) & 0x7) * 10 + (jjydata[compare[i][1]].bits.min & 0x0f) + 2;
if (jjydata[compare[i][0]].bits.year == jjydata[compare[i][1]].bits.year &&
Expand All @@ -108,7 +108,7 @@ bool JJYReceiver::timeCheck(){
{
last_jjydata[0] = (min2 > min1) ? jjydata[compare[i][1]] : jjydata[compare[i][0]];
state = TIMEVALID;
stop();
power(false);
return true;
}
}
Expand All @@ -123,7 +123,6 @@ time_t JJYReceiver::get_time(uint8_t index) {
return updateTimeInfo(jjydata,index,1);
}
time_t JJYReceiver::getTime() {
uint16_t year,yday;
switch(state){
case INIT:
return -1;
Expand Down Expand Up @@ -284,6 +283,7 @@ void JJYReceiver::begin(){

void JJYReceiver::stop(){
power(false);
state = TIMETICK;
}

//timeinfo.tm_yday = // Day of the year is not implmented in Arduino time.h
Expand Down

0 comments on commit e262645

Please sign in to comment.