Kod: Zaznacz cały
if (pc.readable())
{
pc.scanf("%s", dane);
}
po eliminacji blokady całego softu przez rs232 , dodałem
Kod: Zaznacz cały
if (pc.readable())
Kod: Zaznacz cały
if ((*temp_data >= 12) && (*temp_data <= 40))
{
pc.cls();
screen();
intro();
brain.write(eeprom_size = 8, (int32_t) *temp_data);
pc.locate(20, 7);
pc.printf("Zapisalem podaną temperature przekroczenia");
wait(5);
val = 1;
fflush(stdin);
refresh_buffer();
pc.cls();
}
else
{
pc.cls();
screen();
intro();
pc.locate(20, 7);
pc.printf("Wpisano niepoprawne dane. Dopuszczalny zakres: od 12 do 40");
wait(5);
}
}
i wykonuje sekcje z else
Kod: Zaznacz cały
else
{
pc.cls();
screen();
intro();
pc.locate(20, 7);
pc.printf("Wpisano niepoprawne dane. Dopuszczalny zakres: od 12 do 40");
wait(5);
}
Kod: Zaznacz cały
if (pc.readable())
tu cały kod softi
Kod: Zaznacz cały
#include "mbed.h"
#include "MPL3115A2.h"
#include "Terminal.h"
#include "eeprom.h"
#include "cstdlib"
#include "string"
#define EEPROM_ADDR 0x00 // I2c EEPROM address is 0x00
#define SDA PTE25 // I2C SDA pin
#define SCL PTE24 // I2C SCL pin
int32_t eeprom_size , addr;
Terminal pc(PTA2, PTA1); // tx, rx
I2C i2c(PTE0, PTE1); // sda, scl
EEPROM brain(SDA, SCL, EEPROM_ADDR, EEPROM::T24C08);
MPL3115A2 sensor(&i2c, &pc);
int temperature_live_state;
static int read_user_temp;
int val = 0;
int *temp_data = &read_user_temp;
Timer licznik;
char buffer[20];
char dane[4];
float check_battery;
int counter = 100;
DigitalOut buzzer(PTA12); // Sanity check to make sure the program is working.
DigitalOut myled1(PTD1, 1); // Sanity check to make sure the program is working.
AnalogIn batery(PTC2);
float monitor_batery()
{
check_battery = batery.read();
float resume;
return resume = (check_battery*4.1);
}
void refresh_buffer()
{
for (int y = 0; y < sizeof(buffer); y++)
buffer[y] = 0;
for (int z = 0; z < sizeof(dane); z++)
dane[z] = 0;
}
void serials()
{
if (pc.readable())
{
pc.scanf( "%s", buffer);
}
}
void signaller()
{
licznik.start();
if (licznik.read_ms() <= 1000)
{
buzzer = !buzzer;
}
licznik.reset();
}
//void alarm_power()
//{
//
//
// if (0.900000 < 0.800000)
// {
// while (counter <= 0)
// {
//
// licznik.start();
//
// if (licznik.read_ms() <= 1500)
// {
//
// buzzer = !buzzer;
// counter + 1;
// }
//
// licznik.reset();
//
// }
// }
// }
void alarm_temp(string & temp_read_input)
{
string str = temp_read_input;
temperature_live_state = atoi(str.c_str());
if (temperature_live_state >= *temp_data)
{
signaller();
}
if (*temp_data > temperature_live_state)
{
buzzer = 0;
}
}
void screen()
{
pc.foreground(0xFFFF00);
pc.hideCursor();
}
void intro()
{
pc.locate(15, 5);
pc.printf(" ** inteligentny Termometr ** ");
pc.locate(15, 6);
pc.printf("Created by Foreste");
}
void labels()
{
pc.locate(10, 7);
pc.printf("Temperatura");
pc.locate(25, 7);
pc.printf("Cisnienie");
pc.locate(38, 7);
pc.printf("otrzezenie wysokiej temp");
pc.locate(65, 7);
pc.printf("Bateria");
}
void input_add_user_define_temperature()
{
int tempint;
refresh_buffer();
pc.cls();
screen();
intro();
pc.locate(1, 7);
pc.printf("Wpisz wartość temperatury ,po której termometr bedzie sygnalizował przekroczenie");
if (pc.readable())
{
pc.scanf("%s", dane);
}
for (int z = 0; z < 4; z++)
{
if (isdigit(dane[z]))//sprawdzanie czy znak jest liczbą
{
tempint = atoi(dane); //kowertowanie tablicy typu char na zmienną int
}
*temp_data = tempint;
if ((*temp_data >= 12) && (*temp_data <= 40))
{
pc.cls();
screen();
intro();
brain.write(eeprom_size = 8, (int32_t) *temp_data);
pc.locate(20, 7);
pc.printf("Zapisalem podaną temperature przekroczenia");
wait(5);
val = 1;
fflush(stdin);
refresh_buffer();
pc.cls();
}
else
{
pc.cls();
screen();
intro();
pc.locate(20, 7);
pc.printf("Wpisano niepoprawne dane. Dopuszczalny zakres: od 12 do 40");
wait(5);
}
}
}
void rs232_menu()
{
if (strcmp(buffer, "reset") == 0)
{
NVIC_SystemReset();
}
else if (strcmp(buffer, "alarm") == 0)
{
input_add_user_define_temperature();
}
}
int main() {
pc.baud(9600);
pc.cls();
sensor.init();
screen();
intro();
wait(5);
Temperature t;
Pressure p;
sensor.setOffsetTemperature(20);
sensor.setOffsetPressure(-32);
brain.read((uint32_t)(eeprom_size = 8), (int32_t&) *temp_data);
while (read_user_temp <= 0)
{
while (val <= 0)
{
input_add_user_define_temperature();
}
}
pc.cls();
while (1)
{
val = 0;
sensor.readTemperature(&t);
sensor.setModeStandby();
sensor.setModeBarometer();
sensor.setModeActive();
sensor.readPressure(&p);
screen();
intro();
labels();
string temp_cache = t.print();
pc.locate(10, 9);
pc.printf("%s C", t.print());
pc.locate(25, 9);
pc.printf("%s Hpa", p.print());
pc.locate(45, 9);
pc.printf("%d", *temp_data);
pc.locate(65, 9);
pc.printf("%1.2fV", monitor_batery());
pc.locate(65, 11);
pc.printf("%fV", check_battery);
pc.locate(65, 12);
pc.printf("%d", counter);
alarm_temp(temp_cache);
serials();
//alarm_power();
rs232_menu();
sensor.setModeStandby();
sensor.setModeAltimeter();
sensor.setModeActive();
}
}