Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Just some refactoring #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 23 additions & 24 deletions Software/ATmega32U4/HackCube.cpp
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
#include "HackCube.h"

HackCube::Cube(void){
HackCube::Cube(void) {

};

void HackCube::Begin()
{
void HackCube::Begin() {

};

void HackCube::pinSetup(){
pinMode(nRF_CS_1, OUTPUT);
pinMode(nRF_CE,OUTPUT);
void HackCube::pinSetup() {
pinMode(nRF_CS_1, OUTPUT);
pinMode(nRF_CE, OUTPUT);

pinMode(RF433_CS, OUTPUT);
pinMode(RF433_GDO0,OUTPUT);
pinMode(RF433_GDO2, INPUT);

digitalWrite(RF433_CS, HIGH);
digitalWrite(RF433_GDO0, LOW);
digitalWrite(RF315_CS, HIGH);
digitalWrite(RF315_GDO0, LOW);
pinMode(RF433_CS, OUTPUT);
pinMode(RF433_GDO0, OUTPUT);
pinMode(RF433_GDO2, INPUT);

pinMode(RF315_CS, OUTPUT);
pinMode(RF315_GDO0,OUTPUT);
pinMode(RF315_GDO2, INPUT);
digitalWrite(RF433_CS, HIGH);
digitalWrite(RF433_GDO0, LOW);
digitalWrite(RF315_CS, HIGH);
digitalWrite(RF315_GDO0, LOW);

pinMode(RF_EN, OUTPUT);
digitalWrite(RF_EN, HIGH);
pinMode(RF315_CS, OUTPUT);
pinMode(RF315_GDO0, OUTPUT);
pinMode(RF315_GDO2, INPUT);

pinMode(ID_OUT, INPUT);
pinMode(MOD, OUTPUT);
pinMode(SHD, OUTPUT);
pinMode(RF_EN, OUTPUT);
digitalWrite(RF_EN, HIGH);

digitalWrite(MOD,LOW);
digitalWrite(SHD,LOW);
pinMode(ID_OUT, INPUT);
pinMode(MOD, OUTPUT);
pinMode(SHD, OUTPUT);

digitalWrite(MOD, LOW);
digitalWrite(SHD, LOW);
};
17 changes: 9 additions & 8 deletions Software/ATmega32U4/HackCube.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@

#include "Pin.h"

class HackCube{
class HackCube {

public:
Cube(void);
// 初始化模块
void Begin();
// 将模块io设置为对应的输入输出模式
void pinSetup();
Cube(void);

private:
int pin;
// 初始化模块
void Begin();

// 将模块io设置为对应的输入输出模式
void pinSetup();

private:
int pin;
};

#endif
17 changes: 8 additions & 9 deletions Software/ATmega32U4/HackRadio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//#if defined(__AVR_ATmega1280__)

//#if defined (MCU_STM32F103R)
#if defined(__STM32F1__)
#if defined(__STM32F1__)
#include "itoa.h"
#endif
//
Expand Down Expand Up @@ -74,7 +74,6 @@ void HackRadio::transmit(int nHighPulses, int nLowPulses) {


void HackRadio::Send0() {

this->transmit(721,390);//690 420
//Serial.print("0");
}
Expand Down Expand Up @@ -184,13 +183,13 @@ void HackRadio::handleInterrupt() {
static unsigned int changeCount;
static unsigned long lastTime;
static unsigned int repeatCount;

long time = micros();
duration = time - lastTime;

if (
changeCount > 155
&& duration > HackRadio::timings[0] - 4000
&& duration > HackRadio::timings[0] - 4000
&& duration < HackRadio::timings[0] + 4000
&& HackRadio::timings[24]<4500
&& HackRadio::timings[24]>3500
Expand All @@ -204,29 +203,29 @@ void HackRadio::handleInterrupt() {
}



if (changeCount >= HackRadio_MAX_CHANGES) {
changeCount = 0;
repeatCount = 0;
}
HackRadio::timings[changeCount++] = duration;
lastTime = time;
lastTime = time;
}

bool HackRadio::receiveProtocol2(unsigned int changeCount){
String sn;
String tiaoma;
String action;
unsigned long delay = HackRadio::timings[0] / 31;
unsigned long delayTolerance = delay * HackRadio::nReceiveTolerance * 0.01;
unsigned long delayTolerance = delay * HackRadio::nReceiveTolerance * 0.01;
for (int i = 25 ; i< 89 ; i=i+2){
if (HackRadio::timings[i] < HackRadio::timings[i+1]){
if (HackRadio::timings[i] < HackRadio::timings[i+1]){
tiaoma +="0";
} else if (HackRadio::timings[i] > HackRadio::timings[i+1]) {
tiaoma +="1";
}
}
for (int i = 89 ; i< 145 ; i=i+2) {
for (int i = 89 ; i< 145 ; i=i+2) {
if (HackRadio::timings[i] < HackRadio::timings[i+1]) {
sn +="0";
} else if (HackRadio::timings[i] > HackRadio::timings[i+1]) {
Expand Down
6 changes: 3 additions & 3 deletions Software/ATmega32U4/HackRadio.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class HackRadio{
static void handleInterrupt();
static bool receiveProtocol2(unsigned int changeCount);
static String dec4bin(String data);
String getkey();
String getsn();
String getaction();
String getKey();
String getSN();
String getAction();

bool available();
void resetAvailable();
Expand Down
Loading