Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 2:71b3736a1bd7
- Parent:
- 1:4f6bcf445501
--- a/main.cpp Thu Jul 16 07:21:46 2015 +0000
+++ b/main.cpp Fri Oct 21 10:54:03 2022 +0000
@@ -1,73 +1,163 @@
#include "mbed.h"
-#include "WIZnetInterface.h"
+#include "nextion_lcd.h"
+#include "APP.h"
-#define USE_DHCP 1
+#include "FATFileSystem.h"
+// Block devices
+#include "SDBlockDevice.h"
+#include "SAVE_CONT.h"
+#include "PS3_BT_CTL.h"
+#include "ROBO1_CONT.h"
+#include "ROBO2_CONT.h"
+#include "IO_CONT.h"
+#include "CUT_CONT.h"
+#include "ROBO_TWIN_CONT.h"
+#include "DiNi_supplyr.h"
-#define LOOPBACKPORT 5000
+DigitalIn SD_CD_I(PC_4);
+// File system declaration
+FATFileSystem fileSystem("fs");
+
+// Physical block device, can be any device that supports the BlockDevice API
+SDBlockDevice blockDevice(PC_3,PC_2,PB_10,PB_12); // mosi, miso, sck, cs
+static UnbufferedSerial *pc;
+
+char pc_print_buf[64];
+
-const char * IP_Addr = "192.168.11.194";
-const char * IP_Subnet = "255.255.255.0";
-const char * IP_Gateway = "192.168.11.1";
-unsigned char MAC_Addr[6] = {0x00,0x08,0xDC,0x12,0x34,0x56};
+void time_set(){
+ RTC_GET();
+ // setup time structure for Wed, 28 Oct 2009 11:35:37
+ struct tm t;
+ t.tm_sec = rtc_sec; // 0-59
+ t.tm_min = rtc_min; // 0-59
+ t.tm_hour =rtc_hour; // 0-23
+ t.tm_mday = rtc_date; // 1-31
+ t.tm_mon = rtc_month-1; // 0-11
+ t.tm_year = rtc_year-1900; // year since 1900
+
+ // convert to timestamp and set (1256729737)
+ time_t seconds = mktime(&t);
+ set_time(seconds);
+}
+void time_disp(){
+ //time_t seconds = time(NULL) + (60 * 60 * 9); // JST
+ time_t seconds = time(NULL);
+ struct tm *t = localtime(&seconds);
+
+ printf("%04d/%02d/%02d %02d:%02d:%02d",
+ t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
+
+}
+void pc_printf(char *txt){
+ unsigned char len = strlen(txt);//文字列の長さを確認
+ pc->write(txt,len);
+}
+////ms単位でのwait指定////
+void wait_ms(double wcnt){
+ wait_us(wcnt*1000);
+
+}
+void wait(double wcnt){
+ wait_us(wcnt*1000000000);
+
+}
-DigitalOut myled1(LED1);
-Serial pc(USBTX, USBRX);
+void SD_CARD_INI(){
+ SD_CD_I.mode(PullUp);
+ if(SD_CD_I.read()==1){
+ lcd_print("t0","SDカード未挿入の為、起動できません。");
+ ALM_ST= ALM_SD;
+ ALM_HOLD_SET();
+ }else{
+ lcd_print("t0","SDカード挿入確認OK");
+ }
+ //lcdのRTCから時刻を取得してマイコンのRTCにセット(ファイルの保存時刻用)
+ //time_set();
+ // time_disp();
+ // Try to mount the filesystem
+ printf("Mounting the filesystem... ");
+ fflush(stdout);
-#ifdef TARGET_LPC11U68
-SPI spi(P0_9,P0_8,P1_29);
-WIZnetInterface ethernet(&spi,P0_2,P1_13);
-#endif
+ int err = fileSystem.mount(&blockDevice);
+ printf("%s\n", (err ? "Fail :(" : "OK"));
+ if (err) {
+ // Reformat if we can't mount the filesystem
+ // this should only happen on the first boot
+ printf("No filesystem found, formatting... ");
+ fflush(stdout);
+ ALM_ST= ALM_SD;
+ lcd_print("t0","SDカード異常の為、起動できません。");
+ ALM_HOLD_SET();
+
+ }
+
+}
int main() {
-
+ wait_ms(500);
+ nextion_lcd_ini(); //LCD初期化
+ lcd_backlight(50);
//Set serial port baudrate speed: 115200
- pc.baud(115200);
-
- pc.printf("Start\r\n");
+ pc= new UnbufferedSerial(USBTX, USBRX,115200);
+
+
+ //RB1_CONNECT();
+ // RB2_CONNECT();
+ HOME_STATE=1;//TEST
+
+ IO_INI();//IO初期化 I2C絶縁IO
+ EA_IO_INI();
+
+
+ PS3_CTL_INI();
+ /////SDカード初期処理///
+ SD_CARD_INI();
+ wait_ms(100);
- char buffer[256];
+ ////ポジションデータ読み込み///
+ RB1_LIST_READ();
+ RB2_LIST_READ();
+ sprintf(lcd_print_buf,"ポイントデータ読み込み件数 :RB1 : %02d R2 : %02d",RB1_POINT_NO_CNT-1,RB1_POINT_NO_CNT-1);
+ lcd_print("t0",lcd_print_buf);
+ ///極棒交換回数,ニッケル端子設定値の読み出し//
+ // SET_UP_SAVE();
+ SETUP_DATA_RD();//設定値の読み出し(リセット時にSDエラーになるのでデバック中は、コメントアウト)
+
+ //lcdのRTCから時刻を取得してマイコンのRTCにセット(ファイルの保存時刻用)
+ time_set();
+ time_disp();
+
+ wait_ms(1500);
+ // printf("Start\r\n");
- while(1)
- {
- #if USE_DHCP
- int ret = ethernet.init(MAC_Addr);
- #else
- int ret = ethernet.init(MAC_Addr,IP_Addr,IP_Subnet,IP_Gateway);
- #endif
-
- if (!ret) {
- pc.printf("Initialized, MAC: %s\r\n", ethernet.getMACAddress());
- ret = ethernet.connect();
- if (!ret) {
- pc.printf("IP: %s, MASK: %s, GW: %s\r\n",
- ethernet.getIPAddress(), ethernet.getNetworkMask(), ethernet.getGateway());
- } else {
- pc.printf("Error ethernet.connect() - ret = %d\r\n", ret);
- exit(0);
- }
- } else {
- pc.printf("Error ethernet.init() - ret = %d\r\n", ret);
- exit(0);
+ ///作業画面へ移行////
+ lcd_page_set(P_MAIN,100);
+ wait_ms(200);
+
+
+ lcd_print("t0","ダイレクト溶接DOBOT板 V0.17(2022/10/13)");
+ printf("dobot direct prgoram start\r\n");
+ MAIN_PAGE_DISP();
+ lcd_audio_vol(0,100);//val=0から100 def80
+ lcd_audio_play(AU_BOOT,0,80);
+ //lcdのRTCから時刻を取得してマイコンのRTCにセット(ファイルの保存時刻用)
+ time_set();
+ time_disp();
+ wait_ms(1000);
+
+ /* while(1){
+ if(IO_EX_BIT_READ(WTRP_HEND_I)==IOEX_OFF_I){
+ printf("HEND OFF\r\n");
+ lcd_print("t0","HEND OFF");
+ }else{
+ printf("HEND ON\r\n");
+ lcd_print("t0","HEND ON");
}
-
- TCPSocketServer server;
- server.bind(LOOPBACKPORT);
- server.listen();
-
- while (1) {
- pc.printf("\nWait for new connection...\r\n");
- TCPSocketConnection client;
- server.accept(client);
- client.set_blocking(false, 0); // Timeout=0.
- pc.printf("Connection from: %s\r\n", client.get_address());
- while (client.is_connected() == true) {
- int n = client.receive(buffer, sizeof(buffer));
- if(n > 0)
- client.send_all(buffer, n);
- if(client.is_fin_received())
- client.close();
- }
- pc.printf("Disconnected.\r\n");
- }
+ wait_ms(1000);
+ }
+*/
+ while(1){
+ MG400_AP();
}
}