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.
SavedGames/SavedGames.cpp@51:35cb8e604b72, 2020-05-19 (annotated)
- Committer:
- evanso
- Date:
- Tue May 19 16:46:40 2020 +0000
- Revision:
- 51:35cb8e604b72
- Parent:
- 50:13c8710985f4
- Child:
- 52:feb8cf28bcff
Added check if the file can open function to saved games class.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| evanso | 49:ed569eceeaa4 | 1 | #include "SavedGames.h" |
| evanso | 49:ed569eceeaa4 | 2 | |
| evanso | 49:ed569eceeaa4 | 3 | SavedGames::SavedGames() { |
| evanso | 49:ed569eceeaa4 | 4 | |
| evanso | 49:ed569eceeaa4 | 5 | } |
| evanso | 49:ed569eceeaa4 | 6 | |
| evanso | 49:ed569eceeaa4 | 7 | SavedGames::~SavedGames() { |
| evanso | 49:ed569eceeaa4 | 8 | |
| evanso | 49:ed569eceeaa4 | 9 | } |
| evanso | 49:ed569eceeaa4 | 10 | |
| evanso | 50:13c8710985f4 | 11 | void SavedGames::init(SDFileSystem &sd,N5110 &lcd){ |
| evanso | 50:13c8710985f4 | 12 | error_ = false; |
| evanso | 50:13c8710985f4 | 13 | check_sd_present(sd,lcd); |
| evanso | 51:35cb8e604b72 | 14 | check_open_file(sd,lcd); |
| evanso | 50:13c8710985f4 | 15 | } |
| evanso | 49:ed569eceeaa4 | 16 | |
| evanso | 50:13c8710985f4 | 17 | void SavedGames::check_sd_present(SDFileSystem &sd,N5110 &lcd){ |
| evanso | 50:13c8710985f4 | 18 | if(!sd.card_present()) { |
| evanso | 50:13c8710985f4 | 19 | error_ = true; |
| evanso | 51:35cb8e604b72 | 20 | |
| evanso | 51:35cb8e604b72 | 21 | //print error screen |
| evanso | 50:13c8710985f4 | 22 | lcd.clear(); |
| evanso | 50:13c8710985f4 | 23 | lcd.printString("SD card not ",9,3); |
| evanso | 50:13c8710985f4 | 24 | lcd.printString(" present ",9,4); |
| evanso | 50:13c8710985f4 | 25 | lcd.refresh(); |
| evanso | 50:13c8710985f4 | 26 | wait(3); |
| evanso | 50:13c8710985f4 | 27 | } |
| evanso | 50:13c8710985f4 | 28 | } |
| evanso | 50:13c8710985f4 | 29 | |
| evanso | 51:35cb8e604b72 | 30 | void SavedGames::check_open_file(SDFileSystem &sd,N5110 &lcd){ |
| evanso | 51:35cb8e604b72 | 31 | //opens file |
| evanso | 51:35cb8e604b72 | 32 | FILE *fp; |
| evanso | 51:35cb8e604b72 | 33 | fp = fopen("/sd/SavedGames.text", "a"); |
| evanso | 51:35cb8e604b72 | 34 | |
| evanso | 51:35cb8e604b72 | 35 | //checks if file is opened corectly |
| evanso | 51:35cb8e604b72 | 36 | if (fp == NULL) { |
| evanso | 51:35cb8e604b72 | 37 | error_ = true; |
| evanso | 51:35cb8e604b72 | 38 | |
| evanso | 51:35cb8e604b72 | 39 | //print error screen |
| evanso | 51:35cb8e604b72 | 40 | lcd.clear(); |
| evanso | 51:35cb8e604b72 | 41 | lcd.printString(" Unable to ",9,3); |
| evanso | 51:35cb8e604b72 | 42 | lcd.printString(" open file ",9,4); |
| evanso | 51:35cb8e604b72 | 43 | lcd.refresh(); |
| evanso | 51:35cb8e604b72 | 44 | wait(3); |
| evanso | 51:35cb8e604b72 | 45 | } |
| evanso | 51:35cb8e604b72 | 46 | } |
| evanso | 51:35cb8e604b72 | 47 | |
| evanso | 51:35cb8e604b72 | 48 | void SavedGames::add_saved_data(SDFileSystem &sd, struct SavedGamesData){ |
| evanso | 51:35cb8e604b72 | 49 | FILE *fp; |
| evanso | 51:35cb8e604b72 | 50 | |
| evanso | 51:35cb8e604b72 | 51 | } |
| evanso | 51:35cb8e604b72 | 52 | |
| evanso | 50:13c8710985f4 | 53 | bool SavedGames::get_error(){ |
| evanso | 50:13c8710985f4 | 54 | return error_; |
| evanso | 50:13c8710985f4 | 55 | } |
| evanso | 50:13c8710985f4 | 56 | |
| evanso | 50:13c8710985f4 | 57 |