Попробовал Amarino plug-in скомпилировать отсюда (http://www.amarino-toolkit.net/index.php/plug-in.html) - Eclipse матюкается и ничего не получается...
Liliput 629 GL, Intel Atom N230 1.6, HDD 200 GB, ОЗУ 2GB, Globalsat GT-100.
Обновленный скетч с поддержкой камеры
Код:#include <IRremote.h> #include <OneWire.h> #include <DallasTemperature.h> #include <Wire.h> #include <SPI.h> #include <MeetAndroid.h> #define HEATER1 19 //#define HEATER1 6 #define HEATER2 41 #define AMP_ON 16 #define AUDIO_MUTE 17 #define AD_SELECT 20 // Data wire is plugged into pin 25 on the Arduino #define ONE_WIRE_BUS 25 const int RECV_PIN = 26; #define FAN_DIRECTION_PWM 27 #define POWER_SWITCH 38 #define AUDIO_ON 44 #define ACC 45 #define CLIMATE_POWER 42 #define CLIMATE_REC 43 #define DS1307_I2C_ADDRESS 0x68 #define TDA7318_I2C_ADDRESS 0x44 #define TDA_SW1 0x58 #define TDA_SW2 0x59 #define TDA_SW3 0x5A #define TDA_SW4 0x5B // LM pins #define LM_CE 14 //LM7001 PIN3 #define LM_CL 13 //LM7001 PIN4 #define LM_DA 12 //LM7001 PIN5 // LM delay in microsec #define LM_DELAY 2 #define RADIO_MIN_FREQUENCY 880 #define RADIO_MAX_FREQUENCY 1080 DeviceAddress intTempSensor = { 0x28, 0x44, 0x0A, 0xD8, 0x02, 0x00, 0x00, 0x58 }; DeviceAddress extTempSensor = { 0x28, 0xA8, 0xE4, 0x7D, 0x02, 0x00, 0x00, 0x5C }; DeviceAddress hlTempSensor = { 0x28, 0x7C, 0xDF, 0xD7, 0x02, 0x00, 0x00, 0x02 }; DeviceAddress hrTempSensor = { 0x28, 0xB6, 0x1A, 0x7E, 0x02, 0x00, 0x00, 0x98 }; byte climateTempMap[] = {255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,225,200, 175,150,130,105,80,60,40,0x00}; byte climateFanMap[] = {0,16,32,48,64,80,96,112,128,144, 160,176,192,208,224,255}; byte climateDirectionMap[] = {0,0,64,128,255}; byte volMap[] = {0x3F,0x3D,0x3B,0x39,0x37,0x35,0x33,0x31, 0x2F,0x2D,0x2B,0x29,0x27,0x25,0x23,0x21, 0x1F,0x1D,0x1B,0x19,0x17,0x15,0x13,0x11, 0x0F,0x0D,0x0B,0x09,0x07,0x05,0x03,0x00}; byte lfAttMap[] = {0x9F,0x9D,0x9B,0x99,0x97,0x95,0x93,0x91, 0x8F,0x8D,0x8B,0x89,0x87,0x85,0x83,0x80}; byte rfAttMap[] = {0xBF,0xBD,0xBB,0xB9,0xB7,0xB5,0xB3,0xB1, 0xAF,0xAD,0xAB,0xA9,0xA7,0xA5,0xA3,0xA0}; byte lrAttMap[] = {0xDF,0xDD,0xDB,0xD9,0xD7,0xD5,0xD3,0xD1, 0xCF,0xCD,0xCB,0xC9,0xC7,0xC5,0xC3,0xC0}; byte rrAttMap[] = {0xFF,0xFD,0xFB,0xF9,0xF7,0xF5,0xF3,0xF1, 0xEF,0xED,0xEB,0xE9,0xE7,0xE5,0xE3,0xE0}; byte bassMap[] = {0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x6F, 0x6E,0x6D,0x6C,0x6B,0x6A,0x69,0x68}; byte trebleMap[] = {0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x7F, 0x7E,0x7D,0x7C,0x7B,0x7A,0x79,0x78}; byte currentVolume = 16; byte currentHeaterOff1 = 0; byte currentHeaterOn1 = 0; byte currentHeaterOff2 = 0; byte currentHeaterOn2 = 0; int heaterTimer1 = 0; int heaterTimer2 = 0; byte currentACCValue = 0; byte accTimer = 0; OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); IRrecv irrecv(RECV_PIN); decode_results results; MeetAndroid meetAndroid; HardwareSerial Uart = HardwareSerial(); void setup() { Uart.begin(9600); Serial.begin(9600); setCallbacks(); initTempSensors(); initTda(); initLM(); initAd(); initHeaters(); initIR(); pinMode(CLIMATE_POWER, OUTPUT); pinMode(CLIMATE_REC, OUTPUT); pinMode(POWER_SWITCH, OUTPUT); digitalWrite(POWER_SWITCH, LOW); pinMode(FAN_DIRECTION_PWM, OUTPUT); pinMode(AMP_ON, OUTPUT); pinMode(AUDIO_ON, OUTPUT); pinMode(AUDIO_MUTE, OUTPUT); } void loop() { meetAndroid.receive(); // you need to keep this in your loop() to receive events receiveIR(); receiveACC(); if (heaterTimer1 == 10000) { checkHeater1(); heaterTimer1 = 0; } if (heaterTimer2 == 15000) { checkHeater2(); heaterTimer2 = 0; } heaterTimer1++; heaterTimer2++; } void setCallbacks() { meetAndroid.registerFunction(getInternalTemperature, 'A'); //Internal temperature: 1 meetAndroid.registerFunction(setAudioBalance, 'B'); //Audio balance: 0-15 meetAndroid.registerFunction(setClimatePower, 'C'); //Climate power: 1-ON, 0-OFF meetAndroid.registerFunction(setClimateFanDirection, 'D'); //Climate fan direction: 1-direction 1, 2-direction 2, 3-direction 3, 4-direction 4 meetAndroid.registerFunction(getExternalTemperature, 'E'); //External temperature: 1 meetAndroid.registerFunction(setClimateFanSpeed, 'F'); //Climate fan speed: 0-15 meetAndroid.registerFunction(setHeaterOnTemperature1, 'G'); //Heater temp 1 ON: 25-ON, 0-OFF meetAndroid.registerFunction(setHeaterOnTemperature2, 'H'); //Heater temp 2 ON: 25-ON, 0-OFF meetAndroid.registerFunction(setClimateRecirculation, 'I'); //Climate internal recirculation: 1-ON, 0-OFF meetAndroid.registerFunction(setAudioBass, 'J'); //Audio bass: 0-14 meetAndroid.registerFunction(setAudioTreble, 'K'); //Audio treble: 0-14 meetAndroid.registerFunction(setAudioRearLeftVolume, 'L'); //Audio rear left volume: 0-15 meetAndroid.registerFunction(setAudioMute, 'M'); //Audio mute: 1-ON, 0-OFF meetAndroid.registerFunction(setHeaterOffTemperature1, 'N'); //Heater temp 1 OFF: 25-OFF, 0-OFF meetAndroid.registerFunction(setHeaterOffTemperature2, 'O'); //Heater temp 2 OFF: 25-OFF, 0-OFF meetAndroid.registerFunction(setPowerState, 'P'); //Power state: 1-ON, 0-OFF meetAndroid.registerFunction(setRadioFrequency, 'R'); //Radio frequency: (880-1080)-ON, 0-OFF meetAndroid.registerFunction(setAudioSource, 'S'); //Audio source: 2-radio, 3-music meetAndroid.registerFunction(setClimateTemperature, 'T'); //Climate temperature: 18-26 //meetAndroid.registerFunction(getCarVoltage, 'U'); //Car voltage: 1 meetAndroid.registerFunction(setAudioVolume, 'V'); //Audio volume: 0-31 meetAndroid.registerFunction(setAudioRearRightVolume, 'X'); //Audio rear right volume: 0-15 meetAndroid.registerFunction(getHeaterTemperature1, 'Y'); //Heater 1 meetAndroid.registerFunction(getHeaterTemperature2, 'Z'); //Heater 2 } void initTempSensors() { sensors.begin(); // set the resolution to 9 bit sensors.setResolution(intTempSensor, 9); sensors.setResolution(extTempSensor, 9); sensors.setResolution(hlTempSensor, 9); sensors.setResolution(hrTempSensor, 9); } void initTda() { sendAudioMute(1); sendAudioOn(1); delay(3000); sendAmpOn(1); Wire.begin(); // join i2c bus (address optional for master) sendAudioVolume(16); sendAudioLFAttenuator(15); sendAudioRFAttenuator(15); sendAudioLRAttenuator(15); sendAudioRRAttenuator(15); sendAudioSwitch(3); sendAudioBass(7); sendAudioTreble(7); sendAudioMute(0); } void initLM() { pinMode(LM_CE, OUTPUT); pinMode(LM_CL, OUTPUT); pinMode(LM_DA, OUTPUT); } void initAd(){ pinMode(AD_SELECT, OUTPUT); SPI.begin(); } void initHeaters() { pinMode(HEATER1, OUTPUT); pinMode(HEATER2, OUTPUT); } void initIR() { irrecv.enableIRIn(); irrecv.blink13(true); } void receiveIR() { if (irrecv.decode(&results)) { char buf[50]; sprintf(buf, "IR:%u", results.value); meetAndroid.send(buf); irrecv.resume(); } } void receiveACC() { int value = analogRead(ACC); if (value > 85 && currentACCValue == 0 && accTimer == 0) { currentACCValue = 1; accTimer = 200; meetAndroid.send("CAM:1"); } if (value < 85 && currentACCValue == 1 && accTimer == 0) { currentACCValue = 0; accTimer = 200; meetAndroid.send("CAM:0"); } if (accTimer > 0) { accTimer--; } } void checkHeater1() { if (currentHeaterOff1 != 0 && currentHeaterOn1 != 0) { sensors.requestTemperaturesByAddress(hlTempSensor); float tempC = sensors.getTempC(hlTempSensor); if (tempC != -127.00) { if (tempC > currentHeaterOff1) { digitalWrite(HEATER1, LOW); } if (tempC < currentHeaterOn1) { digitalWrite(HEATER1, HIGH); } } } else { digitalWrite(HEATER1, LOW); } } void checkHeater2() { if (currentHeaterOff2 != 0 && currentHeaterOn2 != 0) { sensors.requestTemperaturesByAddress(hrTempSensor); float tempC = sensors.getTempC(hrTempSensor); if (tempC != -127.00) { if (tempC > currentHeaterOff2) { digitalWrite(HEATER2, LOW); } if (tempC < currentHeaterOn2) { digitalWrite(HEATER2, HIGH); } } } else { digitalWrite(HEATER2, LOW); } } void writeI2c(byte address, byte value) { Wire.beginTransmission(address); Wire.send(value); Wire.endTransmission(); } void sendAudioMute(byte value) { digitalWrite(AUDIO_MUTE, value == 1 ? HIGH : LOW); } void sendAmpOn(byte value) { digitalWrite(AMP_ON, value == 1 ? HIGH : LOW); } void sendAudioOn(byte value) { digitalWrite(AUDIO_ON, value == 1 ? HIGH : LOW); } void sendAudioVolume(byte value) { if (value > 31) return; currentVolume = value; writeI2c(TDA7318_I2C_ADDRESS, volMap[value]); } void sendAudioLFAttenuator(byte value) { if (value > 15) return; writeI2c(TDA7318_I2C_ADDRESS, lfAttMap[value]); } void sendAudioRFAttenuator(byte value) { if (value > 15) return; writeI2c(TDA7318_I2C_ADDRESS, rfAttMap[value]); } void sendAudioLRAttenuator(byte value) { if (value > 15) return; writeI2c(TDA7318_I2C_ADDRESS, lrAttMap[value]); } void sendAudioRRAttenuator(byte value) { if (value > 15) return; writeI2c(TDA7318_I2C_ADDRESS, rrAttMap[value]); } void sendAudioBass(byte value) { if (value > 14) return; writeI2c(TDA7318_I2C_ADDRESS, bassMap[value]); } void sendAudioTreble(byte value) { if (value > 14) return; writeI2c(TDA7318_I2C_ADDRESS, trebleMap[value]); } void sendAudioSwitch(byte value) { switch (value) { case 1: writeI2c(TDA7318_I2C_ADDRESS, TDA_SW1); break; case 2: writeI2c(TDA7318_I2C_ADDRESS, TDA_SW2); break; case 3: writeI2c(TDA7318_I2C_ADDRESS, TDA_SW3); break; case 4: writeI2c(TDA7318_I2C_ADDRESS, TDA_SW4); break; } } void sendRadioFrequency(int frequency, boolean power) { frequency += 107; digitalWrite(LM_CE, HIGH); writeLM(byte(frequency)); writeLM(byte(frequency >> 8)); writeLM((power == true) ? 135 : 71); digitalWrite(LM_CE, LOW); } void writeLM(byte bytes) { int d; int d1; delayMicroseconds(LM_DELAY); for (int x=0; x <= 7; x++) { // Set DA d = bytes >> 1; d1 = d << 1; digitalWrite(LM_DA, bytes == d1 ? LOW : HIGH); // Make CL digitalWrite(LM_CL, HIGH); delayMicroseconds(LM_DELAY); digitalWrite(LM_CL, LOW); delayMicroseconds(LM_DELAY); bytes = bytes >> 1; } delayMicroseconds(LM_DELAY); } void getInternalTemperature(byte flag, byte numOfValues) { sensors.requestTemperaturesByAddress(intTempSensor); float tempC = sensors.getTempC(intTempSensor); meetAndroid.send(tempC == -127.00 ? 0 : tempC); } void setAudioBalance(byte flag, byte numOfValues) { int value = meetAndroid.getInt(); sendAudioLFAttenuator(value); sendAudioRFAttenuator(15 - value); } void setClimatePower(byte flag, byte numOfValues) { digitalWrite(CLIMATE_POWER, meetAndroid.getInt() == 1 ? HIGH : LOW); } void setClimateFanDirection(byte flag, byte numOfValues) { int value = meetAndroid.getInt(); if (value < 1 && value > 4) value = 1; analogWrite(FAN_DIRECTION_PWM, climateDirectionMap[value]); } void getExternalTemperature(byte flag, byte numOfValues) { sensors.requestTemperaturesByAddress(extTempSensor); float tempC = sensors.getTempC(extTempSensor); meetAndroid.send(tempC == -127.00 ? 0 : tempC); } void setClimateFanSpeed(byte flag, byte numOfValues) { int value = meetAndroid.getInt(); if (value < 0) value = 0; if (value > 15) value = 15; digitalPotWrite(0, climateFanMap[value]); } void getHeaterTemperature1(byte flag, byte numOfValues) { sensors.requestTemperaturesByAddress(hlTempSensor); float tempC = sensors.getTempC(hlTempSensor); meetAndroid.send(tempC == -127.00 ? 0 : tempC); } void getHeaterTemperature2(byte flag, byte numOfValues) { sensors.requestTemperaturesByAddress(hrTempSensor); float tempC = sensors.getTempC(hrTempSensor); meetAndroid.send(tempC == -127.00 ? 0 : tempC); } void setHeaterOnTemperature1(byte flag, byte numOfValues) { currentHeaterOn1 = meetAndroid.getInt(); } void setHeaterOffTemperature1(byte flag, byte numOfValues) { currentHeaterOff1 = meetAndroid.getInt(); } void setHeaterOnTemperature2(byte flag, byte numOfValues) { currentHeaterOn2 = meetAndroid.getInt(); } void setHeaterOffTemperature2(byte flag, byte numOfValues) { currentHeaterOff2 = meetAndroid.getInt(); } void setClimateRecirculation(byte flag, byte numOfValues) { digitalWrite(CLIMATE_REC, (meetAndroid.getInt() == 1) ? HIGH : LOW); } void setAudioBass(byte flag, byte numOfValues) { sendAudioBass(meetAndroid.getInt()); } void setAudioTreble(byte flag, byte numOfValues) { sendAudioTreble(meetAndroid.getInt()); } void setAudioRearLeftVolume(byte flag, byte numOfValues) { sendAudioLRAttenuator(meetAndroid.getInt()); } void setAudioMute(byte flag, byte numOfValues) { sendAudioMute(meetAndroid.getInt()); } void setPowerState(byte flag, byte numOfValues) { digitalWrite(POWER_SWITCH, (meetAndroid.getInt() == 1) ? HIGH : LOW); } void setRadioFrequency(byte flag, byte numOfValues) { int frequency = meetAndroid.getInt(); if (frequency == 0) { sendRadioFrequency(frequency, false); } else if (frequency >= RADIO_MIN_FREQUENCY && frequency <= RADIO_MAX_FREQUENCY){ sendRadioFrequency(frequency, true); } } void setAudioSource(byte flag, byte numOfValues) { sendAudioSwitch(meetAndroid.getInt()); } void setClimateTemperature(byte flag, byte numOfValues) { int value = meetAndroid.getInt(); if (value < 18) value = 0; if (value > 26) value = 27; digitalPotWrite(1, climateTempMap[value]); } void digitalPotWrite(byte address, byte value){ digitalWrite(AD_SELECT, LOW); SPI.transfer(address); SPI.transfer(value); digitalWrite(AD_SELECT, HIGH); } void getCarVoltage(byte flag, byte numOfValues) { float R1 = 9930.0; float R2 = 970.0; int value = analogRead(ACC); meetAndroid.send(((value * 5.0) / 1024.0) / (R2 / (R1 + R2))); } void setAudioVolume(byte flag, byte numOfValues) { sendAudioVolume(meetAndroid.getInt()); } void setAudioRearRightVolume(byte flag, byte numOfValues) { sendAudioRRAttenuator(meetAndroid.getInt()); }
Скетч для работы по сети
PHP код:
#include <OneWire.h>
#include <DallasTemperature.h>
#include <IRremote.h>
#include <Wire.h>
#include <SPI.h>
#include <Ethernet.h>
byte lanServerMac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress lanServerIp(192, 168, 1, 177);
int lanServerPort = 5202;
IPAddress lanClientIp(192, 168, 1, 1);
int lanCommandClientPort = 5102;
int localPort = 8888; // local port to listen on
int lanGPSClientPort = 8888;
#define HEATER1 19
#define HEATER2 41
#define AMP_ON 16
#define AUDIO_MUTE 17
// Data wire is plugged into pin 25 on the Arduino
#define ONE_WIRE_BUS 25
const int RECV_PIN = 26;
#define POWER_SWITCH 38
#define AUDIO_ON 44
#define ACC 45
#define CAM 10
#define TDA7318_I2C_ADDRESS 0x44
#define TDA_SW1 0x58
#define TDA_SW2 0x59
#define TDA_SW3 0x5A
#define TDA_SW4 0x5B
// LM pins
#define LM_CE 14 //LM7001 PIN3
#define LM_CL 13 //LM7001 PIN4
#define LM_DA 12 //LM7001 PIN5
// LM delay in microsec
#define LM_DELAY 2
#define RADIO_MIN_FREQUENCY 880
#define RADIO_MAX_FREQUENCY 1080
#define RADIO_SOURCE 2
#define MUSIC_SOURCE 3
DeviceAddress intTempSensor = { 0x28, 0x44, 0x0A, 0xD8, 0x02, 0x00, 0x00, 0x58 };
DeviceAddress extTempSensor = { 0x28, 0xA8, 0xE4, 0x7D, 0x02, 0x00, 0x00, 0x5C };
DeviceAddress hlTempSensor = { 0x28, 0x7C, 0xDF, 0xD7, 0x02, 0x00, 0x00, 0x02 };
DeviceAddress hrTempSensor = { 0x28, 0xB6, 0x1A, 0x7E, 0x02, 0x00, 0x00, 0x98 };
byte volMap[] = {0x3F,0x3D,0x3B,0x39,0x37,0x35,0x33,0x31,
0x2F,0x2D,0x2B,0x29,0x27,0x25,0x23,0x21,
0x1F,0x1D,0x1B,0x19,0x17,0x15,0x13,0x11,
0x0F,0x0D,0x0B,0x09,0x07,0x05,0x03,0x00};
byte lfAttMap[] = {0x9F,0x9D,0x9B,0x99,0x97,0x95,0x93,0x91,
0x8F,0x8D,0x8B,0x89,0x87,0x85,0x83,0x80};
byte rfAttMap[] = {0xBF,0xBD,0xBB,0xB9,0xB7,0xB5,0xB3,0xB1,
0xAF,0xAD,0xAB,0xA9,0xA7,0xA5,0xA3,0xA0};
byte lrAttMap[] = {0xDF,0xDD,0xDB,0xD9,0xD7,0xD5,0xD3,0xD1,
0xCF,0xCD,0xCB,0xC9,0xC7,0xC5,0xC3,0xC0};
byte rrAttMap[] = {0xFF,0xFD,0xFB,0xF9,0xF7,0xF5,0xF3,0xF1,
0xEF,0xED,0xEB,0xE9,0xE7,0xE5,0xE3,0xE0};
byte bassMap[] = {0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x6F,
0x6E,0x6D,0x6C,0x6B,0x6A,0x69,0x68};
byte trebleMap[] = {0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x7F,
0x7E,0x7D,0x7C,0x7B,0x7A,0x79,0x78};
byte currentVolume = 16;
byte currentHeaterOff1 = 0;
byte currentHeaterOn1 = 0;
byte currentHeaterOff2 = 0;
byte currentHeaterOn2 = 0;
unsigned long heaterTimer1 = 150000;
unsigned long heaterTimer2 = 0;
byte camTimer = 0;
String urlString = String(15);
int urlStringMaxLength = 15;
#define SOP '$'
#define EOP '\r'
boolean started = false;
boolean ended = false;
char inData[82]; // Size as appropriate
byte index = 0;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
IRrecv irrecv(RECV_PIN);
decode_results results;
HardwareSerial Uart = HardwareSerial();
EthernetServer CommandServer(lanServerPort);
EthernetUDP UdpClient;
void setup() {
Uart.begin(38400);
Serial.begin(9600);
initTempSensors();
initTda();
initLM();
initHeaters();
initIR();
initLanServer();
pinMode(POWER_SWITCH, OUTPUT);
digitalWrite(POWER_SWITCH, LOW);
pinMode(AMP_ON, OUTPUT);
pinMode(AUDIO_ON, OUTPUT);
pinMode(AUDIO_MUTE, OUTPUT);
pinMode(CAM, INPUT);
}
void loop() {
sendGPS();
receiveLan();
receiveIR();
receiveCAM();
checkHeaters();
}
void initTempSensors() {
sensors.begin();
// set the resolution to 9 bit
sensors.setResolution(intTempSensor, 9);
sensors.setResolution(extTempSensor, 9);
sensors.setResolution(hlTempSensor, 9);
sensors.setResolution(hrTempSensor, 9);
}
void initTda() {
sendAudioMute(1);
sendAudioOn(1);
delay(3000);
sendAmpOn(1);
Wire.begin(); // join i2c bus (address optional for master)
sendAudioVolume(16);
sendAudioLFAttenuator(15);
sendAudioRFAttenuator(15);
sendAudioLRAttenuator(15);
sendAudioRRAttenuator(15);
sendAudioSwitch(3);
sendAudioBass(7);
sendAudioTreble(7);
sendAudioMute(0);
}
void initLM() {
pinMode(LM_CE, OUTPUT);
pinMode(LM_CL, OUTPUT);
pinMode(LM_DA, OUTPUT);
}
void initHeaters() {
pinMode(HEATER1, OUTPUT);
pinMode(HEATER2, OUTPUT);
}
void initIR() {
irrecv.enableIRIn();
irrecv.blink13(true);
}
void initLanServer() {
Ethernet.begin(lanServerMac, lanServerIp);
UdpClient.begin(localPort);
CommandServer.begin();
}
void receiveIR() {
if (irrecv.decode(&results)) {
char buf[50];
sprintf(buf, "IR:%u", results.value);
sendLan(buf);
irrecv.resume();
}
}
void receiveCAM() {
int value = digitalRead(CAM);
if (value == 1 && camTimer == 0) {
camTimer = 10000;
sendLan("CAM:1");
}
if (camTimer > 0) {
camTimer--;
}
}
void checkHeaters() {
if (currentHeaterOff1 == 0 && currentHeaterOn1 == 0) {
//Serial.println("HEATER1: OFF");
digitalWrite(HEATER1, LOW);
}
else {
if (heaterTimer1 == 300000) {
heaterTimer1 = 0;
sensors.requestTemperaturesByAddress(hlTempSensor);
int tempL = sensors.getTempC(hlTempSensor);
if (tempL != -127) {
if (tempL >= currentHeaterOff1) {
Serial.println("HEATER1: OFF");
digitalWrite(HEATER1, LOW);
}
if (tempL <= currentHeaterOn1) {
Serial.println("HEATER1: ON");
digitalWrite(HEATER1, HIGH);
}
}
}
heaterTimer1++;
}
if (currentHeaterOff2 == 0 && currentHeaterOn2 == 0) {
//Serial.println("HEATER2: OFF");
digitalWrite(HEATER2, LOW);
}
else {
if (heaterTimer2 == 300000) {
heaterTimer2 = 0;
sensors.requestTemperaturesByAddress(hrTempSensor);
int tempR = sensors.getTempC(hrTempSensor);
if (tempR != -127) {
if (tempR >= currentHeaterOff2) {
Serial.println("HEATER2: OFF");
digitalWrite(HEATER2, LOW);
}
if (tempR <= currentHeaterOn2) {
Serial.println("HEATER2: ON");
digitalWrite(HEATER2, HIGH);
}
}
}
heaterTimer2++;
}
}
void writeI2c(byte address, byte value) {
Wire.beginTransmission(address);
Wire.send(value);
Wire.endTransmission();
}
void sendAudioMute(byte value) {
digitalWrite(AUDIO_MUTE, value == 1 ? HIGH : LOW);
}
void sendAmpOn(byte value) {
digitalWrite(AMP_ON, value == 1 ? HIGH : LOW);
}
void sendAudioOn(byte value) {
digitalWrite(AUDIO_ON, value == 1 ? HIGH : LOW);
}
void sendAudioVolume(byte value) {
if (value > 31) return;
currentVolume = value;
writeI2c(TDA7318_I2C_ADDRESS, volMap[value]);
}
void sendAudioLFAttenuator(byte value) {
if (value > 15) return;
writeI2c(TDA7318_I2C_ADDRESS, lfAttMap[value]);
}
void sendAudioRFAttenuator(byte value) {
if (value > 15) return;
writeI2c(TDA7318_I2C_ADDRESS, rfAttMap[value]);
}
void sendAudioLRAttenuator(byte value) {
if (value > 15) return;
writeI2c(TDA7318_I2C_ADDRESS, lrAttMap[value]);
}
void sendAudioRRAttenuator(byte value) {
if (value > 15) return;
writeI2c(TDA7318_I2C_ADDRESS, rrAttMap[value]);
}
void sendAudioBass(byte value) {
if (value > 14) return;
writeI2c(TDA7318_I2C_ADDRESS, bassMap[value]);
}
void sendAudioTreble(byte value) {
if (value > 14) return;
writeI2c(TDA7318_I2C_ADDRESS, trebleMap[value]);
}
void sendAudioSwitch(byte value) {
switch (value) {
case 1:
writeI2c(TDA7318_I2C_ADDRESS, TDA_SW1);
break;
case 2:
writeI2c(TDA7318_I2C_ADDRESS, TDA_SW2);
break;
case 3:
writeI2c(TDA7318_I2C_ADDRESS, TDA_SW3);
break;
case 4:
writeI2c(TDA7318_I2C_ADDRESS, TDA_SW4);
break;
}
}
void sendRadioFrequency(int frequency, boolean power) {
frequency += 107;
digitalWrite(LM_CE, HIGH);
writeLM(byte(frequency));
writeLM(byte(frequency >> 8));
writeLM((power == true) ? 135 : 71);
digitalWrite(LM_CE, LOW);
}
void writeLM(byte bytes) {
int d;
int d1;
delayMicroseconds(LM_DELAY);
for (int x=0; x <= 7; x++) {
// Set DA
d = bytes >> 1;
d1 = d << 1;
digitalWrite(LM_DA, bytes == d1 ? LOW : HIGH);
// Make CL
digitalWrite(LM_CL, HIGH);
delayMicroseconds(LM_DELAY);
digitalWrite(LM_CL, LOW);
delayMicroseconds(LM_DELAY);
bytes = bytes >> 1;
}
delayMicroseconds(LM_DELAY);
}
char* getTemperature(String param) {
char paramCommand[2];
param.toCharArray(paramCommand, 2);
float tempC;
if (strcmp(paramCommand, "E") == 0) {
sensors.requestTemperaturesByAddress(extTempSensor);
tempC = sensors.getTempC(extTempSensor);
}
else if (strcmp(paramCommand, "I") == 0) {
sensors.requestTemperaturesByAddress(intTempSensor);
tempC = sensors.getTempC(intTempSensor);
}
else if (strcmp(paramCommand, "L") == 0) {
sensors.requestTemperaturesByAddress(hlTempSensor);
tempC = sensors.getTempC(hlTempSensor);
}
else if (strcmp(paramCommand, "R") == 0) {
sensors.requestTemperaturesByAddress(hrTempSensor);
tempC = sensors.getTempC(hrTempSensor);
}
tempC = (tempC == -127.00) ? 0 : tempC;
char out[7];
dtostrf(tempC, 2, 2, out);
return out;
}
void setAudioBalance(String param) {
int value = getInt(param);
sendAudioLFAttenuator(value);
sendAudioRFAttenuator(15 - value);
}
void setHeaterOnTemperature1(String param) {
currentHeaterOn1 = getInt(param);
}
void setHeaterOffTemperature1(String param) {
currentHeaterOff1 = getInt(param);
}
void setHeaterOnTemperature2(String param) {
currentHeaterOn2 = getInt(param);
}
void setHeaterOffTemperature2(String param) {
currentHeaterOff2 = getInt(param);
}
void setAudioBass(String param) {
sendAudioBass(getInt(param));
}
void setAudioTreble(String param) {
sendAudioTreble(getInt(param));
}
void setAudioRearLeftVolume(String param) {
sendAudioLRAttenuator(getInt(param));
}
void setAudioMute(String param) {
sendAudioMute(getInt(param));
}
void setPowerState(String param) {
digitalWrite(POWER_SWITCH, (getInt(param) == 1) ? HIGH : LOW);
}
void setRadioFrequency(String param) {
int frequency = getInt(param);
if (frequency == 0) {
sendRadioFrequency(frequency, false);
setAudioSource(MUSIC_SOURCE);
}
else if (frequency >= RADIO_MIN_FREQUENCY && frequency <= RADIO_MAX_FREQUENCY){
sendRadioFrequency(frequency, true);
setAudioSource(RADIO_SOURCE);
}
}
void setAudioSource(String param) {
sendAudioSwitch(getInt(param));
}
char* getCarVoltage() {
float R1 = 9930.0;
float R2 = 970.0;
int value = analogRead(ACC);
value = ((value * 5.0) / 1024.0) / (R2 / (R1 + R2));
char out[7];
dtostrf(value, 2, 2, out);
return out;
}
void setAudioVolume(String param) {
sendAudioVolume(getInt(param));
}
void setAudioRearRightVolume(String param) {
sendAudioRRAttenuator(getInt(param));
}
void sendLan(char* data) {
Serial.println(data);
UdpClient.beginPacket(lanClientIp, lanCommandClientPort);
UdpClient.write(data);
UdpClient.endPacket();
}
void receiveLan() {
EthernetClient client = CommandServer.available();
if (client) {
String command;
String parameters = "";
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (urlString.length() < urlStringMaxLength) {
urlString += (c);
}
if (c == '\n' && currentLineIsBlank) {
Serial.println("Web request:");
Serial.println(urlString);
if (urlString.indexOf("?") >= 0) {
int posMark = urlString.indexOf("?") + 1;
int posHttp = urlString.indexOf("HTTP");
if (urlString.indexOf(",") >= 0) {
int posSemicolon = urlString.indexOf(",");
command = urlString.substring(posMark, posSemicolon);
parameters = urlString.substring(posSemicolon + 1, posHttp - 1);
}
else {
command = urlString.substring(posMark, posHttp - 1);
}
Serial.println("Web command received:");
Serial.println(command);
if (parameters.length() > 0) {
Serial.println("Parameters received:");
Serial.println(parameters);
}
}
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/plain");
client.println();
client.println(processLanCommand(command, parameters));
break;
}
if (c == '\n') {
currentLineIsBlank = true;
}
else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
delay(1);
urlString = "";
client.stop();
}
}
char* processLanCommand(String command, String parameters) {
char charCommand[2];
command.toCharArray(charCommand, 2);
if (strcmp(charCommand, "T") == 0) {
return getTemperature(parameters);
}
else if (strcmp(charCommand, "B") == 0) {
setAudioBalance(parameters);
return "1";
}
else if (strcmp(charCommand, "G") == 0) {
setHeaterOnTemperature1(parameters);
return "1";
}
else if (strcmp(charCommand, "H") == 0) {
setHeaterOnTemperature2(parameters);
return "1";
}
else if (strcmp(charCommand, "J") == 0) {
setAudioBass(parameters);
return "1";
}
else if (strcmp(charCommand, "K") == 0) {
setAudioTreble(parameters);
return "1";
}
else if (strcmp(charCommand, "L") == 0) {
setAudioRearLeftVolume(parameters);
return "1";
}
else if (strcmp(charCommand, "M") == 0) {
setAudioMute(parameters);
return "1";
}
else if (strcmp(charCommand, "N") == 0) {
setHeaterOffTemperature1(parameters);
return "1";
}
else if (strcmp(charCommand, "O") == 0) {
setHeaterOffTemperature2(parameters);
return "1";
}
else if (strcmp(charCommand, "P") == 0) {
setPowerState(parameters);
return "1";
}
else if (strcmp(charCommand, "R") == 0) {
setRadioFrequency(parameters);
return "1";
}
else if (strcmp(charCommand, "S") == 0) {
setAudioSource(parameters);
return "1";
}
else if (strcmp(charCommand, "U") == 0) {
return getCarVoltage();
}
else if (strcmp(charCommand, "V") == 0) {
setAudioVolume(parameters);
return "1";
}
else if (strcmp(charCommand, "X") == 0) {
setAudioRearRightVolume(parameters);
return "1";
}
return "";
/*
registerFunction(getTemperature, 'T'); //Temperature: E - external, I - internal, L - left heater, R - right heater
192.168.1.177:5202/?T,E
192.168.1.177:5202/?T,I
192.168.1.177:5202/?T,L
192.168.1.177:5202/?T,R
registerFunction(setAudioBalance, 'B'); //Audio balance: 0-15
192.168.1.177:5202/?B,6
registerFunction(setHeaterOnTemperature1, 'G'); //Heater temp 1 ON: 25-ON, 0-OFF
192.168.1.177:5202/?G,0
192.168.1.177:5202/?G,25
registerFunction(setHeaterOnTemperature2, 'H'); //Heater temp 2 ON: 25-ON, 0-OFF
192.168.1.177:5202/?H,0
192.168.1.177:5202/?H,25
registerFunction(setAudioBass, 'J'); //Audio bass: 0-14
192.168.1.177:5202/?J,6
registerFunction(setAudioTreble, 'K'); //Audio treble: 0-14
192.168.1.177:5202/?K,6
registerFunction(setAudioRearLeftVolume, 'L'); //Audio rear left volume: 0-15
192.168.1.177:5202/?L,5
registerFunction(setAudioMute, 'M'); //Audio mute: 1-ON, 0-OFF
192.168.1.177:5202/?M,1
192.168.1.177:5202/?M,0
registerFunction(setHeaterOffTemperature1, 'N'); //Heater temp 1 OFF: 25-OFF, 0-OFF
192.168.1.177:5202/?N,0
192.168.1.177:5202/?N,25
registerFunction(setHeaterOffTemperature2, 'O'); //Heater temp 2 OFF: 25-OFF, 0-OFF
192.168.1.177:5202/?O,0
192.168.1.177:5202/?O,25
registerFunction(setPowerState, 'P'); //Power state: 1-ON, 0-OFF
192.168.1.177:5202/?P,1
192.168.1.177:5202/?P,0
registerFunction(setRadioFrequency, 'R'); //Radio frequency: (880-1080)-ON, 0-OFF
192.168.1.177:5202/?R,0
192.168.1.177:5202/?R,1079
registerFunction(setAudioSource, 'S'); //Audio source: 2-radio, 3-music
192.168.1.177:5202/?S,2
192.168.1.177:5202/?S,3
registerFunction(getCarVoltage, 'U'); //Car voltage: 1
192.168.1.177:5202/?U
registerFunction(setAudioVolume, 'V'); //Audio volume: 0-31
192.168.1.177:5202/?V,4
registerFunction(setAudioRearRightVolume, 'X'); //Audio rear right volume: 0-15
192.168.1.177:5202/?X,4
*/
}
int getInt(String param) {
return param.toInt();
}
void sendGPS() {
while(Uart.available() > 0) {
char inChar = Uart.read();
if (inChar == SOP) {
started = true;
index = 0;
inData[index++] = inChar;
inData[index] = '\0';
}
else if (inChar == EOP) {
ended = true;
break;
}
else {
if (index < 82-1) {
inData[index++] = inChar;
inData[index] = '\0';
}
}
}
if (started && ended) {
Serial.print("UDP sent: ");
Serial.println(inData);
UdpClient.beginPacket(lanClientIp, lanGPSClientPort);
UdpClient.write(inData);
UdpClient.endPacket();
started = false;
ended = false;
index = 0;
inData[82];
}
}
Последний раз редактировалось s.m.; 10.07.2012 в 05:32.
Скетч для работы с ком-портом - улучшена работа с термометрами
PHP код:
#include <IRremote.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <MeetAndroid.h>
#define HEATER1 19
#define HEATER2 41
#define AMP_ON 16
#define AUDIO_MUTE 17
#define ONE_WIRE_BUS 25
const int RECV_PIN = 26;
#define AUDIO_ON 44
#define CAM 10
#define TDA7318_I2C_ADDRESS 0x44
#define TDA_SW1 0x58
#define TDA_SW2 0x59
#define TDA_SW3 0x5A
#define TDA_SW4 0x5B
// LM pins
#define LM_CE 14 //LM7001 PIN3
#define LM_CL 13 //LM7001 PIN4
#define LM_DA 12 //LM7001 PIN5
// LM delay in microsec
#define LM_DELAY 2
#define RADIO_MIN_FREQUENCY 880
#define RADIO_MAX_FREQUENCY 1080
#define RADIO_SOURCE 2
#define MUSIC_SOURCE 3
DeviceAddress intTempSensor = { 0x28, 0x44, 0x0A, 0xD8, 0x02, 0x00, 0x00, 0x58 };
DeviceAddress extTempSensor = { 0x28, 0xA8, 0xE4, 0x7D, 0x02, 0x00, 0x00, 0x5C };
DeviceAddress hlTempSensor = { 0x28, 0x7C, 0xDF, 0xD7, 0x02, 0x00, 0x00, 0x02 };
DeviceAddress hrTempSensor = { 0x28, 0xB6, 0x1A, 0x7E, 0x02, 0x00, 0x00, 0x98 };
byte volMap[] = {0x3F,0x3D,0x3B,0x39,0x37,0x35,0x33,0x31,
0x2F,0x2D,0x2B,0x29,0x27,0x25,0x23,0x21,
0x1F,0x1D,0x1B,0x19,0x17,0x15,0x13,0x11,
0x0F,0x0D,0x0B,0x09,0x07,0x05,0x03,0x00};
byte lfAttMap[] = {0x9F,0x9D,0x9B,0x99,0x97,0x95,0x93,0x91,
0x8F,0x8D,0x8B,0x89,0x87,0x85,0x83,0x80};
byte rfAttMap[] = {0xBF,0xBD,0xBB,0xB9,0xB7,0xB5,0xB3,0xB1,
0xAF,0xAD,0xAB,0xA9,0xA7,0xA5,0xA3,0xA0};
byte lrAttMap[] = {0xDF,0xDD,0xDB,0xD9,0xD7,0xD5,0xD3,0xD1,
0xCF,0xCD,0xCB,0xC9,0xC7,0xC5,0xC3,0xC0};
byte rrAttMap[] = {0xFF,0xFD,0xFB,0xF9,0xF7,0xF5,0xF3,0xF1,
0xEF,0xED,0xEB,0xE9,0xE7,0xE5,0xE3,0xE0};
byte bassMap[] = {0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x6F,
0x6E,0x6D,0x6C,0x6B,0x6A,0x69,0x68};
byte trebleMap[] = {0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x7F,
0x7E,0x7D,0x7C,0x7B,0x7A,0x79,0x78};
byte currentVolume = 16;
byte currentHeaterOff1 = 0;
byte currentHeaterOn1 = 0;
byte currentHeaterOff2 = 0;
byte currentHeaterOn2 = 0;
unsigned long heaterTimer1 = 150000;
unsigned long heaterTimer2 = 0;
unsigned long camTimer = 0;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
IRrecv irrecv(RECV_PIN);
decode_results results;
MeetAndroid meetAndroid;
HardwareSerial Uart = HardwareSerial();
void setup() {
Uart.begin(38400);
Serial.begin(9600);
setCallbacks();
initTempSensors();
initTda();
initLM();
initHeaters();
initIR();
pinMode(AMP_ON, OUTPUT);
pinMode(AUDIO_ON, OUTPUT);
pinMode(AUDIO_MUTE, OUTPUT);
pinMode(CAM, INPUT);
}
void loop() {
meetAndroid.receive();
receiveIR();
receiveCAM();
checkHeaters();
}
void setCallbacks() {
meetAndroid.registerFunction(getInternalTemperature, 'A'); //Internal temperature: 1
meetAndroid.registerFunction(setAudioBalance, 'B'); //Audio balance: 0-15
meetAndroid.registerFunction(setHeaterOnTemperature1, 'G'); //Heater temp 1 ON: 25-ON, 0-OFF
meetAndroid.registerFunction(setHeaterOnTemperature2, 'H'); //Heater temp 2 ON: 25-ON, 0-OFF
meetAndroid.registerFunction(getExternalTemperature, 'E'); //External temperature: 1
meetAndroid.registerFunction(setAudioBass, 'J'); //Audio bass: 0-14
meetAndroid.registerFunction(setAudioTreble, 'K'); //Audio treble: 0-14
meetAndroid.registerFunction(setAudioRearLeftVolume, 'L'); //Audio rear left volume: 0-15
meetAndroid.registerFunction(setAudioMute, 'M'); //Audio mute: 1-ON, 0-OFF
meetAndroid.registerFunction(setHeaterOffTemperature1, 'N'); //Heater temp 1 OFF: 25-OFF, 0-OFF
meetAndroid.registerFunction(setHeaterOffTemperature2, 'O'); //Heater temp 2 OFF: 25-OFF, 0-OFF
meetAndroid.registerFunction(setRadioFrequency, 'R'); //Radio frequency: (880-1080)-ON, 0-OFF
meetAndroid.registerFunction(setAudioSource, 'S'); //Audio source: 2-radio, 3-music
meetAndroid.registerFunction(setAudioVolume, 'V'); //Audio volume: 0-31
meetAndroid.registerFunction(setAudioRearRightVolume, 'X'); //Audio rear right volume: 0-15
meetAndroid.registerFunction(getHeaterTemperature1, 'Y'); //Heater 1
meetAndroid.registerFunction(getHeaterTemperature2, 'Z'); //Heater 2
}
void initTempSensors() {
sensors.begin();
// set the resolution to 9 bit
sensors.setResolution(intTempSensor, 9);
sensors.setResolution(extTempSensor, 9);
sensors.setResolution(hlTempSensor, 9);
sensors.setResolution(hrTempSensor, 9);
}
void initTda() {
sendAudioMute(1);
sendAudioOn(1);
delay(3000);
sendAmpOn(1);
Wire.begin(); // join i2c bus (address optional for master)
sendAudioVolume(16);
sendAudioLFAttenuator(15);
sendAudioRFAttenuator(15);
sendAudioLRAttenuator(15);
sendAudioRRAttenuator(15);
sendAudioSwitch(3);
sendAudioBass(7);
sendAudioTreble(7);
sendAudioMute(0);
}
void initLM() {
pinMode(LM_CE, OUTPUT);
pinMode(LM_CL, OUTPUT);
pinMode(LM_DA, OUTPUT);
}
void initHeaters() {
pinMode(HEATER1, OUTPUT);
pinMode(HEATER2, OUTPUT);
}
void initIR() {
irrecv.enableIRIn();
irrecv.blink13(true);
}
void receiveIR() {
if (irrecv.decode(&results)) {
char buf[50];
sprintf(buf, "IR:%u", results.value);
meetAndroid.send(buf);
irrecv.resume();
}
}
void receiveCAM() {
int value = digitalRead(CAM);
if (value == 1 && camTimer == 0) {
camTimer = 3000;
meetAndroid.send("CAM:1");
}
if (camTimer > 0) {
camTimer--;
}
}
void checkHeaters() {
if (currentHeaterOff1 == 0 && currentHeaterOn1 == 0) {
//Serial.println("HEATER1: OFF");
digitalWrite(HEATER1, LOW);
}
else {
if (heaterTimer1 == 300000) {
heaterTimer1 = 0;
sensors.requestTemperaturesByAddress(hlTempSensor);
int tempL = sensors.getTempC(hlTempSensor);
if (tempL != -127) {
if (tempL >= currentHeaterOff1) {
Serial.println("HEATER1: OFF");
digitalWrite(HEATER1, LOW);
}
if (tempL <= currentHeaterOn1) {
Serial.println("HEATER1: ON");
digitalWrite(HEATER1, HIGH);
}
}
}
heaterTimer1++;
}
if (currentHeaterOff2 == 0 && currentHeaterOn2 == 0) {
//Serial.println("HEATER2: OFF");
digitalWrite(HEATER2, LOW);
}
else {
if (heaterTimer2 == 300000) {
heaterTimer2 = 0;
sensors.requestTemperaturesByAddress(hrTempSensor);
int tempR = sensors.getTempC(hrTempSensor);
if (tempR != -127) {
if (tempR >= currentHeaterOff2) {
Serial.println("HEATER2: OFF");
digitalWrite(HEATER2, LOW);
}
if (tempR <= currentHeaterOn2) {
Serial.println("HEATER2: ON");
digitalWrite(HEATER2, HIGH);
}
}
}
heaterTimer2++;
}
}
void writeI2c(byte address, byte value) {
Wire.beginTransmission(address);
Wire.send(value);
Wire.endTransmission();
}
void sendAudioMute(byte value) {
digitalWrite(AUDIO_MUTE, value == 1 ? HIGH : LOW);
}
void sendAmpOn(byte value) {
digitalWrite(AMP_ON, value == 1 ? HIGH : LOW);
}
void sendAudioOn(byte value) {
digitalWrite(AUDIO_ON, value == 1 ? HIGH : LOW);
}
void sendAudioVolume(byte value) {
if (value > 31) return;
currentVolume = value;
writeI2c(TDA7318_I2C_ADDRESS, volMap[value]);
}
void sendAudioLFAttenuator(byte value) {
if (value > 15) return;
writeI2c(TDA7318_I2C_ADDRESS, lfAttMap[value]);
}
void sendAudioRFAttenuator(byte value) {
if (value > 15) return;
writeI2c(TDA7318_I2C_ADDRESS, rfAttMap[value]);
}
void sendAudioLRAttenuator(byte value) {
if (value > 15) return;
writeI2c(TDA7318_I2C_ADDRESS, lrAttMap[value]);
}
void sendAudioRRAttenuator(byte value) {
if (value > 15) return;
writeI2c(TDA7318_I2C_ADDRESS, rrAttMap[value]);
}
void sendAudioBass(byte value) {
if (value > 14) return;
writeI2c(TDA7318_I2C_ADDRESS, bassMap[value]);
}
void sendAudioTreble(byte value) {
if (value > 14) return;
writeI2c(TDA7318_I2C_ADDRESS, trebleMap[value]);
}
void sendAudioSwitch(byte value) {
switch (value) {
case 1:
writeI2c(TDA7318_I2C_ADDRESS, TDA_SW1);
break;
case 2:
writeI2c(TDA7318_I2C_ADDRESS, TDA_SW2);
break;
case 3:
writeI2c(TDA7318_I2C_ADDRESS, TDA_SW3);
break;
case 4:
writeI2c(TDA7318_I2C_ADDRESS, TDA_SW4);
break;
}
}
void sendRadioFrequency(int frequency, boolean power) {
frequency += 107;
digitalWrite(LM_CE, HIGH);
writeLM(byte(frequency));
writeLM(byte(frequency >> 8));
writeLM((power == true) ? 135 : 71);
digitalWrite(LM_CE, LOW);
}
void writeLM(byte bytes) {
int d;
int d1;
delayMicroseconds(LM_DELAY);
for (int x=0; x <= 7; x++) {
// Set DA
d = bytes >> 1;
d1 = d << 1;
digitalWrite(LM_DA, bytes == d1 ? LOW : HIGH);
// Make CL
digitalWrite(LM_CL, HIGH);
delayMicroseconds(LM_DELAY);
digitalWrite(LM_CL, LOW);
delayMicroseconds(LM_DELAY);
bytes = bytes >> 1;
}
delayMicroseconds(LM_DELAY);
}
void getInternalTemperature(byte flag, byte numOfValues) {
sensors.requestTemperaturesByAddress(intTempSensor);
float tempC = sensors.getTempC(intTempSensor);
if (tempC == -127.00) {
tempC = 0;
}
char buf[50];
sprintf(buf, "IT:%u", (int)tempC);
meetAndroid.send(buf);
}
void getExternalTemperature(byte flag, byte numOfValues) {
sensors.requestTemperaturesByAddress(extTempSensor);
float tempC = sensors.getTempC(extTempSensor);
if (tempC == -127.00) {
tempC = 0;
}
char buf[50];
sprintf(buf, "ET:%u", (int)tempC);
meetAndroid.send(buf);
}
void setAudioBalance(byte flag, byte numOfValues) {
int value = meetAndroid.getInt();
sendAudioLFAttenuator(value);
sendAudioRFAttenuator(15 - value);
}
void setHeaterOnTemperature1(byte flag, byte numOfValues) {
currentHeaterOn1 = meetAndroid.getInt();
}
void setHeaterOffTemperature1(byte flag, byte numOfValues) {
currentHeaterOff1 = meetAndroid.getInt();
}
void setHeaterOnTemperature2(byte flag, byte numOfValues) {
currentHeaterOn2 = meetAndroid.getInt();
}
void setHeaterOffTemperature2(byte flag, byte numOfValues) {
currentHeaterOff2 = meetAndroid.getInt();
}
void setAudioBass(byte flag, byte numOfValues) {
sendAudioBass(meetAndroid.getInt());
}
void setAudioTreble(byte flag, byte numOfValues) {
sendAudioTreble(meetAndroid.getInt());
}
void setAudioRearLeftVolume(byte flag, byte numOfValues) {
sendAudioLRAttenuator(meetAndroid.getInt());
}
void setAudioMute(byte flag, byte numOfValues) {
sendAudioMute(meetAndroid.getInt());
}
void setRadioFrequency(byte flag, byte numOfValues) {
int frequency = meetAndroid.getInt();
if (frequency == 0) {
sendRadioFrequency(frequency, false);
sendAudioSwitch(MUSIC_SOURCE);
}
else if (frequency >= RADIO_MIN_FREQUENCY && frequency <= RADIO_MAX_FREQUENCY){
sendRadioFrequency(frequency, true);
sendAudioSwitch(RADIO_SOURCE);
}
}
void setAudioSource(byte flag, byte numOfValues) {
sendAudioSwitch(meetAndroid.getInt());
}
void setAudioVolume(byte flag, byte numOfValues) {
sendAudioVolume(meetAndroid.getInt());
}
void setAudioRearRightVolume(byte flag, byte numOfValues) {
sendAudioRRAttenuator(meetAndroid.getInt());
}
void getHeaterTemperature1(byte flag, byte numOfValues) {
sensors.requestTemperaturesByAddress(hlTempSensor);
float tempC = sensors.getTempC(hlTempSensor);
if (tempC == -127.00) {
tempC = 0;
}
char buf[50];
sprintf(buf, "LT:%u", (int)tempC);
meetAndroid.send(buf);
}
void getHeaterTemperature2(byte flag, byte numOfValues) {
sensors.requestTemperaturesByAddress(hrTempSensor);
float tempC = sensors.getTempC(hrTempSensor);
if (tempC == -127.00) {
tempC = 0;
}
char buf[50];
sprintf(buf, "RT:%u", (int)tempC);
meetAndroid.send(buf);
}
Последний раз редактировалось s.m.; 01.11.2012 в 03:18.
Финальная версия AutoLauncher здесь
Требует Навител - без него будет падать. Только для ICS и выше.
Поддержка сетевых камер
S.M. есть вопроски у начинающего вникать в эту тематику.
Прочитал всё от корки до корки. Очень вдохновил.
1. У тебя есть средства разработки под Андройд - не мог бы для начинающего расписать по блочно что и для чего используешь, схематично. Что было понятно с чего начинать.
2. И есть проект(само устройство), для которого все делаешь - не мог бы схематично нарисовать что сделано и что с чем взаимодействует.
все будет немного позже - соберу железо и все распишу, пока сам не забыл
Получилось. Скачал. Но вот как-то не очень интересно выглядит (Galaxy tab 2 1024x600). Первая версия симпатичнее кажется.
Liliput 629 GL, Intel Atom N230 1.6, HDD 200 GB, ОЗУ 2GB, Globalsat GT-100.
Эту тему просматривают: 1 (пользователей: 0 , гостей: 1)